refactor(core): Reduce boilterplate code in between tests 🧹, and fix the tests in node.js 20 (no-changelog) (#6654)
refactor(core): Reduce boilterplate code in between tests also cleaned up some imports, and fixed the tests in node.js 20
This commit is contained in:
committed by
GitHub
parent
3e07ffa73e
commit
b895ba438a
@@ -1,4 +1,3 @@
|
||||
import type { Application } from 'express';
|
||||
import validator from 'validator';
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
|
||||
@@ -13,32 +12,28 @@ import {
|
||||
randomValidPassword,
|
||||
} from './shared/random';
|
||||
import * as testDb from './shared/testDb';
|
||||
import * as utils from './shared/utils';
|
||||
import * as utils from './shared/utils/';
|
||||
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['owner'] });
|
||||
|
||||
let app: Application;
|
||||
let globalOwnerRole: Role;
|
||||
let ownerShell: User;
|
||||
let authOwnerShellAgent: SuperAgentTest;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await utils.initTestServer({ endpointGroups: ['owner'] });
|
||||
globalOwnerRole = await testDb.getGlobalOwnerRole();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
config.set('userManagement.isInstanceOwnerSetUp', false);
|
||||
ownerShell = await testDb.createUserShell(globalOwnerRole);
|
||||
authOwnerShellAgent = utils.createAuthAgent(app)(ownerShell);
|
||||
authOwnerShellAgent = testServer.authAgentFor(ownerShell);
|
||||
config.set('userManagement.isInstanceOwnerSetUp', false);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await testDb.truncate(['User']);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
describe('POST /owner/setup', () => {
|
||||
test('should create owner and enable isInstanceOwnerSetUp', async () => {
|
||||
const newOwnerData = {
|
||||
@@ -159,13 +154,9 @@ describe('POST /owner/setup', () => {
|
||||
];
|
||||
|
||||
test('should fail with invalid inputs', async () => {
|
||||
const authOwnerAgent = authOwnerShellAgent;
|
||||
|
||||
await Promise.all(
|
||||
INVALID_POST_OWNER_PAYLOADS.map(async (invalidPayload) => {
|
||||
const response = await authOwnerAgent.post('/owner/setup').send(invalidPayload);
|
||||
expect(response.statusCode).toBe(400);
|
||||
}),
|
||||
);
|
||||
for (const invalidPayload of INVALID_POST_OWNER_PAYLOADS) {
|
||||
const response = await authOwnerShellAgent.post('/owner/setup').send(invalidPayload);
|
||||
expect(response.statusCode).toBe(400);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user