From 6afa19854c884fd478c579d19ddbe84796b3bf45 Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Thu, 2 Nov 2023 14:44:43 +0000 Subject: [PATCH 1/3] Wrap delete and insert of tags in a transaction --- src/domain/services/import.service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/domain/services/import.service.ts b/src/domain/services/import.service.ts index 6ec4ff8..c6c1e23 100644 --- a/src/domain/services/import.service.ts +++ b/src/domain/services/import.service.ts @@ -167,6 +167,8 @@ export class ImportService { // Get the underlying table name for the entity const tableName = this.em.getMetadata(entity).tableName; + await connection.execute('begin'); + // Delete existing tags for products that were imorted on this run const deleted = await connection.execute( `delete from ${tableName} From 9866af4c29a91b564ddec4e438360844675bbb6c Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Thu, 2 Nov 2023 14:49:57 +0000 Subject: [PATCH 2/3] Increase timeout for import test --- src/domain/services/import.service.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/domain/services/import.service.spec.ts b/src/domain/services/import.service.spec.ts index 7223035..a30333f 100644 --- a/src/domain/services/import.service.spec.ts +++ b/src/domain/services/import.service.spec.ts @@ -50,6 +50,9 @@ function mockMongoDB(productList) { mockedProducts = productList; } +// Import tests can sometimes take a little time in GitHub +jest.setTimeout(10000); + describe('importFromMongo', () => { it('should import a new product update existing products and delete missing products', async () => { await createTestingModule([DomainModule], async (app) => { From 89392be9f2e037f348da96fb7ad73b59eff5dca1 Mon Sep 17 00:00:00 2001 From: John Gomersall Date: Thu, 2 Nov 2023 14:57:27 +0000 Subject: [PATCH 3/3] Add timeout for query tests too --- src/domain/services/query.service.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/domain/services/query.service.spec.ts b/src/domain/services/query.service.spec.ts index 544bba7..5588649 100644 --- a/src/domain/services/query.service.spec.ts +++ b/src/domain/services/query.service.spec.ts @@ -14,6 +14,9 @@ import { createTestingModule, randomCode } from '../../../test/test.helper'; import { UnprocessableEntityException } from '@nestjs/common'; import { LoadedTag } from '../entities/loaded-tag'; +// Tests can sometimes take a little time in GitHub +jest.setTimeout(10000); + describe('count', () => { it('should count the number of products with a tag', async () => { await createTestingModule([DomainModule], async (app) => {