diff --git a/api/test/utils/test-manager.ts b/api/test/utils/test-manager.ts index 601cec3a..0340cb2c 100644 --- a/api/test/utils/test-manager.ts +++ b/api/test/utils/test-manager.ts @@ -8,12 +8,12 @@ import { Type } from '@nestjs/common/interfaces'; import * as request from 'supertest'; import { getDataSourceToken } from '@nestjs/typeorm'; -import { clearTestDataFromDatabase } from './db-helpers'; import { User } from '@shared/entities/users/user.entity'; import { IEmailServiceToken } from '@api/modules/notifications/email/email-service.interface'; import { MockEmailService } from './mocks/mock-email.service'; import { ROLES } from '@shared/entities/users/roles.enum'; import { createUser } from '@shared/lib/entity-mocks'; +import { clearTestDataFromDatabase } from '@shared/lib/db-helpers'; /** * @description: Abstraction for NestJS testing workflow. For now its a basic implementation to create a test app, but can be extended to encapsulate diff --git a/shared/lib/db-helpers.ts b/shared/lib/db-helpers.ts index 1542da94..ce8e4202 100644 --- a/shared/lib/db-helpers.ts +++ b/shared/lib/db-helpers.ts @@ -1,5 +1,5 @@ -import { DataSource, EntityMetadata } from 'typeorm'; -import { difference } from 'lodash'; +import { DataSource, EntityMetadata } from "typeorm"; +import { difference } from "lodash"; export async function clearTestDataFromDatabase( dataSource: DataSource, @@ -11,8 +11,8 @@ export async function clearTestDataFromDatabase( const entityTableNames: string[] = dataSource.entityMetadatas .filter( (entityMetadata: EntityMetadata) => - entityMetadata.tableType === 'regular' || - entityMetadata.tableType === 'junction', + entityMetadata.tableType === "regular" || + entityMetadata.tableType === "junction", ) .map((entityMetadata: EntityMetadata) => entityMetadata.tableName); @@ -24,9 +24,9 @@ export async function clearTestDataFromDatabase( entityTableNames.push(dataSource.metadataTableName); entityTableNames.push( - dataSource.options.migrationsTableName || 'migrations', + dataSource.options.migrationsTableName || "migrations", ); - entityTableNames.push('spatial_ref_sys'); + entityTableNames.push("spatial_ref_sys"); const databaseTableNames: string[] = ( await dataSource.query( @@ -34,14 +34,13 @@ export async function clearTestDataFromDatabase( ) ).map((e: Record) => e.table_name); - // todo: Alex to take a look later - // const tablesToDrop = difference(databaseTableNames, entityTableNames); - // - // await Promise.all( - // tablesToDrop.map((tableToDrop: string) => - // queryRunner.dropTable(tableToDrop), - // ), - // ); + const tablesToDrop = difference(databaseTableNames, entityTableNames); + + await Promise.all( + tablesToDrop.map((tableToDrop: string) => + queryRunner.dropTable(tableToDrop), + ), + ); await queryRunner.commitTransaction(); } catch (err) { // rollback changes before throwing error