Skip to content

Commit

Permalink
unit: coverage to 100%
Browse files Browse the repository at this point in the history
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
  • Loading branch information
gnanakeethan committed Dec 6, 2023
1 parent 447d9e9 commit a4e41c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 64 deletions.
81 changes: 21 additions & 60 deletions src/__tests__/unit/lib/co2js/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,25 @@ import {Co2jsModel} from '../../../../lib/co2js';
jest.setTimeout(30000);

describe('co2js-test', () => {
test('initialize and test', async () => {
const model = await new Co2jsModel().configure({
type: '1byte',
});
expect(model).toBeInstanceOf(Co2jsModel);
test('initialization tests', async () => {
const outputModel = new Co2jsModel();
await expect(
model.execute([
{
timestamp: '2021-01-01T00:00:00Z',
duration: 3600,
bytes: 100000,
'green-web-host': true,
},
])
).resolves.toStrictEqual([
{
timestamp: '2021-01-01T00:00:00Z',
duration: 3600,
bytes: 100000,
'green-web-host': true,
'operational-carbon': 0.023195833333333332,
},
]);
});
test('initialize and test', async () => {
const model = await new Co2jsModel().configure({
type: '1byte',
});
expect(model).toBeInstanceOf(Co2jsModel);
outputModel.configure({
type: '1byte',
})
).resolves.toBeInstanceOf(Co2jsModel);
await expect(
model.execute([
{
timestamp: '2021-01-01T00:00:00Z',
duration: 3600,
bytes: 100000,
'green-web-host': true,
},
])
).resolves.toStrictEqual([
{
timestamp: '2021-01-01T00:00:00Z',
duration: 3600,
bytes: 100000,
'green-web-host': true,
'operational-carbon': 0.023195833333333332,
},
]);
outputModel.configure({
type: 'swd',
})
).resolves.toBeInstanceOf(Co2jsModel);
await expect(
outputModel.configure({
type: '1byt',
})
).rejects.toThrow();
});
test('initialize and test', async () => {
test('initialize and test 1byte', async () => {
const model = await new Co2jsModel().configure({
type: '1byte',
});
Expand All @@ -76,9 +46,9 @@ describe('co2js-test', () => {
},
]);
});
test('initialize and test', async () => {
test('initialize and test swd', async () => {
const model = await new Co2jsModel().configure({
type: '1byte',
type: 'swd',
});
expect(model).toBeInstanceOf(Co2jsModel);
await expect(
Expand All @@ -96,11 +66,11 @@ describe('co2js-test', () => {
duration: 3600,
bytes: 100000,
'green-web-host': true,
'operational-carbon': 0.023195833333333332,
'operational-carbon': 0.023209515022500005,
},
]);
});
test('initialize and test', async () => {
test('initialize and test without bytes input', async () => {
const model = await new Co2jsModel().configure({
type: '1byte',
});
Expand All @@ -110,18 +80,9 @@ describe('co2js-test', () => {
{
timestamp: '2021-01-01T00:00:00Z',
duration: 3600,
bytes: 100000,
'green-web-host': true,
},
])
).resolves.toStrictEqual([
{
timestamp: '2021-01-01T00:00:00Z',
duration: 3600,
bytes: 100000,
'green-web-host': true,
'operational-carbon': 0.023195833333333332,
},
]);
).rejects.toThrow();
});
});
4 changes: 0 additions & 4 deletions src/lib/co2js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ export class Co2jsModel implements ModelPluginInterface {
time: string | unknown;
model: any | undefined;

authenticate(authParams: object): void {
this.authParams = authParams;
}

async execute(observations: ModelParams[]): Promise<ModelParams[]> {
return observations.map((observation: any) => {
this.configure(observation);
Expand Down

0 comments on commit a4e41c8

Please sign in to comment.