From 365870e5f870fbbc47369982e484d6235fd1fd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20J=C3=A4ggi?= <1872195+solaris007@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:38:31 +0100 Subject: [PATCH] fix: key-event schema, fixture, test (#525) --- .../src/v2/models/key-event/key-event.schema.js | 1 + .../test/fixtures/api-keys.fixtures.js | 2 +- .../test/fixtures/import-jobs.fixture.js | 6 +++--- .../test/it/import-job/import-job.test.js | 8 +++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/spacecat-shared-data-access/src/v2/models/key-event/key-event.schema.js b/packages/spacecat-shared-data-access/src/v2/models/key-event/key-event.schema.js index 6bce4cf7..d719f7a8 100644 --- a/packages/spacecat-shared-data-access/src/v2/models/key-event/key-event.schema.js +++ b/packages/spacecat-shared-data-access/src/v2/models/key-event/key-event.schema.js @@ -38,6 +38,7 @@ const schema = new SchemaBuilder(KeyEvent, KeyEventCollection) .addAttribute('time', { type: 'string', required: true, + default: () => new Date().toISOString(), validate: (value) => isIsoDate(value), }); diff --git a/packages/spacecat-shared-data-access/test/fixtures/api-keys.fixtures.js b/packages/spacecat-shared-data-access/test/fixtures/api-keys.fixtures.js index cb89acba..c49814e9 100644 --- a/packages/spacecat-shared-data-access/test/fixtures/api-keys.fixtures.js +++ b/packages/spacecat-shared-data-access/test/fixtures/api-keys.fixtures.js @@ -42,7 +42,7 @@ const apiKeys = [ { name: 'Test API Key 3', expiresAt: '2025-10-09T19:21:55.834Z', - hashedApiKey: 'some-key-2', + hashedApiKey: 'some-key-3', imsOrgId: 'org-1@AdobeOrg', imsUserId: 'user-1', scopes: [{ diff --git a/packages/spacecat-shared-data-access/test/fixtures/import-jobs.fixture.js b/packages/spacecat-shared-data-access/test/fixtures/import-jobs.fixture.js index 4ad0f1df..0079724f 100644 --- a/packages/spacecat-shared-data-access/test/fixtures/import-jobs.fixture.js +++ b/packages/spacecat-shared-data-access/test/fixtures/import-jobs.fixture.js @@ -16,7 +16,7 @@ const importJobs = [ { importJobId: '021cbb7d-0772-45c6-967c-86a0a598b7dd', importQueueId: 'Q-123', - hashedApiKey: '1234', + hashedApiKey: 'some-key-1', baseURL: 'https://example-1.com/cars', startedAt: '2023-12-06T08:17:41.467Z', status: ImportJob.ImportJobStatus.RUNNING, @@ -32,7 +32,7 @@ const importJobs = [ { importJobId: '72113a4d-ca45-4c35-bd2e-29bb0ec03435', importQueueId: 'Q-321', - hashedApiKey: '4321', + hashedApiKey: 'some-key-1', baseURL: 'https://example-2.com/cars', startedAt: '2023-11-15T01:22:05.000Z', status: ImportJob.ImportJobStatus.FAILED, @@ -48,7 +48,7 @@ const importJobs = [ { importJobId: '78e1f8de-661a-418b-bd80-24589a10b5ce', importQueueId: 'Q-213', - hashedApiKey: '4231', + hashedApiKey: 'some-key-2', baseURL: 'https://example-3.com/', startedAt: '2023-11-15T03:46:40.000Z', endedAt: '2023-11-15T03:49:13.000Z', diff --git a/packages/spacecat-shared-data-access/test/it/import-job/import-job.test.js b/packages/spacecat-shared-data-access/test/it/import-job/import-job.test.js index 3c024ab9..99e0ff2b 100644 --- a/packages/spacecat-shared-data-access/test/it/import-job/import-job.test.js +++ b/packages/spacecat-shared-data-access/test/it/import-job/import-job.test.js @@ -17,6 +17,7 @@ import chaiAsPromised from 'chai-as-promised'; import { getDataAccess } from '../util/db.js'; import { seedDatabase } from '../util/seed.js'; +import { ImportJobStatus } from '../../../src/index.js'; use(chaiAsPromised); @@ -121,13 +122,14 @@ describe('ImportJob IT', async () => { }); it('gets all import jobs by status', async () => { - const sampleImportJob = sampleData.importJobs[0]; - const importJobs = await ImportJob.allByStatus(sampleImportJob.getStatus()); + const importJobs = await ImportJob.allByStatus(ImportJobStatus.COMPLETE); expect(importJobs).to.be.an('array'); + expect(importJobs.length).to.equal(2); + expect(importJobs[0].getId()).to.equal(sampleData.importJobs[0].getId()); importJobs.forEach((importJob) => { checkImportJob(importJob); - expect(importJob.getStatus()).to.equal(sampleImportJob.getStatus()); + expect(importJob.getStatus()).to.equal(ImportJobStatus.COMPLETE); }); });