Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
issue 367 - Draft entity query error (#371)
Browse files Browse the repository at this point in the history
* test: draft referencing other draft Odata call

* fix: wrong alias when subquery inside "SELECT"

* fix: less disruptive changes in test model

* chore(deps): bump moment from 2.29.1 to 2.29.4 (#372)

* chore(deps): bump moment from 2.29.1 to 2.29.4

* chore(deps): bump moment from 2.29.1 to 2.29.4

---------

Co-authored-by: Rajdeep Bhuva <[email protected]>

* fix: removed Suppliers annotations

* test: draft referencing other draft Odata call

* fix: wrong alias when subquery inside "SELECT"

* fix: less disruptive changes in test model

* fix: removed Suppliers annotations

---------

Co-authored-by: ryegros <[email protected]>
Co-authored-by: Rajdeep Bhuva <[email protected]>
Co-authored-by: Rajdeep Bhuva <[email protected]>
  • Loading branch information
4 people committed Jan 27, 2023
1 parent 2646bbc commit d649a57
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 9 deletions.
9 changes: 8 additions & 1 deletion __tests__/__assets__/beershop-admin-service.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ CREATE TABLE csw_TypeChecks (
PRIMARY KEY(ID)
);

CREATE TABLE csw_TypeChecksSibling (
ID VARCHAR(36) NOT NULL,
dummyField VARCHAR(5000),
typeChecks_ID VARCHAR(36),
PRIMARY KEY(ID)
);

CREATE VIEW BeershopAdminService_Beers AS SELECT
Beers_0.ID,
Beers_0.createdAt,
Expand All @@ -64,4 +71,4 @@ CREATE VIEW BeershopAdminService_Breweries AS SELECT
Brewery_0.modifiedAt,
Brewery_0.modifiedBy,
Brewery_0.name
FROM csw_Brewery AS Brewery_0
FROM csw_Brewery AS Brewery_0;
1 change: 1 addition & 0 deletions __tests__/__assets__/cap-proj/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# full URL to deployed cap-proj
# aka /__tests__/__assets__/cap-proj
scpServiceURL = https://<yourspace>-cap-proj-srv.cfapps.eu10.hana.ondemand.com
CDS_DEBUG = true
6 changes: 6 additions & 0 deletions __tests__/__assets__/cap-proj/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ entity TypeChecks : cuid {
type_LargeString : LargeString;
virtual type_virtual : Integer;
}


entity TypeChecksSibling : cuid {
dummyField : String;
typeChecks : Association to one TypeChecks;
}
5 changes: 5 additions & 0 deletions __tests__/__assets__/cap-proj/srv/beershop-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ service BeershopService {
entity Breweries as projection on csw.Brewery;
entity TypeChecks as projection on csw.TypeChecks;

@cds.redirection.target
@odata.draft.enabled
entity TypeChecksWithDraft as projection on csw.TypeChecks;

@odata.draft.enabled
entity TypeChecksSibling as projection on csw.TypeChecksSibling;

}

extend service BeershopService with {
Expand Down
26 changes: 25 additions & 1 deletion __tests__/__assets__/test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ CREATE TABLE csw_TypeChecks (
PRIMARY KEY(ID)
);

CREATE TABLE csw_TypeChecksSibling (
ID VARCHAR(36) NOT NULL,
dummyField VARCHAR(5000),
typeChecks_ID VARCHAR(36),
PRIMARY KEY(ID)
);

CREATE TABLE DRAFT_DraftAdministrativeData (
DraftUUID VARCHAR(36) NOT NULL,
CreationDateTime TIMESTAMPTZ,
Expand Down Expand Up @@ -73,6 +80,17 @@ CREATE TABLE BeershopService_TypeChecksWithDraft_drafts (
PRIMARY KEY(ID)
);

CREATE TABLE BeershopService_TypeChecksSibling_drafts (
ID VARCHAR(36) NOT NULL,
dummyField VARCHAR(5000) NULL,
typeChecks_ID VARCHAR(36) NULL,
IsActiveEntity BOOLEAN,
HasActiveEntity BOOLEAN,
HasDraftEntity BOOLEAN,
DraftAdministrativeData_DraftUUID VARCHAR(36) NOT NULL,
PRIMARY KEY(ID)
);

CREATE VIEW BeershopService_Beers AS SELECT
Beers_0.ID,
Beers_0.createdAt,
Expand Down Expand Up @@ -128,6 +146,12 @@ CREATE VIEW BeershopService_TypeChecksWithDraft AS SELECT
TypeChecks_0.type_LargeString
FROM csw_TypeChecks AS TypeChecks_0;

CREATE VIEW BeershopService_TypeChecksSibling AS SELECT
TypeChecksSibling_0.ID,
TypeChecksSibling_0.dummyField,
TypeChecksSibling_0.typeChecks_ID
FROM csw_TypeChecksSibling AS TypeChecksSibling_0;

CREATE VIEW BeershopService_DraftAdministrativeData AS SELECT
DraftAdministrativeData.DraftUUID,
DraftAdministrativeData.CreationDateTime,
Expand All @@ -137,4 +161,4 @@ CREATE VIEW BeershopService_DraftAdministrativeData AS SELECT
DraftAdministrativeData.LastChangedByUser,
DraftAdministrativeData.InProcessByUser,
DraftAdministrativeData.DraftIsProcessedByMe
FROM DRAFT_DraftAdministrativeData AS DraftAdministrativeData
FROM DRAFT_DraftAdministrativeData AS DraftAdministrativeData;
17 changes: 14 additions & 3 deletions __tests__/lib/pg/draft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const deploy = require('@sap/cds/lib/deploy')
// mock (package|.cdsrc).json entries
cds.env.requires.db = { kind: 'postgres' }
cds.env.requires.postgres = {
impl: './cds-pg', // hint: not really sure as to why this is, but...
impl: './cds-pg' // hint: not really sure as to why this is, but...
}

// default (single) test environment is local,
Expand All @@ -23,7 +23,7 @@ describe.each(suiteEnvironments)(
kind: 'postgres',
dialect: 'plain',
model: this._model,
credentials: credentials,
credentials: credentials
}

// only bootstrap in local mode as scp app is deployed and running
Expand All @@ -49,13 +49,24 @@ describe.each(suiteEnvironments)(
`${basepath}/BeershopService.draftEdit?$expand=DraftAdministrativeData($select=DraftUUID,InProcessByUser)`
)
.send({
PreserveChanges: true,
PreserveChanges: true
})
expect(response.status).toStrictEqual(201)

const responseGet = await request.get(basepath)
expect(responseGet.status).toStrictEqual(200)
})

test(' -> Draft entity referencing another draft entity on matchcode call', async () => {
const oQuery =
'/beershop/TypeChecksSibling?$filter=(IsActiveEntity eq false or SiblingEntity/IsActiveEntity eq null)&$expand=typeChecks($select=type_String)'

const response = await request.get(oQuery).send({
PreserveChanges: true
})

expect(response.status).toStrictEqual(200)
})
})
}
)
2 changes: 1 addition & 1 deletion __tests__/lib/pg/service-admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe.each(suiteEnvironments)(
const response = await request.get('/beershop/')

expect(response.status).toStrictEqual(200)
expect(response.body.value.length).toStrictEqual(4)
expect(response.body.value.length).toStrictEqual(5)
})

describe('OData admin: CREATE', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/pg/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe.each(suiteEnvironments)(
const response = await request.get('/beershop/')

expect(response.status).toStrictEqual(200)
expect(response.body.value.length).toStrictEqual(4)
expect(response.body.value.length).toStrictEqual(5)
})

describe('odata: GET -> sql: SELECT', () => {
Expand Down
8 changes: 6 additions & 2 deletions lib/pg/sql-builder/SelectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ class PGSelectBuilder extends SelectBuilder {
}

// an as (alias) should always be passed Postgres need it for its select statements
if (element.as || as) {
if (element.as) {
// identifier
res.sql += ` ${this._quoteElement(element.as || as)}`
res.sql += ` ${this._quoteElement(element.as)}`
} else {
if (as && this._options.objectKey !== 'xpr') {
res.sql += ` ${this._quoteElement(as)}`
}
}

this._outputObj.values.push(...res.values)
Expand Down

0 comments on commit d649a57

Please sign in to comment.