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

Feat: Add Unittests #54

Merged
merged 13 commits into from
Sep 9, 2024
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://EditorConfig.org

root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
charset = utf-8
94 changes: 94 additions & 0 deletions __tests__/unittest/__snapshots__/defaults.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`defaults $schema should return default value 1`] = `"https://sap.github.io/open-resource-discovery/spec-v1/interfaces/Document.schema.json"`;

exports[`defaults baseTemplate should return default value 1`] = `
{
"openResourceDiscoveryV1": {
"documents": [
{
"accessStrategies": [
{
"type": "open",
},
],
"url": "/open-resource-discovery/v1/documents/1",
},
],
},
}
`;

exports[`defaults consumptionBundles should return default value 1`] = `
[
{
"description": "This Consumption Bundle contains all resources of the reference app which are unprotected and do not require authentication",
"ordId": "MyConsumptionBundle:consumptionBundle:unknown:v1",
"shortDescription": "If we have another protected API then it will be another object",
"title": "Unprotected resources",
"version": "1.0.0",
},
]
`;

exports[`defaults description should return default value 1`] = `"this is an application description"`;

exports[`defaults groupTypeId should return default value 1`] = `"sap.cds:service"`;

exports[`defaults openResourceDiscovery should return default value 1`] = `"1.9"`;

exports[`defaults packages should return default value if policyLevel contains sap 1`] = `
[
{
"description": "Description for My Package",
"ordId": "MyPackage:package:sample-api:v1",
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description for My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
{
"description": "Description for My Package",
"ordId": "MyPackage:package:sample-event:v1",
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description for My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
]
`;

exports[`defaults packages should return default value if policyLevel does not contain sap 1`] = `
[
{
"description": "Description for My Package",
"ordId": "MyPackage:package:sample:v1",
"partOfProducts": [
"customer:product:My.Package:",
],
"shortDescription": "Short description for My Package",
"title": "My Package",
"vendor": "customer:vendor:Customer:",
"version": "1.0.0",
},
]
`;

exports[`defaults policyLevel should return default value 1`] = `"none"`;

exports[`defaults products should return default value 1`] = `
[
{
"ordId": "customer:product:My.Product:",
"shortDescription": "Description for My Product",
"title": "My Product",
"vendor": "customer:vendor:customer:",
},
]
`;
110 changes: 110 additions & 0 deletions __tests__/unittest/__snapshots__/templates.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`templates checkEntityFunctionAction should fail when entity is empty 1`] = `
[
{
"entitySet": "customer.testNamespace123.Books",
"entitySetMapping": "undefined:entitySet:customer.testNamespace123.Books:v1",
"entityType": "customer.testNamespace123.Books",
"entityTypeMapping": "undefined:entityType:customer.testNamespace123.Books:v1",
"name": "customer.testNamespace123.Books",
"type": "entity",
},
]
`;

exports[`templates checkEntityFunctionAction should return entity 1`] = `
[
{
"entitySet": "customer.testNamespace123.Books",
"entitySetMapping": "undefined:entitySet:customer.testNamespace123.Books:v1",
"entityType": "customer.testNamespace123.Books",
"entityTypeMapping": "undefined:entityType:customer.testNamespace123.Books:v1",
"name": "customer.testNamespace123.Books",
"type": "entity",
},
]
`;

exports[`templates fCreateAPIResourceTemplate should create API resource template correctly 1`] = `
[
{
"apiProtocol": "odata-v4",
"description": "Here we have the description for MyService",
"entityTypeMappings": [
{
"entityTypeTargets": undefined,
},
],
"entryPoints": [
"/odata/v4/my",
],
"extensible": {
"supported": "no",
},
"ordId": "customer:apiResource:undefined.MyService:v1",
"partOfGroups": [
"sap.cds:service:customer:undefined.MyService",
],
"partOfPackage": undefined,
"releaseStatus": "active",
"resourceDefinitions": [
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/json",
"type": "openapi-v3",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/MyService.oas3.json",
},
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/xml",
"type": "edmx",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/MyService.edmx",
},
],
"shortDescription": "Here we have the shortDescription for MyService",
"title": "The service is for MyService",
"version": "1.0.0",
"visibility": "public",
},
]
`;

exports[`templates fCreateEventResourceTemplate should create API resource template correctly 1`] = `
{
"description": "This is an example event catalog that contains only a partial ODM testAppName V1 event",
"extensible": {
"supported": "no",
},
"ordId": "customer:eventResource:undefined.MyService:v1",
"partOfGroups": [
"sap.cds:service:customer:undefined.MyService",
],
"partOfPackage": undefined,
"releaseStatus": "beta",
"resourceDefinitions": [
{
"accessStrategies": [
{
"type": "open",
},
],
"mediaType": "application/json",
"type": "asyncapi-v2",
"url": "/.well-known/open-resource-discovery/v1/api-metadata/MyService.asyncapi2.json",
},
],
"shortDescription": "Example ODM Event",
"title": "ODM testAppName Events",
"version": "1.0.0",
"visibility": "public",
}
`;
68 changes: 68 additions & 0 deletions __tests__/unittest/defaults.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const defaults = require('../../lib/defaults');

describe('defaults', () => {
describe('$schema', () => {
it('should return default value', () => {
expect(defaults.$schema).toMatchSnapshot();
});
});

describe('openResourceDiscovery', () => {
it('should return default value', () => {
expect(defaults.openResourceDiscovery).toMatchSnapshot();
});
});

describe('policyLevel', () => {
it('should return default value', () => {
expect(defaults.policyLevel).toMatchSnapshot();
});
});

describe('description', () => {
it('should return default value', () => {
expect(defaults.description).toMatchSnapshot();
});
});

describe('products', () => {
const testProductsName = 'My Product';
it('should return default value', () => {
expect(defaults.products(testProductsName)).toMatchSnapshot()
});
});

describe('groupTypeId', () => {
it('should return default value', () => {
expect(defaults.groupTypeId).toMatchSnapshot()
});
});

describe('packages', () => {
const testGetPackageDataName = 'My Package';
const testGetPackageCapNamespace = 'sample';
it('should return default value if policyLevel contains sap', () => {
const testPolicyLevel = 'sap:policy';

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

it('should return default value if policyLevel does not contain sap', () => {
const testPolicyLevel = 'policy';

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

describe('consumptionBundles', () => {
const testConsumptionBundlesName = 'My Consumption Bundle';
it('should return default value', () => {
expect(defaults.consumptionBundles(testConsumptionBundlesName)).toMatchSnapshot();
});
});
describe('baseTemplate', () => {
it('should return default value', () => {
expect(defaults.baseTemplate).toMatchSnapshot();
});
});
});
5 changes: 5 additions & 0 deletions __tests__/unittest/metaData.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('metaData', () => {
it('test placeholder', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/unittest/ord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('ord', () => {
it('test placeholder', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions __tests__/unittest/plugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('plugin', () => {
it('test placeholder', () => {
expect(true).toBe(true);
});
});
Loading