Skip to content

Commit

Permalink
Adjust unittest for latest main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
zongqichen committed Sep 2, 2024
1 parent 1825f1e commit 6eaa523
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 41 deletions.
68 changes: 34 additions & 34 deletions __tests__/unittest/defaults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,106 +2,106 @@ const defaults = require('../../lib/defaults');

describe('defaults', () => {
describe('$schema', () => {
const test$schemaDefaultValue = "https://sap.github.io/open-resource-discovery/spec-v1/interfaces/Document.schema.json";
const test$schemaDefaultValue = 'https://sap.github.io/open-resource-discovery/spec-v1/interfaces/Document.schema.json';
it('should return default value', () => {
expect(defaults.$schema).toEqual(test$schemaDefaultValue);
});
});

describe('openResourceDiscovery', () => {
const testOpenResourceDiscoveryDefaultValue = "1.9";
const testOpenResourceDiscoveryDefaultValue = '1.9';
it('should return default value', () => {
expect(defaults.openResourceDiscovery).toEqual(testOpenResourceDiscoveryDefaultValue);
});
});

describe('policyLevel', () => {
const testPolicyLevelDefaultValue = "none";
const testPolicyLevelDefaultValue = 'none';
it('should return default value', () => {
expect(defaults.policyLevel).toEqual(testPolicyLevelDefaultValue);
});
});

describe('description', () => {
const testDescriptionDefaultValue = "this is an application description";
const testDescriptionDefaultValue = 'this is an application description';
it('should return default value', () => {
expect(defaults.description).toEqual(testDescriptionDefaultValue);
});
});

describe('products', () => {
const testProductsName = "My Product";
const testProductsName = 'My Product';
it('should return default value', () => {
expect(defaults.products(testProductsName)).toEqual([
{
ordId: "customer:product:My.Product:",
title: "My Product",
shortDescription: "Description for My Product",
vendor: "customer:vendor:customer:"
ordId: 'customer:product:My.Product:',
title: 'My Product',
shortDescription: 'Description for My Product',
vendor: 'customer:vendor:customer:'
}
]);
});
});

describe('groupTypeId', () => {
const testGroupTypeIdDefaultValue = "sap.cds:service";
const testGroupTypeIdDefaultValue = 'sap.cds:service';
it('should return default value', () => {
expect(defaults.groupTypeId).toEqual(testGroupTypeIdDefaultValue);
});
});

describe('packages', () => {
const testGetPackageDataName = "My Package";
const testGetPackageCapNamespace = "sample";
const testGetPackageDataName = 'My Package';
const testGetPackageCapNamespace = 'sample';
it('should return default value if policyLevel contains sap', () => {
const testPolicyLevel = "sap:policy";
const testPolicyLevel = 'sap:policy';
const testCreatePackage = (_, tag) => {
return {
ordId: `MyPackage:package:${testGetPackageCapNamespace}${tag}`,
title: `sample title for MyPackage`,
shortDescription: "Here is the shortDescription for packages",
description: "Here is the description for packages",
version: "1.0.0",
title: `My Package`,
shortDescription: 'Short description for My Package',
description: 'Description for My Package',
version: '1.0.0',
partOfProducts: [`customer:product:My.Package:`],
vendor: "customer:vendor:SAP:"
vendor: 'customer:vendor:Customer:'
};
};
const testCreatePackageReturnValue = [testCreatePackage(testGetPackageDataName, "-api:v1"), testCreatePackage(testGetPackageDataName, "-event:v1")];
const testCreatePackageReturnValue = [testCreatePackage(testGetPackageDataName, '-api:v1'), testCreatePackage(testGetPackageDataName, '-event:v1')];

expect(defaults.packages(testGetPackageDataName, testPolicyLevel, testGetPackageCapNamespace)).toEqual(testCreatePackageReturnValue);
});

it('should return default value if policyLevel does not contain sap', () => {
const testPolicyLevel = "policy";
const testPolicyLevel = 'policy';
const testCreatePackage = (_, tag) => {
return {
ordId: `MyPackage:package:${testGetPackageCapNamespace}${tag}`,
title: `sample title for MyPackage`,
shortDescription: "Here is the shortDescription for packages",
description: "Here is the description for packages",
version: "1.0.0",
title: `My Package`,
shortDescription: 'Short description for My Package',
description: 'Description for My Package',
version: '1.0.0',
partOfProducts: [`customer:product:My.Package:`],
vendor: "customer:vendor:SAP:"
vendor: 'customer:vendor:Customer:'
};
};
const testCreatePackageReturnValue = [testCreatePackage(testGetPackageDataName, ":v1")];
const testCreatePackageReturnValue = [testCreatePackage(testGetPackageDataName, ':v1')];

expect(defaults.packages(testGetPackageDataName, testPolicyLevel, testGetPackageCapNamespace)).toEqual(testCreatePackageReturnValue);
});
});

describe('consumptionBundles', () => {
const testConsumptionBundlesName = "My Consumption Bundle";
const testConsumptionBundlesName = 'My Consumption Bundle';
it('should return default value', () => {
expect(defaults.consumptionBundles(testConsumptionBundlesName)).toEqual([
{
ordId: "MyConsumptionBundle:consumptionBundle:unknown:v1",
version: "1.0.0",
title: "Unprotected resources",
ordId: 'MyConsumptionBundle:consumptionBundle:unknown:v1',
version: '1.0.0',
title: 'Unprotected resources',
shortDescription:
"If we have another protected API then it will be another object",
'If we have another protected API then it will be another object',
description:
"This Consumption Bundle contains all resources of the reference app which are unprotected and do not require authentication",
'This Consumption Bundle contains all resources of the reference app which are unprotected and do not require authentication',
}
]);
});
Expand Down Expand Up @@ -130,10 +130,10 @@ describe('defaults', () => {
openResourceDiscoveryV1: {
documents: [
{
url: "/open-resource-discovery/v1/documents/1",
url: '/open-resource-discovery/v1/documents/1',
accessStrategies: [
{
type: "open",
type: 'open',
},
],
},
Expand Down
9 changes: 2 additions & 7 deletions __tests__/unittest/templates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('templates', () => {
describe('fCreateEntityTypeTemplate', () => {
it('should return default value', () => {
expect(templates.fCreateEntityTypeTemplate(linkedModel)).toEqual({
// TODO: fix undefined. Root cause: get the value from ${entity["@ODM.entityName"]} without setting default value
ordId: "sap.odm:entityType:undefined:v1"
// TODO: fix undefined. Root cause: get the value from ${entity['@ODM.entityName']} without setting default value
ordId: 'sap.odm:entityType:undefined:v1'
});
});
});
Expand Down Expand Up @@ -127,11 +127,6 @@ describe('templates', () => {
partOfPackage: undefined,
partOfGroups: ['sap.cds:service:customer:undefined.MyService'],
releaseStatus: 'active',
partOfConsumptionBundles: [
{
ordId: 'customer:consumptionBundle:noAuth:v1',
},
],
apiProtocol: 'odata-v4',
resourceDefinitions: [
{
Expand Down

0 comments on commit 6eaa523

Please sign in to comment.