Skip to content

Commit

Permalink
tmp change
Browse files Browse the repository at this point in the history
  • Loading branch information
aramovic79 committed Nov 12, 2024
1 parent ab2acae commit 38effe1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 114 deletions.
88 changes: 10 additions & 78 deletions __tests__/noOrdInCdsrc.test.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,22 @@
const cds = require("@sap/cds");
const ord = require("../lib/ord");
const path = require("path");
const csn = require("./__mocks__/publicResourcesCsn.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");
cds.env = {};
describe("Tests for default ORD document when .cdsrc.json is present", () => {
beforeAll(async () => { });

return cds;
});


describe.skip("Tests for default ORD document when .cdsrc.json is present", () => {
let csn;
beforeEach(() => {
cds.root = path.join(__dirname, "bookshop");
cds.env = {};
});

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

test("Successfully create ORD Documents with defaults", () => {
const document = ord(csn);
expect(document).toMatchSnapshot();
});

describe("apiResources", () => {
// eslint-disable-next-line no-useless-escape
const PACKAGE_ID_REGEX =
/^([a-z0-9]+(?:[.][a-z0-9]+)*):(package):([a-zA-Z0-9._\-]+):(v0|v[1-9][0-9]*)$/;

let document;

beforeAll(() => {
document = ord(csn);
});

test("PartOfPackage values are valid ORD IDs ", () => {
for (const apiResource of document.apiResources) {
expect(apiResource.partOfPackage).toMatch(PACKAGE_ID_REGEX);
}
});

test("The partOfPackage references an existing package", () => {
for (const apiResource of document.apiResources) {
expect(
document.packages.find(
(pck) => pck.ordId === apiResource.partOfPackage
)
).toBeDefined();
}
});
});

describe("eventResources", () => {
// eslint-disable-next-line no-useless-escape
const GROUP_ID_REGEX =
/^([a-z0-9-]+(?:[.][a-z0-9-]+)*):([a-zA-Z0-9._\-/]+):([a-z0-9-]+(?:[.][a-z0-9-]+)*):(?<service>[a-zA-Z0-9._\-/]+)$/;

let document;

beforeAll(() => {
document = ord(csn);
});

test("Assigned to exactly one CDS Service group", () => {
for (const eventResource of document.eventResources) {
expect(eventResource.partOfGroups.length).toEqual(1);
}
});

test("The CDS Service Group ID includes the CDS Service identifier", () => {
for (const eventResource of document.eventResources) {
const [groupId] = eventResource.partOfGroups;
expect(groupId).toMatch(GROUP_ID_REGEX);

const match = GROUP_ID_REGEX.exec(groupId);
if (match && match.groups?.service) {
let service = match.groups?.service;
if (service.startsWith("undefined"))
service = service.replace("undefined.", "");
const definition = csn.definitions[service];
expect(definition).toBeDefined();
expect(definition.kind).toEqual("service");
}
}
});
expect(document).not.toBeUndefined();
});
});
9 changes: 5 additions & 4 deletions __tests__/ordCdsrc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const path = require("path");
// Mock the @sap/cds module
jest.mock("@sap/cds", () => {
const path = require("path");
let originalCds = jest.requireActual("@sap/cds");
originalCds.root = path.join(__dirname, "bookshop");
return originalCds;
let cds = jest.requireActual("@sap/cds");
cds.root = path.join(__dirname, "bookshop");

return cds;
});

jest.mock("../lib/date", () => ({
Expand All @@ -19,7 +20,7 @@ describe("Tests for default ORD document when .cdsrc.json is present", () => {
let csn;

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

test("Successfully create ORD Documents with defaults", () => {
Expand Down
13 changes: 3 additions & 10 deletions __tests__/ordPackageJson.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ const cds = require("@sap/cds");
const ord = require("../lib/ord");
const path = require("path");


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

jest.mock("../lib/date", () => ({
getRFC3339Date: jest.fn(() => "2024-11-04T14:33:25+01:00")
}));
Expand All @@ -19,9 +10,11 @@ describe("Tests for default ORD document when .cdsrc.json is not present", () =>
let csn;

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

beforeEach(() => {
cds.root = path.join(__dirname, "bookshop");
});

test("Successfully create ORD Documents with defaults", () => {
Expand Down
30 changes: 8 additions & 22 deletions __tests__/protectedServices.test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
const cds = require("@sap/cds");
const internal_csn = require("./__mocks__/internalResourcesCsn.json");
const ord = require("../lib/ord");
const path = require("path");
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/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", () => {
beforeAll(() => {
cds.root = path.join(__dirname, "bookshop");
cds.env = {};
});

afterAll(() => {
jest.clearAllMocks();
})
Expand Down

0 comments on commit 38effe1

Please sign in to comment.