From a781b0f97ca2188fbaecea28a91399d1fb2750d9 Mon Sep 17 00:00:00 2001 From: manushak Date: Wed, 21 Aug 2024 18:04:05 +0400 Subject: [PATCH] test(util): remove mapping functions tests --- src/__tests__/common/util/helpers.test.ts | 155 +--------------------- 1 file changed, 1 insertion(+), 154 deletions(-) diff --git a/src/__tests__/common/util/helpers.test.ts b/src/__tests__/common/util/helpers.test.ts index 387689371..11838100c 100644 --- a/src/__tests__/common/util/helpers.test.ts +++ b/src/__tests__/common/util/helpers.test.ts @@ -2,12 +2,7 @@ jest.mock('node:readline/promises', () => require('../../../__mocks__/readline') ); -import { - parseManifestFromStdin, - mapInputIfNeeded, - mapConfigIfNeeded, - mapOutputIfNeeded, -} from '../../../common/util/helpers'; +import {parseManifestFromStdin} from '../../../common/util/helpers'; describe('common/util/helpers: ', () => { describe('parseManifestFromStdin(): ', () => { @@ -46,152 +41,4 @@ describe('common/util/helpers: ', () => { expect(response).toEqual(expectedMessage); }); }); - - describe('mapInputIfNeeded(): ', () => { - it('returns a new object with no changes when mapping is empty.', () => { - const input = { - timestamp: '2021-01-01T00:00:00Z', - duration: 60 * 60 * 24 * 30, - 'device/carbon-footprint': 200, - 'device/expected-lifespan': 60 * 60 * 24 * 365 * 4, - 'resources-reserved': 1, - 'resources-total': 1, - }; - const mapping = {}; - - const result = mapInputIfNeeded(input, mapping); - - expect(result).toEqual(input); - }); - - it('returns a new object with keys remapped according to the mapping.', () => { - const input = { - timestamp: '2021-01-01T00:00:00Z', - duration: 60 * 60 * 24 * 30, - 'device/carbon-footprint': 200, - 'device/expected-lifespan': 60 * 60 * 24 * 365 * 4, - 'resources-reserved': 1, - 'resources-total': 1, - }; - const mapping = {'device/emissions-embodied': 'device/carbon-footprint'}; - - const expectedOutput = { - timestamp: '2021-01-01T00:00:00Z', - duration: 60 * 60 * 24 * 30, - 'device/emissions-embodied': 200, - 'device/expected-lifespan': 60 * 60 * 24 * 365 * 4, - 'resources-reserved': 1, - 'resources-total': 1, - }; - - const result = mapInputIfNeeded(input, mapping); - - expect(result).toEqual(expectedOutput); - expect(result).not.toHaveProperty('device/carbon-footprint'); - }); - }); - - describe('mapConfigIfNeeded', () => { - it('returns the config as is if no mapping is provided.', () => { - const config = { - filepath: './file.csv', - query: { - 'cpu-cores-available': 'cpu/available', - 'cpu-cores-utilized': 'cpu/utilized', - 'cpu-manufacturer': 'cpu/manufacturer', - }, - output: ['cpu-tdp', 'tdp'], - }; - - const nullMapping = null; - expect(mapConfigIfNeeded(config, nullMapping!)).toEqual(config); - - const undefinedMapping = undefined; - expect(mapConfigIfNeeded(config, undefinedMapping!)).toEqual(config); - }); - - it('recursively maps config keys and values according to the mapping.', () => { - const config = { - filepath: './file.csv', - query: { - 'cpu-cores-available': 'cpu/available', - 'cpu-cores-utilized': 'cpu/utilized', - 'cpu-manufacturer': 'cpu/manufacturer', - }, - output: ['cpu-tdp', 'tdp'], - }; - const mapping = { - 'cpu/utilized': 'cpu/util', - }; - - const expected = { - filepath: './file.csv', - query: { - 'cpu-cores-available': 'cpu/available', - 'cpu-cores-utilized': 'cpu/util', - 'cpu-manufacturer': 'cpu/manufacturer', - }, - output: ['cpu-tdp', 'tdp'], - }; - expect(mapConfigIfNeeded(config, mapping)).toEqual(expected); - }); - - it('returns an empty object or array when config is an empty object or array.', () => { - expect(mapConfigIfNeeded({}, {})).toEqual({}); - expect(mapConfigIfNeeded([], {})).toEqual([]); - }); - }); - - describe('mapOutputIfNeeded(): ', () => { - const output = { - timestamp: '2021-01-01T00:00:00Z', - duration: 3600, - 'cpu/energy': 1, - 'network/energy': 1, - 'memory/energy': 1, - }; - it('returns provided `output` if `mapping` is not valid.', () => { - const mapping = undefined; - const mappedOutput = mapOutputIfNeeded(output, mapping!); - - expect.assertions(1); - expect(mappedOutput).toEqual(output); - }); - - it('returns mapped output if `mapping` has data.', () => { - const mapping = { - 'cpu/energy': 'energy-from-cpu', - 'network/energy': 'energy-from-network', - }; - const expectedOutput = { - timestamp: '2021-01-01T00:00:00Z', - duration: 3600, - 'energy-from-cpu': 1, - 'energy-from-network': 1, - 'memory/energy': 1, - }; - const mappedOutput = mapOutputIfNeeded(output, mapping); - - expect.assertions(1); - expect(mappedOutput).toEqual(expectedOutput); - }); - - it('returns the correct mapped output if some properties are mismatched.', () => { - const mapping = { - 'mock-cpu/energy': 'energy-from-cpu', - 'network/energy': 'energy-from-network', - }; - const expectedOutput = { - timestamp: '2021-01-01T00:00:00Z', - duration: 3600, - 'cpu/energy': 1, - 'energy-from-network': 1, - 'memory/energy': 1, - }; - const mappedOutput = mapOutputIfNeeded(output, mapping); - - expect.assertions(1); - expect(mappedOutput).toEqual(expectedOutput); - }); - }); });