diff --git a/src/__tests__/unit/lib/co2js/index.test.ts b/src/__tests__/unit/lib/co2js/index.test.ts index 9d3333a..143c64e 100644 --- a/src/__tests__/unit/lib/co2js/index.test.ts +++ b/src/__tests__/unit/lib/co2js/index.test.ts @@ -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', }); @@ -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( @@ -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', }); @@ -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(); }); }); diff --git a/src/lib/co2js/index.ts b/src/lib/co2js/index.ts index bdb6164..8eaccd5 100644 --- a/src/lib/co2js/index.ts +++ b/src/lib/co2js/index.ts @@ -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 { return observations.map((observation: any) => { this.configure(observation);