Skip to content

Commit

Permalink
change the version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aramovic79 committed Dec 9, 2024
1 parent 05a3736 commit a5fdaee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions __tests__/mockedCsn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const cds = require("@sap/cds");
const path = require("path");

describe("Tests for ORD document generated out of mocked csn files", () => {
let ord;
let ord; //, errorSpy;

function checkOrdDocument(csn) {
const document = ord(csn);
Expand All @@ -26,11 +26,12 @@ describe("Tests for ORD document generated out of mocked csn files", () => {
description: "this is my custom description",
policyLevel: "sap:core:v1"
};
// errorSpy = jest.spyOn(console, "error");
});

afterAll(() => {
jest.restoreAllMocks();
jest.clearAllMocks();
jest.resetAllMocks();
});

describe("Tests for ORD document when .cdsrc.json has no `ord` property", () => {
Expand Down Expand Up @@ -100,4 +101,12 @@ describe("Tests for ORD document generated out of mocked csn files", () => {
expect(document.eventResources[0].ordId).toEqual(expect.stringContaining("CatalogService"));
});
});

describe("Tests for ORD document when namespace is not correctly defined", () => {
test("Namespace is not correctly defined in cdsrc.json: throw error", () => {
cds.env.ord.namespace = "invalid_namespace";
const csn = require("./__mocks__/publicResourcesCsn.json");
expect(() => ord(csn)).toThrowError(expect.objectContaining({"message": expect.stringContaining("Namespace is not correctly defined in cdsrc.json")}));
});
});
});
4 changes: 2 additions & 2 deletions lib/ord.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ function _getConsumptionBundles(appConfig) {
function validateNamespace(appConfig) {
const validateSystemNamespace = new RegExp(`^${appConfig.eventApplicationNamespace}\\.[^.]+\\..+$`);
if (
appConfig.ordNamespace === undefined &&
appConfig.ordNamespace === undefined ||
!validateSystemNamespace.test(appConfig.ordNamespace)
) {
let error = new Error(
`Namespace is not defined in cdsrc.json or it is not in the format of ${appConfig.eventApplicationNamespace}.<appName>.<service>`
`Namespace is not correctly defined in cdsrc.json or it is not in the format of ${appConfig.eventApplicationNamespace}.<appName>.<service>`
);
Logger.error('Namespace error:', error.message);
throw error;
Expand Down
2 changes: 1 addition & 1 deletion lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function _getTitleFromServiceName(srv) {
*/
function _getEntityVersion(entity) {
const entityVersion = entity.ordId.split(":").pop();
const version = entityVersion === "v1" ? "1.0.0" : entityVersion;
const version = entityVersion.replace("v", "") + ".0.0"; // TODO: version can be stated/overwritten by annotation
if (!SEM_VERSION_REGEX.test(version)) {
Logger.warn(`Entity version "${version}" is not a valid semantic version.`);
}
Expand Down

0 comments on commit a5fdaee

Please sign in to comment.