Skip to content

Commit

Permalink
Merge pull request #18 from /issues/17
Browse files Browse the repository at this point in the history
bug: Wrap delete and insert of tags in a transaction
  • Loading branch information
john-gom authored Nov 2, 2023
2 parents 0c73b8f + 89392be commit dae0214
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/domain/services/import.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 2 additions & 0 deletions src/domain/services/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
3 changes: 3 additions & 0 deletions src/domain/services/query.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit dae0214

Please sign in to comment.