From 447d9e948b92cd7d0116e76655f3d57e941b2938 Mon Sep 17 00:00:00 2001 From: Gnanakeethan Balasubramaniam Date: Tue, 5 Dec 2023 15:59:30 +0530 Subject: [PATCH] unit: fixing unit tests Signed-off-by: Gnanakeethan Balasubramaniam --- src/__tests__/unit/lib/co2js/index.test.ts | 98 +++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/src/__tests__/unit/lib/co2js/index.test.ts b/src/__tests__/unit/lib/co2js/index.test.ts index 699f8fd..9d3333a 100644 --- a/src/__tests__/unit/lib/co2js/index.test.ts +++ b/src/__tests__/unit/lib/co2js/index.test.ts @@ -3,7 +3,103 @@ import {Co2jsModel} from '../../../../lib/co2js'; jest.setTimeout(30000); -describe('sci:configure test', () => { +describe('co2js-test', () => { + test('initialize and test', async () => { + const model = await new Co2jsModel().configure({ + type: '1byte', + }); + expect(model).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, + }, + ]); + }); + test('initialize and test', async () => { + const model = await new Co2jsModel().configure({ + type: '1byte', + }); + expect(model).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, + }, + ]); + }); + test('initialize and test', async () => { + const model = await new Co2jsModel().configure({ + type: '1byte', + }); + expect(model).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, + }, + ]); + }); + test('initialize and test', async () => { + const model = await new Co2jsModel().configure({ + type: '1byte', + }); + expect(model).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, + }, + ]); + }); test('initialize and test', async () => { const model = await new Co2jsModel().configure({ type: '1byte',