Skip to content

Commit

Permalink
Feat: extend custom ORD content (#63)
Browse files Browse the repository at this point in the history
* add ovrride logic

* add todo list

* udpate unittest

* extract into new file

* add unittest

* extend conflict function

* Update lib/extendOrdWithCustom.js

Co-authored-by: Sebastian Wennemers <sebastian.wennemers@sap.com>

* Update lib/extendOrdWithCustom.js

Co-authored-by: Sebastian Wennemers <sebastian.wennemers@sap.com>

* use lodash to merge two objects

* update snapshot

* fix small issues

* add one more test

* update ord.custom.json

* clean up logic to be clear

* clean up unittest

* clean up unittest

* change patch logic

* fix mutation bug

* use override instead of merge

* clean up

* clean up dead code and add cds.log replacing console.log

* give proper logger id

* refactor and fix

---------

Co-authored-by: Simon Heimler <heimlersimon@gmail.com>
Co-authored-by: Sebastian Wennemers <sebastian.wennemers@sap.com>
  • Loading branch information
3 people authored Oct 9, 2024
1 parent 1f70236 commit a159fee
Show file tree
Hide file tree
Showing 16 changed files with 581 additions and 18 deletions.
51 changes: 44 additions & 7 deletions __tests__/__snapshots__/ordCdsrc.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ exports[`Tests for default ORD document when .cdsrc.json is present Successfully
"description": "AdminService",
"entityTypeMappings": [
{
"entityTypeTargets": [],
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:BusinessPartner:v1",
},
],
},
],
"entryPoints": [
"/odata/v4/admin",
],
"extensible": {
"supported": "no",
"supported": "yes",
},
"ordId": "sap.test.cdsrc.sample:apiResource:AdminService:v1",
"partOfGroups": [
"sap.cds:service:sap.test.cdsrc.sample:AdminService",
],
"partOfPackage": "sap.test.cdsrc.sample:package:capirebookshopordsample-api:v1",
"releaseStatus": "active",
"resourceDefinitions": [
Expand Down Expand Up @@ -99,6 +100,32 @@ exports[`Tests for default ORD document when .cdsrc.json is present Successfully
"visibility": "public",
},
],
"dataProducts": [
{
"category": "business-object",
"description": "The Supplier data product offers access to all customers.",
"entityTypes": [
"sap.odm:entityType:BusinessPartner:v1",
"sap.sm:entityType:BusinessPartner:v1",
],
"lastUpdate": "2024-06-20T14:04:01+01:00",
"localId": "Supplier",
"ordId": "sap.sm:dataProduct:Supplier:v1",
"outputPorts": [
{
"ordId": "sap.sm:apiResource:SupplierService:v1",
},
],
"partOfPackage": "sap.sm:package:smDataProducts:v1",
"releaseStatus": "active",
"responsible": "sap:ach:CIC-DP-CO",
"shortDescription": "Ariba Supplier data product",
"title": "Supplier",
"type": "primary",
"version": "1.1.11",
"visibility": "public",
},
],
"description": "this is my custom description",
"eventResources": [
{
Expand Down Expand Up @@ -189,10 +216,20 @@ 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",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
"version": "1.0.1",
},
{
"description": "Description for capire bookshop ord sample version 2",
"ordId": "sap.test.cdsrc.sample:package:capirebookshopordsample-api:v2",
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:",
],
"shortDescription": "Short description for capire bookshop ord sample version 2",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "2.0.0",
},
],
"policyLevel": "sap:core:v1",
Expand Down
3 changes: 2 additions & 1 deletion __tests__/bookshop/.cdsrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"ord": {
"namespace": "sap.test.cdsrc.sample",
"description": "this is my custom description",
"policyLevel": "sap:core:v1"
"policyLevel": "sap:core:v1",
"customOrdContentFile": "./ord/custom.ord.json"
}
}
66 changes: 66 additions & 0 deletions __tests__/bookshop/ord/custom.ord.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"namespace": "should not update since has conflict with cdsrc.json",
"openResourceDiscovery": "should not update since not defined in cdsrc.json",
"packages": [
{
"description": "Description for capire bookshop ord sample version 2",
"ordId": "sap.test.cdsrc.sample:package:capirebookshopordsample-api:v2",
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:"
],
"shortDescription": "Short description for capire bookshop ord sample version 2",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "2.0.0"
},
{
"ordId": "sap.test.cdsrc.sample:package:capirebookshopordsample-event:v1",
"shortDescription": null,
"version": "1.0.1"
}
],
"apiResources": [
{
"partOfGroups": null,
"ordId": "sap.test.cdsrc.sample:apiResource:AdminService:v1",
"entityTypeMappings": [
{
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:BusinessPartner:v1"
}
]
}
],
"extensible": {
"supported": "yes"
}
}
],
"dataProducts": [
{
"ordId": "sap.sm:dataProduct:Supplier:v1",
"localId": "Supplier",
"title": "Supplier",
"shortDescription": "Ariba Supplier data product",
"description": "The Supplier data product offers access to all customers.",
"partOfPackage": "sap.sm:package:smDataProducts:v1",
"visibility": "public",
"releaseStatus": "active",
"version": "1.1.11",
"lastUpdate": "2024-06-20T14:04:01+01:00",
"type": "primary",
"category": "business-object",
"outputPorts": [
{
"ordId": "sap.sm:apiResource:SupplierService:v1"
}
],
"responsible": "sap:ach:CIC-DP-CO",
"entityTypes": [
"sap.odm:entityType:BusinessPartner:v1",
"sap.sm:entityType:BusinessPartner:v1"
]
}
]
}
6 changes: 3 additions & 3 deletions __tests__/ordCdsrc.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ord = require("../lib/ord");
const { join } = require("path");
const path = require("path");

// Mock the @sap/cds module
jest.mock("@sap/cds", () => {
Expand All @@ -15,7 +15,7 @@ describe("Tests for default ORD document when .cdsrc.json is present", () => {
let csn;

beforeAll(async () => {
csn = await cds.load(join(__dirname, "bookshop", "srv"));
csn = await cds.load(path.join(__dirname, "bookshop", "srv"));
});

test("Successfully create ORD Documents with defaults", () => {
Expand All @@ -33,7 +33,7 @@ describe("Tests for default ORD document when .cdsrc.json is present", () => {
document = ord(csn);
});

test("partOfPackage values are valid ORD IDs ", () => {
test("PartOfPackage values are valid ORD IDs ", () => {
for (const apiResource of document.apiResources) {
expect(apiResource.partOfPackage).toMatch(PACKAGE_ID_REGEX);
}
Expand Down
107 changes: 107 additions & 0 deletions __tests__/unittest/__snapshots__/extendOrdWithCustom.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`extendOrdWithCustom extendCustomORDContentIfExists should add new ord resources that are not supported by cap framework 1`] = `
{
"dataProducts": [
{
"category": "business-object",
"description": "The Supplier data product offers access to all customers.",
"entityTypes": [
"sap.odm:entityType:BusinessPartner:v1",
"sap.sm:entityType:BusinessPartner:v1",
],
"lastUpdate": "2024-06-20T14:04:01+01:00",
"localId": "Supplier",
"ordId": "sap.sm:dataProduct:Supplier:v1",
"outputPorts": [
{
"ordId": "sap.sm:apiResource:SupplierService:v1",
},
],
"partOfPackage": "sap.sm:package:smDataProducts:v1",
"releaseStatus": "active",
"responsible": "sap:ach:CIC-DP-CO",
"shortDescription": "Ariba Supplier data product",
"title": "Supplier",
"type": "primary",
"version": "1.1.11",
"visibility": "public",
},
],
}
`;

exports[`extendOrdWithCustom extendCustomORDContentIfExists should enhance the list of generated ord resources 1`] = `
{
"packages": [
{
"localId": "smDataProductsV1",
"ordId": "sap.sm:package:smDataProducts:v1",
},
{
"localId": "smDataProductsV2",
"ordId": "sap.sm:package:smDataProducts:v2",
},
],
}
`;

exports[`extendOrdWithCustom extendCustomORDContentIfExists should ignore and log warn if found ord top-level primitive property in customOrdFile 1`] = `
{
"packages": [
{
"localId": "smDataProducts",
"ordId": "sap.sm:package:smDataProducts:v1",
},
],
}
`;

exports[`extendOrdWithCustom extendCustomORDContentIfExists should should patch the existing generated ord resources 1`] = `
{
"apiResources": [
{
"entityTypeMappings": [
{
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:BusinessPartner:v1",
},
],
},
],
"entryPoints": [
"/odata/v4/admin",
],
"ordId": "sap.sm:apiResource:SupplierService:v1",
"partOfGroups": [
"sap.cds:service:sap.test.cdsrc.sample:AdminService",
],
"partOfPackage": "sap.sm:package:smDataProducts:v1",
},
{
"entityTypeMappings": [
{
"entityTypeTargets": [],
},
],
"ordId": "sap.sm:apiResource:orginalService:v2",
"partOfGroups": [
"sap.cds:service:sap.test.cdsrc.sample:originalService",
],
"partOfPackage": "sap.sm:package:smDataProducts:v2",
},
],
"packages": [
{
"localId": "overrideSmDataProductsV1",
"ordId": "sap.sm:package:smDataProducts:v1",
"version": "1.1.1",
},
{
"localId": "smDataProductsV2",
"ordId": "sap.sm:package:smDataProducts:v2",
},
],
}
`;
Loading

0 comments on commit a159fee

Please sign in to comment.