Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added top level property entityTypes #95

Merged
merged 22 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cc76d9b
initial commit
aramovic79 Nov 14, 2024
0e59e39
Merge branch 'main' of https://github.com/cap-js/ORD into fix/69-add-…
aramovic79 Nov 20, 2024
c015722
Merge branch 'main' into fix/69-add-missing-top-level-property-entity…
RoshniNaveenaS Nov 27, 2024
7fd665f
Merge branch 'fix/69-add-missing-top-level-property-entitytypes' of h…
aramovic79 Dec 3, 2024
8199513
Merge branch 'main' of https://github.com/cap-js/ORD into fix/69-add-…
aramovic79 Dec 3, 2024
30cc29e
construct entityTypes and entityTypeMappings arrays
aramovic79 Dec 4, 2024
b157ed4
Fix entityTypeTargets to be array of objects and not strings
aramovic79 Dec 4, 2024
44031df
check existance of @ORDExtensions on entity level
aramovic79 Dec 4, 2024
02c5e6f
change schema and service in the xmpl folder so the sample ord docume…
aramovic79 Dec 4, 2024
b232ba8
handle entity type version
aramovic79 Dec 5, 2024
80c7ccc
tests clean-up
aramovic79 Dec 5, 2024
96fef2a
minor change:rewrite the map statement
aramovic79 Dec 5, 2024
6a456b0
introduct LEVEL constant
aramovic79 Dec 5, 2024
05a3736
rename sample entities in xmpl app
aramovic79 Dec 5, 2024
a5fdaee
change the version handling
aramovic79 Dec 9, 2024
2860721
minor change
aramovic79 Dec 9, 2024
c449696
remove incorrect validateNamespace function
aramovic79 Dec 9, 2024
56f29db
Merge branch 'main' into fix/69-add-missing-top-level-property-entity…
aramovic79 Dec 9, 2024
64fbeec
add test for missing package.json
aramovic79 Dec 9, 2024
d01f752
Merge branch 'fix/69-add-missing-top-level-property-entitytypes' of h…
aramovic79 Dec 9, 2024
0135366
Merge branch 'main' of https://github.com/cap-js/ORD into fix/69-add-…
aramovic79 Dec 9, 2024
1218ec6
use constants with miningful names instead of oidIdParts[N]
aramovic79 Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions __tests__/__mocks__/localAndNonODMReferencedEntities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"$version": "2.0",
"definitions": {
"LocalService": {
"@ORD.Extensions.title": "This is Local Service title",
"kind": "service"
},
"LocalService.DummyEntityA": {
"@ODM.entityName": "SomeODMEntity",
"@ODM.oid": "id",
"@ODM.root": true,
"@title": "Dummy title of Entity with corresponding ODM entity title",
"elements": {
"id": {
"key": true,
"type": "cds.UUID"
},
"propertyA": {
"length": 10,
"type": "cds.String"
},
"propertyB": {
"length": 20,
"type": "cds.String"
}
},
"kind": "entity",
"projection": {
"from": {
"ref": [
"sap.cds.demo.EntityWithCorrespondingODMEntity"
]
}
}
},
"LocalService.DummyEntityB": {
"@EntityRelationship.entityType": "sap.sm:SomeAribaDummyEntity",
"@ObjectModel.compositionRoot": true,
"@title": "Dummy title of Ariba entity",
"elements": {
"id": {
"key": true,
"type": "cds.UUID"
},
"propertyC": {
"length": 10,
"type": "cds.String"
},
"propertyD": {
"length": 20,
"type": "cds.String"
}
},
"kind": "entity",
"projection": {
"from": {
"ref": [
"sap.cds.demo.SomeAribaEntity"
]
}
}
},
"LocalService.TitleChange2": {
"elements": {
"ID": {
"type": "cds.Integer"
},
"title": {
"@title": "Changed title",
"type": "cds.String"
}
},
"kind": "event"
},
"sap.cds.demo.EntityWithCorrespondingODMEntity": {
"@ODM.entityName": "SomeODMEntity",
"@ODM.oid": "id",
"@ODM.root": true,
"@title": "Dummy title of Entity with corresponding ODM entity title",
"elements": {
"id": {
"key": true,
"type": "cds.UUID"
},
"propertyA": {
"length": 10,
"type": "cds.String"
},
"propertyB": {
"length": 20,
"type": "cds.String"
}
},
"kind": "entity"
},
"sap.cds.demo.SomeAribaEntity": {
"@EntityRelationship.entityType": "sap.sm:SomeAribaDummyEntity",
"@ObjectModel.compositionRoot": true,
"@title": "Dummy title of Ariba entity",
"elements": {
"id": {
"key": true,
"type": "cds.UUID"
},
"propertyC": {
"length": 10,
"type": "cds.String"
},
"propertyD": {
"length": 20,
"type": "cds.String"
}
},
"kind": "entity"
}
},
"meta": {
"creator": "CDS Compiler v5.4.4",
"flavor": "inferred"
}
}
13 changes: 5 additions & 8 deletions __tests__/__snapshots__/noOrdInCdsrc.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ exports[`Tests for ORD document when .cdsrc.json has no \`ord\` property Success
"entityTypeMappings": [
{
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:odm.bookshop.Authors:v1",
},
"sap.odm:entityType:odm.bookshop.Authors:v1",
aramovic79 marked this conversation as resolved.
Show resolved Hide resolved
],
},
],
Expand Down Expand Up @@ -112,9 +110,7 @@ exports[`Tests for ORD document when .cdsrc.json has no \`ord\` property Success
"entityTypeMappings": [
{
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:odm.bookshop.Authors:v1",
},
"sap.odm:entityType:odm.bookshop.Authors:v1",
],
},
],
Expand Down Expand Up @@ -170,6 +166,7 @@ exports[`Tests for ORD document when .cdsrc.json has no \`ord\` property Success
},
],
"description": "this is an application description",
"entityTypes": [],
"eventResources": [
{
"description": "CAP Event resource describing events / messages.",
Expand Down Expand Up @@ -291,7 +288,7 @@ exports[`Tests for ORD document when .cdsrc.json has no \`ord\` property Success
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:",
],
"shortDescription": "Short description for capire bookshop ord sample",
"shortDescription": "Short description of capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
Expand All @@ -301,7 +298,7 @@ exports[`Tests for ORD document when .cdsrc.json has no \`ord\` property Success
"products": [
{
"ordId": "customer:product:capire.bookshop.ord.sample:",
"shortDescription": "Description for capire bookshop ord sample",
"shortDescription": "Short description of capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:customer:",
},
Expand Down
27 changes: 25 additions & 2 deletions __tests__/__snapshots__/ordCdsrc.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ exports[`Tests for default ORD document when .cdsrc.json is present Successfully
},
],
"description": "this is my custom description",
"entityTypes": [],
"eventResources": [
{
"description": "CAP Event resource describing events / messages.",
Expand Down Expand Up @@ -154,7 +155,7 @@ exports[`Tests for default ORD document when .cdsrc.json is present Successfully
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:",
],
"shortDescription": "Short description for capire bookshop ord sample",
"shortDescription": "Short description of capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
Expand All @@ -169,6 +170,28 @@ exports[`Tests for default ORD document when .cdsrc.json is present Successfully
"vendor": "customer:vendor:Customer:",
"version": "1.0.1",
},
{
"description": "Description for capire bookshop ord sample",
"ordId": "sap.test.cdsrc.sample:package:capirebookshopordsample-integrationDependency:v1",
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:",
],
"shortDescription": "Short description of capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
{
"description": "Description for capire bookshop ord sample",
"ordId": "sap.test.cdsrc.sample:package:capirebookshopordsample-entityType:v1",
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:",
],
"shortDescription": "Short description of capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
{
"description": "Description for capire bookshop ord sample version 2",
"ordId": "sap.test.cdsrc.sample:package:capirebookshopordsample-api:v2",
Expand All @@ -185,7 +208,7 @@ exports[`Tests for default ORD document when .cdsrc.json is present Successfully
"products": [
{
"ordId": "customer:product:capire.bookshop.ord.sample:",
"shortDescription": "Description for capire bookshop ord sample",
"shortDescription": "Short description of capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:customer:",
},
Expand Down
5 changes: 3 additions & 2 deletions __tests__/__snapshots__/ordPackageJson.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ exports[`Tests for default ORD document when .cdsrc.json is not present Successf
},
],
"description": "this is an application description",
"entityTypes": [],
"eventResources": [
{
"description": "CAP Event resource describing events / messages.",
Expand Down Expand Up @@ -129,7 +130,7 @@ exports[`Tests for default ORD document when .cdsrc.json is not present Successf
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:",
],
"shortDescription": "Short description for capire bookshop ord sample",
"shortDescription": "Short description of capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
Expand All @@ -139,7 +140,7 @@ exports[`Tests for default ORD document when .cdsrc.json is not present Successf
"products": [
{
"ordId": "customer:product:capire.bookshop.ord.sample:",
"shortDescription": "Description for capire bookshop ord sample",
"shortDescription": "Short description of capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:customer:",
},
Expand Down
40 changes: 40 additions & 0 deletions __tests__/entityTypesAndMappings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const cds = require("@sap/cds");
const csn = require("./__mocks__/localAndNonODMReferencedEntities.json");
const path = require("path");

describe("Tests for ORD document checking if entityTypes and entityTypeMappings are generated correctly", () => {
let ord;
beforeAll(() => {
jest.spyOn(require("../lib/date"), "getRFC3339Date").mockReturnValue("2024-11-04T14:33:25+01:00");
ord = require("../lib/ord");
cds.root = path.join(__dirname, "bookshop");
cds.env = {
"ord": {
"namespace": "sap.sm",
"openResourceDiscovery": "1.9",
"description": "this is my custom description",
"policyLevel": "sap:core:v1"
}
};
});

afterAll(() => {
jest.clearAllMocks();
jest.resetAllMocks();
});

test("Successfully create ORD Document: entityTypes with local entities and entityTypeMappings containing referenced entities", () => {
const document = ord(csn);

// ...(appConfig.entityTypeMappings?.length > 0 && { entityTypeMappings: [{ entityTypeTargets: appConfig.entityTypeTargets.map(m => m.ordId) }] }),

expect(document).not.toBeUndefined();
expect(document.entityTypes).toHaveLength(1);
expect(document.entityTypes[0].partOfPackage).toEqual(expect.stringContaining("entityType"));
expect(document.entityTypes[0].level).toEqual(expect.stringContaining("root-entity"));
expect(document.apiResources[0].entityTypeMappings[0].entityTypeTargets).toEqual(expect.arrayContaining([
"sap.odm:entityType:SomeODMEntity:v1",
"sap.sm:entityType:SomeAribaDummyEntity:v1"
]));
});
});
30 changes: 26 additions & 4 deletions __tests__/unittest/__snapshots__/defaults.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports[`defaults packages should return default value if policyLevel contains s
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description for My Package",
"shortDescription": "Short description of My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
Expand All @@ -57,7 +57,29 @@ exports[`defaults packages should return default value if policyLevel contains s
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description for My Package",
"shortDescription": "Short description of My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
{
"description": "Description for My Package",
"ordId": "customer.sample:package:MyPackage-integrationDependency:v1",
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description of My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
{
"description": "Description for My Package",
"ordId": "customer.sample:package:MyPackage-entityType:v1",
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description of My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
Expand All @@ -73,7 +95,7 @@ exports[`defaults packages should return default value if policyLevel does not c
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description for My Package",
"shortDescription": "Short description of My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
Expand All @@ -87,7 +109,7 @@ exports[`defaults products should return default value 1`] = `
[
{
"ordId": "customer:product:My.Product:",
"shortDescription": "Description for My Product",
"shortDescription": "Short description of My Product",
"title": "My Product",
"vendor": "customer:vendor:customer:",
},
Expand Down
6 changes: 4 additions & 2 deletions __tests__/unittest/__snapshots__/templates.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports[`templates createAPIResourceTemplate should create API resource template
"url": "/.well-known/open-resource-discovery/v1/api-metadata/MyService.edmx",
},
],
"shortDescription": "Short description for MyService",
"shortDescription": "Short description of MyService",
"title": "MyService",
"version": "1.0.0",
"visibility": "public",
Expand Down Expand Up @@ -123,7 +123,9 @@ exports[`templates ordExtension should add apiResources with ORD Extension "visi
"description": "Description for MyService",
"entityTypeMappings": [
{
"entityTypeTargets": "sap.odm:entityType:test:v1",
"entityTypeTargets": [
"sap.odm:entityType:test:v1",
],
},
],
"entryPoints": [
Expand Down
Loading
Loading