Skip to content

Commit

Permalink
add tests for protected resources
Browse files Browse the repository at this point in the history
  • Loading branch information
aramovic79 committed Nov 12, 2024
1 parent 7a5dfe4 commit 9616090
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@requires": "authenticated-user",
"@ORD.Extensions.title": "This is test AdminService title",
"@ORD.Extensions.shortDescription": "short description for test AdminService",
"@ORD.Extensions.visibility": "private",
"@ORD.Extensions.visibility": "internal",
"@ORD.Extensions.version": "2.0.0",
"@ORD.Extensions.extensible.supported": "yes",
"@ORD.Extensions.entityTypeMappings.entityTypeTargets": [
Expand Down Expand Up @@ -316,7 +316,7 @@
"@path": "/browse",
"@ORD.Extensions.title": "This is test Catalog Service title",
"@ORD.Extensions.shortDescription": "short description for test CatalogService",
"@ORD.Extensions.visibility": "private",
"@ORD.Extensions.visibility": "internal",
"@ORD.Extensions.version": "2.0.0",
"@ORD.Extensions.extensible.supported": "yes"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
"@path": "/browse",
"@ORD.Extensions.title": "This is test Cinema Service title",
"@ORD.Extensions.shortDescription": "short description for test CinemaService",
"@ORD.Extensions.visibility": "internal",
"@ORD.Extensions.visibility": "private",
"@ORD.Extensions.version": "1.0.0",
"@ORD.Extensions.extensible.supported": "yes"
},
Expand Down
46 changes: 46 additions & 0 deletions __tests__/protectedResources.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const ord = require("../lib/ord");
const private_csn = require("./__mocks__/privateResourcesCsn.json");
const internal_csn = require("./__mocks__/internalResourcesCsn.json");


// Mock the @sap/cds module
jest.mock("@sap/cds", () => {
const path = require("path");
let cds = jest.requireActual("@sap/cds");
cds.root = path.join(__dirname, "bookshop");

return cds;
});

jest.mock("../lib/date", () => ({
getRFC3339Date: jest.fn(() => "2024-11-04T14:33:25+01:00"),
}));

jest.mock("../lib/extendOrdWithCustom", () => ({
extendCustomORDContentIfExists: jest.fn(
(_appConfig, ordContent, _lazyLogger) => {
console.log(
"The custom.ord.json file is not considered for the purpose of this test."
);
return ordContent;
}
),
}));

describe("Tests for ORD document when there is no public service", () => {
test("Private services: Successfully create ORD Documents without packages, empty apiResources and eventResources lists", () => {
const document = ord(private_csn);

expect(document.packages).not.toBeDefined();
expect(document.apiResources).toHaveLength(0);
expect(document.eventResources).toHaveLength(0);
});

test("Internal services: Successfully create ORD Documents without packages, empty apiResources and eventResources lists", () => {
const document = ord(internal_csn);

expect(document.packages).not.toBeDefined();
expect(document.apiResources).toHaveLength(0);
expect(document.eventResources).toHaveLength(0);
});
});
7 changes: 1 addition & 6 deletions lib/ord.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,8 @@ module.exports = (csn) => {

let ordDocument = createDefaultORDDocument(linkedCsn, appConfig);
const packageIds = extractPackageIds(ordDocument);
// TODO: add testcase without apiResources or event, no empty package
ordDocument.apiResources = _getAPIResources(linkedCsn, appConfig, packageIds);
const eventResources = _getEventResources(linkedCsn, appConfig, packageIds);
if (eventResources.length) {
ordDocument.eventResources = eventResources;
}

ordDocument.eventResources = _getEventResources(linkedCsn, appConfig, packageIds);
ordDocument = extendCustomORDContentIfExists(appConfig, ordDocument, logger);

return ordDocument;
Expand Down

0 comments on commit 9616090

Please sign in to comment.