Skip to content

Commit

Permalink
teardown tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryD committed Nov 12, 2023
1 parent 6512fd6 commit 8694f81
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
11 changes: 9 additions & 2 deletions tests/src/integration/controllers/auth/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'reflect-metadata';
import { container } from '@triptyk/nfw-core';
import { beforeAll, expect } from 'vitest';
import { afterAll, beforeAll, expect } from 'vitest';

import { MikroORM } from '@mikro-orm/core';
import { AuthControllerTestSeeder } from './seed.js';
Expand All @@ -9,11 +9,18 @@ import { testCtx } from '../../../../utils/it-request-context.js';
import { AuthController } from '../../../../../src/features/auth/controllers/auth.controller.js';
import { DatabaseConnectionImpl } from '../../../../../src/database/connection.js';
import { RefreshTokenModel } from '../../../../../src/features/auth/models/refresh-token.model.js';
import type { Application } from '../../../../../src/application.js';

let application: Application;

beforeAll(async () => {
await setupIntegrationTest(AuthControllerTestSeeder);
application = await setupIntegrationTest(AuthControllerTestSeeder);
})

afterAll(async () => {
await application.stop();
});

testCtx('Login creates a refresh token', () => container.resolve(MikroORM), async () => {
const authController = container.resolve(AuthController);

Expand Down
6 changes: 6 additions & 0 deletions tests/src/integration/controllers/documents/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import { DocumentsController } from '../../../../../src/features/users/controlle
import { MimeTypes } from '../../../../../src/features/users/enums/mime-type.enum.js';
import { Roles } from '../../../../../src/features/users/enums/roles.enum.js';
import { UserModel } from '../../../../../src/features/users/models/user.model.js';
import type { Application } from '../../../../../src/application.js';

let application: Application;
let documentsController: DocumentsController;

beforeAll(async () => {
await setupIntegrationTest(DocumentsControllerTestSeeder);
documentsController = container.resolve(DocumentsController);
})

afterAll(async () => {
await application.stop();
});

function createAdminUser () {
const adminUser = new UserModel();
adminUser.role = Roles.ADMIN;
Expand Down
10 changes: 8 additions & 2 deletions tests/src/integration/controllers/users/users.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { MikroORM } from '@mikro-orm/core';
import { container } from '@triptyk/nfw-core';
import { beforeAll, expect } from 'vitest';
import { afterAll, beforeAll, expect } from 'vitest';
import { UsersController } from '../../../../../src/features/users/controllers/users.controller.js';
import { Roles } from '../../../../../src/features/users/enums/roles.enum.js';
import { UserModel } from '../../../../../src/features/users/models/user.model.js';
import { testCtx } from '../../../../utils/it-request-context.js';
import { setupIntegrationTest } from '../../../../utils/setup-integration-test.js';
import { UsersControllerTestSeeder } from './seed.js';
import type { Application } from '../../../../../src/application.js';

let usersController: UsersController;
let application: Application;

beforeAll(async () => {
await setupIntegrationTest(UsersControllerTestSeeder);
application = await setupIntegrationTest(UsersControllerTestSeeder);
usersController = container.resolve(UsersController);
})

afterAll(async () => {
await application.stop();
});

function createAdminUser () {
const adminUser = new UserModel();
adminUser.role = Roles.ADMIN;
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/setup-integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ export async function setupIntegrationTest (...seed: Constructor<Seeder>[]) {
const orm = container.resolve(DatabaseConnectionImpl);
await orm.connection.getSchemaGenerator().clearDatabase();
await orm.connection.getSeeder().seed(...seed);
return application;
}

export async function teardownIntegrationTest (application: Application) {
await application.stop();
}

0 comments on commit 8694f81

Please sign in to comment.