Skip to content

Commit

Permalink
Add more test cases for integrationDependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipto-at-sap committed Nov 19, 2024
1 parent cbb0808 commit 9268a91
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 12 deletions.
61 changes: 55 additions & 6 deletions __tests__/ordCdsrc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,67 @@ describe("Tests for default ORD document when .cdsrc.json is present", () => {
});

describe("integrationDependency", () => {
// 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("ordId values are valid ORD IDs", () => {
const ORD_ID_REGEX = /^([a-z0-9]+(?:[.][a-z0-9]+)*):integrationDependency:([a-zA-Z0-9.-]+):(v0|v[1-9][0-9]*)$/;
for (const dep of document.integrationDependency) {
expect(dep.ordId).toMatch(ORD_ID_REGEX);
}
});

test("partOfPackage values are valid package IDs", () => {
const PACKAGE_ID_REGEX = /^([a-z0-9]+(?:[.][a-z0-9]+)*):(package):([a-zA-Z0-9._-]+):(v0|v[1-9][0-9]*)$/;
for (const dep of document.integrationDependency) {
expect(dep.partOfPackage).toBeDefined();
expect(dep.partOfPackage).toMatch(PACKAGE_ID_REGEX);
}
});

test("aspects contain valid eventResources", () => {
for (const dep of document.integrationDependency) {
expect(dep.aspects).toBeDefined();
for (const aspect of dep.aspects) {
expect(aspect.eventResources).toBeDefined();
expect(Array.isArray(aspect.eventResources)).toBe(true);
}
}
});

test("eventResources ordId values are valid", () => {
const EVENT_RESOURCE_ORD_ID_REGEX = /^([a-z0-9]+(?:[.][a-z0-9]+)*):eventResource:([a-zA-Z0-9._-]+):(v0|v[1-9][0-9]*)$/;
for (const dep of document.integrationDependency) {
for (const aspect of dep.aspects) {
for (const eventResource of aspect.eventResources) {
expect(eventResource.ordId).toMatch(EVENT_RESOURCE_ORD_ID_REGEX);
}
}
}
});

test("eventResources subset contains valid eventType fields", () => {
for (const dep of document.integrationDependency) {
for (const aspect of dep.aspects) {
for (const eventResource of aspect.eventResources) {
expect(eventResource.subset).toBeDefined();
expect(Array.isArray(eventResource.subset)).toBe(true);
for (const subsetItem of eventResource.subset) {
expect(subsetItem.eventType).toBeDefined();
expect(typeof subsetItem.eventType).toBe("string");
}
}
}
}
});

test("partOfPackage matches an existing package ordId", () => {
const packageOrdIds = document.packages.map(pkg => pkg.ordId);
for (const dep of document.integrationDependency) {
expect(packageOrdIds).toContain(dep.partOfPackage);
}
});
});
Expand Down
61 changes: 55 additions & 6 deletions __tests__/ordPackageJson.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,67 @@ describe("Tests for default ORD document when .cdsrc.json is not present", () =>
});

describe("integrationDependency", () => {
// 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("ordId values are valid ORD IDs", () => {
const ORD_ID_REGEX = /^([a-z0-9]+(?:[.][a-z0-9]+)*):integrationDependency:([a-zA-Z0-9.-]+):(v0|v[1-9][0-9]*)$/;
for (const dep of document.integrationDependency) {
expect(dep.ordId).toMatch(ORD_ID_REGEX);
}
});

test("partOfPackage values are valid package IDs", () => {
const PACKAGE_ID_REGEX = /^([a-z0-9]+(?:[.][a-z0-9]+)*):(package):([a-zA-Z0-9._-]+):(v0|v[1-9][0-9]*)$/;
for (const dep of document.integrationDependency) {
expect(dep.partOfPackage).toBeDefined();
expect(dep.partOfPackage).toMatch(PACKAGE_ID_REGEX);
}
});

test("aspects contain valid eventResources", () => {
for (const dep of document.integrationDependency) {
expect(dep.aspects).toBeDefined();
for (const aspect of dep.aspects) {
expect(aspect.eventResources).toBeDefined();
expect(Array.isArray(aspect.eventResources)).toBe(true);
}
}
});

test("eventResources ordId values are valid", () => {
const EVENT_RESOURCE_ORD_ID_REGEX = /^([a-z0-9]+(?:[.][a-z0-9]+)*):eventResource:([a-zA-Z0-9._-]+):(v0|v[1-9][0-9]*)$/;
for (const dep of document.integrationDependency) {
for (const aspect of dep.aspects) {
for (const eventResource of aspect.eventResources) {
expect(eventResource.ordId).toMatch(EVENT_RESOURCE_ORD_ID_REGEX);
}
}
}
});

test("eventResources subset contains valid eventType fields", () => {
for (const dep of document.integrationDependency) {
for (const aspect of dep.aspects) {
for (const eventResource of aspect.eventResources) {
expect(eventResource.subset).toBeDefined();
expect(Array.isArray(eventResource.subset)).toBe(true);
for (const subsetItem of eventResource.subset) {
expect(subsetItem.eventType).toBeDefined();
expect(typeof subsetItem.eventType).toBe("string");
}
}
}
}
});

test("partOfPackage matches an existing package ordId", () => {
const packageOrdIds = document.packages.map(pkg => pkg.ordId);
for (const dep of document.integrationDependency) {
expect(packageOrdIds).toContain(dep.partOfPackage);
}
});
});
Expand Down

0 comments on commit 9268a91

Please sign in to comment.