-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab2acae
commit 38effe1
Showing
4 changed files
with
26 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters