Skip to content

Commit

Permalink
test(lib): add tests for
Browse files Browse the repository at this point in the history
  • Loading branch information
manushak committed Jul 16, 2024
1 parent 4ecc3d7 commit 2e35df3
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/__tests__/if-run/lib/explain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {explain, addExplainData} from '../../../if-run/lib/explain';

describe('lib/explain: ', () => {
it('successfully adds explain data if `inputs` and `outputs` of `metadata` are `undefined`.', () => {
const mockData = {
pluginName: 'divide',
metadata: {kind: 'execute', inputs: undefined, outputs: undefined},
pluginData: {
path: 'builtin',
method: 'Divide',
},
};
const expectedResult = {
divide: {
method: 'Divide',
path: 'builtin',
inputs: 'undefined',
outputs: 'undefined',
},
};

addExplainData(mockData);
const result = explain();
expect.assertions(1);
expect(result).toEqual(expectedResult);
});

it('successfully adds explain data if `inputs` and `outputs` of `metadata` are valid data.', () => {
const mockData = {
pluginName: 'sum',
metadata: {
kind: 'execute',
inputs: {
'cpu/energy': {
unit: 'kWh',
description: 'energy consumed by the cpu',
},
'network/energy': {
unit: 'kWh',
description: 'energy consumed by data ingress and egress',
},
},
outputs: {
'energy-sum': {
unit: 'kWh',
description: 'sum of energy components',
},
},
},
pluginData: {
path: 'builtin',
method: 'Sum',
},
};
const expectedResult = {
divide: {
method: 'Divide',
path: 'builtin',
inputs: 'undefined',
outputs: 'undefined',
},
sum: {
method: 'Sum',
path: 'builtin',
inputs: {
'cpu/energy': {
unit: 'kWh',
description: 'energy consumed by the cpu',
},
'network/energy': {
unit: 'kWh',
description: 'energy consumed by data ingress and egress',
},
},
outputs: {
'energy-sum': {unit: 'kWh', description: 'sum of energy components'},
},
},
};

addExplainData(mockData);
const result = explain();
expect.assertions(1);
expect(result).toEqual(expectedResult);
});
});

0 comments on commit 2e35df3

Please sign in to comment.