Skip to content

Commit

Permalink
Updated tests, formatted test file using Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
the-bay-kay committed Oct 24, 2023
1 parent 7dd8ffb commit 1907966
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions www/__tests__/unifiedDataLoader.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { mockLogger } from '../__mocks__/globalMocks';
import { combineWithDedup, combinedPromises, getUnifiedDataForInterval } from '../js/unifiedDataLoader'
import { combineWithDedup, combinedPromises } from '../js/unifiedDataLoader';
import { ServerDataPoint } from '../js/types/diaryTypes';

mockLogger();

const testOne : ServerDataPoint = {
const testOne: ServerDataPoint = {
data: '',
metadata: {
key: '',
Expand All @@ -20,7 +20,7 @@ const testTwo = JSON.parse(JSON.stringify(testOne));
testTwo.metadata.write_ts = 2;
const testThree = JSON.parse(JSON.stringify(testOne));
testThree.metadata.write_ts = 3;
const testFour= JSON.parse(JSON.stringify(testOne));
const testFour = JSON.parse(JSON.stringify(testOne));
testFour.metadata.write_ts = 4;

describe('combineWithDedup can', () => {
Expand All @@ -37,7 +37,11 @@ describe('combineWithDedup can', () => {
expect(combineWithDedup([testOne], [testOne, testTwo])).toEqual([testOne, testTwo]);
expect(combineWithDedup([testOne], [testTwo, testTwo])).toEqual([testOne, testTwo]);
expect(combineWithDedup([testOne, testTwo], [testTwo, testTwo])).toEqual([testOne, testTwo]);
expect(combineWithDedup([testOne, testTwo, testThree], [testOne, testTwo])).toEqual([testOne, testTwo, testThree]);
expect(combineWithDedup([testOne, testTwo, testThree], [testOne, testTwo])).toEqual([
testOne,
testTwo,
testThree,
]);
});
});

Expand All @@ -47,15 +51,17 @@ const promiseGenerator = (values: Array<ServerDataPoint>) => {
};

it('throws an error on an empty input', async () => {
expect(() => {combinedPromises([], combineWithDedup)}).toThrow();
expect(() => {
combinedPromises([], combineWithDedup);
}).toThrow();
});

it('work with arrays of len 1', async () => {
const promiseArrayOne = [promiseGenerator([testOne])];
const promiseArrayTwo = [promiseGenerator([testOne, testTwo])];
const testResultOne = await combinedPromises(promiseArrayOne, combineWithDedup);
const testResultTwo = await combinedPromises(promiseArrayTwo, combineWithDedup);

expect(testResultOne).toEqual([testOne]);
expect(testResultTwo).toEqual([testOne, testTwo]);
});
Expand All @@ -64,8 +70,14 @@ it('works with arrays of len 2', async () => {
const promiseArrayOne = [promiseGenerator([testOne]), promiseGenerator([testTwo])];
const promiseArrayTwo = [promiseGenerator([testOne, testTwo]), promiseGenerator([testThree])];
const promiseArrayThree = [promiseGenerator([testOne]), promiseGenerator([testTwo, testThree])];
const promiseArrayFour = [promiseGenerator([testOne, testTwo]), promiseGenerator([testThree, testFour])];
const promiseArrayFive = [promiseGenerator([testOne, testTwo]), promiseGenerator([testTwo, testThree])];
const promiseArrayFour = [
promiseGenerator([testOne, testTwo]),
promiseGenerator([testThree, testFour]),
];
const promiseArrayFive = [
promiseGenerator([testOne, testTwo]),
promiseGenerator([testTwo, testThree]),
];

const testResultOne = await combinedPromises(promiseArrayOne, combineWithDedup);
const testResultTwo = await combinedPromises(promiseArrayTwo, combineWithDedup);
Expand All @@ -81,10 +93,26 @@ it('works with arrays of len 2', async () => {
});

it('works with arrays of len >= 2', async () => {
const promiseArrayOne = [promiseGenerator([testOne]), promiseGenerator([testTwo]), promiseGenerator([testThree])];
const promiseArrayTwo = [promiseGenerator([testOne]), promiseGenerator([testTwo]), promiseGenerator([testTwo])];
const promiseArrayThree = [promiseGenerator([testOne]), promiseGenerator([testTwo]), promiseGenerator([testThree, testFour])];
const promiseArrayFour = [promiseGenerator([testOne]), promiseGenerator([testTwo, testThree]), promiseGenerator([testFour])];
const promiseArrayOne = [
promiseGenerator([testOne]),
promiseGenerator([testTwo]),
promiseGenerator([testThree]),
];
const promiseArrayTwo = [
promiseGenerator([testOne]),
promiseGenerator([testTwo]),
promiseGenerator([testTwo]),
];
const promiseArrayThree = [
promiseGenerator([testOne]),
promiseGenerator([testTwo]),
promiseGenerator([testThree, testFour]),
];
const promiseArrayFour = [
promiseGenerator([testOne]),
promiseGenerator([testTwo, testThree]),
promiseGenerator([testFour]),
];

const testResultOne = await combinedPromises(promiseArrayOne, combineWithDedup);
const testResultTwo = await combinedPromises(promiseArrayTwo, combineWithDedup);
Expand All @@ -96,3 +124,8 @@ it('works with arrays of len >= 2', async () => {
expect(testResultThree).toEqual([testOne, testTwo, testThree, testFour]);
expect(testResultFour).toEqual([testOne, testTwo, testThree, testFour]);
});

/*
TO-DO: Once getRawEnteries can be tested via end-to-end testing, we will be able to
test getUnifiedDataForInterval as well.
*/

0 comments on commit 1907966

Please sign in to comment.