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

Feat: extend custom ORD content #63

Merged
merged 25 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
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
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
96 changes: 96 additions & 0 deletions __tests__/unittest/__snapshots__/extendOrdWithCustom.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`extendOrdWithCustom extendCustomORDContentIfExists should add new ord resources that are not supported by cap framework 1`] = `
zongqichen marked this conversation as resolved.
Show resolved Hide resolved
{
"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 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