From db62d16ecf8e82fe17c5ef0d1c61b3c38ae3c975 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sun, 24 Mar 2024 22:58:26 +0000 Subject: [PATCH] Added test for getMeasurements() of compare.ts Signed-off-by: Stefan Marr --- src/backend/compare/compare.ts | 5 ++- tests/backend/compare/db-measurements.test.ts | 44 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/backend/compare/db-measurements.test.ts diff --git a/src/backend/compare/compare.ts b/src/backend/compare/compare.ts index 4857ec52..3103f48e 100644 --- a/src/backend/compare/compare.ts +++ b/src/backend/compare/compare.ts @@ -84,7 +84,10 @@ export async function getMeasurementsAsJson( completeRequestAndHandlePromise(start, db, 'get-measurements'); } -async function getMeasurements( +/** + * Only exported for testing, meant to be private. + */ +export async function getMeasurements( projectSlug: string, runId: number, baseCommitId: string, diff --git a/tests/backend/compare/db-measurements.test.ts b/tests/backend/compare/db-measurements.test.ts new file mode 100644 index 00000000..39d78812 --- /dev/null +++ b/tests/backend/compare/db-measurements.test.ts @@ -0,0 +1,44 @@ +import { describe, expect, it, beforeAll, afterAll } from '@jest/globals'; + +import { + TestDatabase, + closeMainDb, + createAndInitializeDB +} from '../db/db-testing.js'; +import { loadLargePayload } from '../../payload.js'; +import { getMeasurements } from '../../../src/backend/compare/compare.js'; + +describe('compare view: getMeasurements()', () => { + let db: TestDatabase; + + beforeAll(async () => { + db = await createAndInitializeDB('compare_view_get_m', 0, false); + const largeTestData = loadLargePayload(); + await db.recordAllData(largeTestData); + }); + + afterAll(async () => { + if (db) return db.close(); + }); + + it('should give expected results for runId 1', async () => { + const results = await getMeasurements( + 'Large-Example-Project', + 10, + '58666d1c84c652306f930daa72e7a47c58478e86', + '58666d1c84c652306f930daa72e7a47c58478e86', + db + ); + + expect(results).toHaveLength(1); + if (results === null) return; + expect(results[0].data).toHaveLength(1); + expect(results[0].data[0].criterion).toEqual('total'); + expect(results[0].data[0].values).toHaveLength(1); + expect(results[0].data[0].values[0]).toHaveLength(1000); + }); +}); + +afterAll(async () => { + return closeMainDb(); +});