Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RoshniNaveenaS committed Aug 23, 2024
1 parent 9d2900c commit 290c112
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compile/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ module.exports.csdl2openapi = function (
try {
servers = JSON.parse(serversObject);
// if csdl.$Version is 4.01 then protocol is rest if it is less than 4.01 then protocol is odata
const protocol = csdl.$Version <= '4.01' ? protocols['odata/v4'] : protocols.rest;
const protocol = csdl.$Version <= '4.01' ? 'odata/v4' : 'rest';
// append /protocol/{$serviceName} to the URL
servers.forEach(server => { server.url = server.url + '/' + protocol + csdl.$EntityContainer });
} catch (err) {
Expand Down
11 changes: 11 additions & 0 deletions test/lib/compile/openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ describe('OpenAPI export', () => {
expect(openapi.servers).toBeTruthy();
});

test('options: Multiple servers', () => {
const csn = cds.compile.to.csn(`
service A {entity E { key ID : UUID; };};`
);
const serverObj = "[{\n \"url\": \"https://{customer1Id}.saas-app.com:{port}/v2\",\n \"variables\": {\n \"customer1Id\": \"demo\",\n \"description\": \"Customer1 ID assigned by the service provider\"\n }\n}, {\n \"url\": \"https://{customer2Id}.saas-app.com:{port}/v2\",\n \"variables\": {\n \"customer2Id\": \"demo\",\n \"description\": \"Customer2 ID assigned by the service provider\"\n }\n}]"
const openapi = toOpenApi(csn, { 'openapi:servers': serverObj });
expect(openapi.servers).toBeTruthy();
expect(openapi.servers[0].url).toMatch('https://{customer1Id}.saas-app.com:{port}/v2/odata/v4A.EntityContainer')
});


test('options: servers - wrong JSON', () => {
const csn = cds.compile.to.csn(`
service A {entity E { key ID : UUID; };};`
Expand Down

0 comments on commit 290c112

Please sign in to comment.