Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add test for cds.rs without ord and services with no public resources #92

Merged
merged 6 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,578 changes: 2,578 additions & 0 deletions __tests__/__mocks__/internalResourcesCsn.json

Large diffs are not rendered by default.

2,578 changes: 2,578 additions & 0 deletions __tests__/__mocks__/privateResourcesCsn.json

Large diffs are not rendered by default.

2,578 changes: 2,578 additions & 0 deletions __tests__/__mocks__/publicResourcesCsn.json

Large diffs are not rendered by default.

310 changes: 310 additions & 0 deletions __tests__/__snapshots__/noOrdInCdsrc.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,310 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tests for ORD document when .cdsrc.json has no \`ord\` property Successfully create ORD Documents with no \`ord\` in .cdsrc.json 1`] = `
{
"$schema": "https://sap.github.io/open-resource-discovery/spec-v1/interfaces/Document.schema.json",
"apiResources": [
{
"apiProtocol": "odata-v4",
"description": "Description for AdminService",
"entityTypeMappings": {
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:test-from-extension:v1",
},
],
},
"entryPoints": [
"/odata/v4/admin",
],
"extensible": {
"supported": "yes",
},
"lastUpdate": "2024-11-04T14:33:25+01:00",
"ordId": "customer.capirebookshopordsample:apiResource:AdminService:v1",
"partOfGroups": [
"sap.cds:service:customer.capirebookshopordsample:AdminService",
],
"partOfPackage": "customer.capirebookshopordsample:package:capirebookshopordsample:v1",
"releaseStatus": "active",
"resourceDefinitions": [
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/json",
"type": "openapi-v3",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/AdminService.oas3.json",
},
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/xml",
"type": "edmx",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/AdminService.edmx",
},
],
"shortDescription": "short description for test AdminService",
"title": "This is test AdminService title",
"version": "2.0.0",
"visibility": "public",
},
{
"apiProtocol": "odata-v4",
"description": "Description for CatalogService",
"entityTypeMappings": [
{
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:odm.bookshop.Authors:v1",
},
],
},
],
"entryPoints": [
"/browse",
],
"extensible": {
"supported": "yes",
},
"lastUpdate": "2024-11-04T14:33:25+01:00",
"ordId": "customer.capirebookshopordsample:apiResource:CatalogService:v1",
"partOfGroups": [
"sap.cds:service:customer.capirebookshopordsample:CatalogService",
],
"partOfPackage": "customer.capirebookshopordsample:package:capirebookshopordsample:v1",
"releaseStatus": "active",
"resourceDefinitions": [
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/json",
"type": "openapi-v3",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CatalogService.oas3.json",
},
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/xml",
"type": "edmx",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CatalogService.edmx",
},
],
"shortDescription": "short description for test CatalogService",
"title": "This is test Catalog Service title",
"version": "2.0.0",
"visibility": "public",
},
{
"apiProtocol": "odata-v4",
"description": "Description for CinemaService",
"entityTypeMappings": [
{
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:odm.bookshop.Authors:v1",
},
],
},
],
"entryPoints": [
"/browse",
],
"extensible": {
"supported": "yes",
},
"lastUpdate": "2024-11-04T14:33:25+01:00",
"ordId": "customer.capirebookshopordsample:apiResource:CinemaService:v1",
"partOfGroups": [
"sap.cds:service:customer.capirebookshopordsample:CinemaService",
],
"partOfPackage": "customer.capirebookshopordsample:package:capirebookshopordsample:v1",
"releaseStatus": "active",
"resourceDefinitions": [
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/json",
"type": "openapi-v3",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CinemaService.oas3.json",
},
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/xml",
"type": "edmx",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CinemaService.edmx",
},
],
"shortDescription": "short description for test CinemaService",
"title": "This is test Cinema Service title",
"version": "1.0.0",
"visibility": "public",
},
],
"consumptionBundles": [
{
"description": "This Consumption Bundle contains all resources of the reference app which are unprotected and do not require authentication",
"lastUpdate": "2024-11-04T14:33:25+01:00",
"ordId": "capirebookshopordsample:consumptionBundle:noAuth:v1",
"shortDescription": "If we have another protected API then it will be another object",
"title": "Unprotected resources",
"version": "1.0.0",
},
],
"description": "this is an application description",
"eventResources": [
{
"description": "CAP Event resource describing events / messages.",
"entityTypeMappings": {
"entityTypeTargets": [
{
"ordId": "sap.odm:entityType:test-from-extension:v1",
},
],
},
"extensible": {
"supported": "yes",
},
"lastUpdate": "2024-11-04T14:33:25+01:00",
"ordId": "customer.capirebookshopordsample:eventResource:AdminService:v1",
"partOfGroups": [
"sap.cds:service:customer.capirebookshopordsample:AdminService",
],
"partOfPackage": "customer.capirebookshopordsample:package:capirebookshopordsample:v1",
"releaseStatus": "active",
"resourceDefinitions": [
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/json",
"type": "asyncapi-v2",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/AdminService.asyncapi2.json",
},
],
"shortDescription": "short description for test AdminService",
"title": "This is test AdminService title",
"version": "2.0.0",
"visibility": "public",
},
{
"description": "CAP Event resource describing events / messages.",
"extensible": {
"supported": "yes",
},
"lastUpdate": "2024-11-04T14:33:25+01:00",
"ordId": "customer.capirebookshopordsample:eventResource:CatalogService:v1",
"partOfGroups": [
"sap.cds:service:customer.capirebookshopordsample:CatalogService",
],
"partOfPackage": "customer.capirebookshopordsample:package:capirebookshopordsample:v1",
"releaseStatus": "active",
"resourceDefinitions": [
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/json",
"type": "asyncapi-v2",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CatalogService.asyncapi2.json",
},
],
"shortDescription": "short description for test CatalogService",
"title": "This is test Catalog Service title",
"version": "2.0.0",
"visibility": "public",
},
{
"description": "CAP Event resource describing events / messages.",
"extensible": {
"supported": "yes",
},
"lastUpdate": "2024-11-04T14:33:25+01:00",
"ordId": "customer.capirebookshopordsample:eventResource:CinemaService:v1",
"partOfGroups": [
"sap.cds:service:customer.capirebookshopordsample:CinemaService",
],
"partOfPackage": "customer.capirebookshopordsample:package:capirebookshopordsample:v1",
"releaseStatus": "active",
"resourceDefinitions": [
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/json",
"type": "asyncapi-v2",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/CinemaService.asyncapi2.json",
},
],
"shortDescription": "short description for test CinemaService",
"title": "This is test Cinema Service title",
"version": "1.0.0",
"visibility": "public",
},
],
"groups": [
{
"groupId": "sap.cds:service:customer.capirebookshopordsample:AdminService",
"groupTypeId": "sap.cds:service",
"title": "This is test AdminService title",
},
{
"groupId": "sap.cds:service:customer.capirebookshopordsample:CatalogService",
"groupTypeId": "sap.cds:service",
"title": "This is test Catalog Service title",
},
{
"groupId": "sap.cds:service:customer.capirebookshopordsample:CinemaService",
"groupTypeId": "sap.cds:service",
"title": "This is test Cinema Service title",
},
],
"openResourceDiscovery": "1.9",
"packages": [
{
"description": "Description for capire bookshop ord sample",
"ordId": "customer.capirebookshopordsample:package:capirebookshopordsample:v1",
"partOfProducts": [
"customer:product:capire.bookshop.ord.sample:",
],
"shortDescription": "Short description for capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
],
"policyLevel": "none",
"products": [
{
"ordId": "customer:product:capire.bookshop.ord.sample:",
"shortDescription": "Description for capire bookshop ord sample",
"title": "capire bookshop ord sample",
"vendor": "customer:vendor:customer:",
},
],
}
`;
26 changes: 26 additions & 0 deletions __tests__/noOrdInCdsrc.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const cds = require("@sap/cds");
const ord = require("../lib/ord");
const path = require("path");
const csn = require("./__mocks__/publicResourcesCsn.json");

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

describe("Tests for ORD document when .cdsrc.json has no `ord` property", () => {
beforeAll(() => {
cds.root = path.join(__dirname, "bookshop");
cds.env = {};
});

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

test("Successfully create ORD Documents with no `ord` in .cdsrc.json", () => {

const document = ord(csn);
expect(document).not.toBeUndefined();
expect(document).toMatchSnapshot();
});
});
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
Loading