refactor: Remove reintroduced non-null assertions in Db calls (#3162)

* 🔥 Remove reintroduced non-null assertions

* 🔥 Remove duplicate cred references

* 🔥 Remove unneeded `@ts-ignore`

* 🔥 Remove another `@ts-ignore`

* 🔥 Remove outdated suite version

* 🔥 Remove leftover non-null assertion

Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>

* 🔥 Remove more leftovers

* 🔥 Remove unneeded optional chaining operators

Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
This commit is contained in:
Iván Ovejero
2022-04-28 18:39:57 +02:00
committed by GitHub
parent 2b008815ca
commit 5e2589e626
18 changed files with 132 additions and 299 deletions

View File

@@ -33,7 +33,7 @@ beforeEach(async () => {
config.set('userManagement.isInstanceOwnerSetUp', true);
await Db.collections.Settings!.update(
await Db.collections.Settings.update(
{ key: 'userManagement.isInstanceOwnerSetUp' },
{ value: JSON.stringify(true) },
);
@@ -102,7 +102,7 @@ test('GET /login should return cookie if UM is disabled', async () => {
config.set('userManagement.isInstanceOwnerSetUp', false);
await Db.collections.Settings!.update(
await Db.collections.Settings.update(
{ key: 'userManagement.isInstanceOwnerSetUp' },
{ value: JSON.stringify(false) },
);

View File

@@ -1,157 +0,0 @@
import express from 'express';
import validator from 'validator';
import { v4 as uuid } from 'uuid';
import * as config from '../../config';
import * as utils from './shared/utils';
import { LOGGED_OUT_RESPONSE_BODY } from './shared/constants';
import { Db } from '../../src';
import { Role } from '../../src/databases/entities/Role';
import { randomEmail, randomValidPassword, randomName } from './shared/random';
import { getGlobalOwnerRole } from './shared/testDb';
import * as testDb from './shared/testDb';
jest.mock('../../src/telemetry');
let globalOwnerRole: Role;
let app: express.Application;
let testDbName = '';
beforeAll(async () => {
app = utils.initTestServer({ endpointGroups: ['auth'], applyAuth: true });
const initResult = await testDb.init();
testDbName = initResult.testDbName;
await testDb.truncate(['User'], testDbName);
globalOwnerRole = await getGlobalOwnerRole();
utils.initTestLogger();
utils.initTestTelemetry();
});
beforeEach(async () => {
await testDb.createUser({
id: uuid(),
email: TEST_USER.email,
firstName: TEST_USER.firstName,
lastName: TEST_USER.lastName,
password: TEST_USER.password,
globalRole: globalOwnerRole,
});
config.set('userManagement.isInstanceOwnerSetUp', true);
await Db.collections.Settings!.update(
{ key: 'userManagement.isInstanceOwnerSetUp' },
{ value: JSON.stringify(true) },
);
});
afterEach(async () => {
await testDb.truncate(['User'], testDbName);
});
afterAll(async () => {
await testDb.terminate(testDbName);
});
test('POST /login should log user in', async () => {
const authlessAgent = utils.createAgent(app);
await Promise.all(
[
{
email: TEST_USER.email,
password: TEST_USER.password,
},
{
email: TEST_USER.email.toUpperCase(),
password: TEST_USER.password,
},
].map(async (payload) => {
const response = await authlessAgent.post('/login').send(payload);
expect(response.statusCode).toBe(200);
const {
id,
email,
firstName,
lastName,
password,
personalizationAnswers,
globalRole,
resetPasswordToken,
} = response.body.data;
expect(validator.isUUID(id)).toBe(true);
expect(email).toBe(TEST_USER.email);
expect(firstName).toBe(TEST_USER.firstName);
expect(lastName).toBe(TEST_USER.lastName);
expect(password).toBeUndefined();
expect(personalizationAnswers).toBeNull();
expect(resetPasswordToken).toBeUndefined();
expect(globalRole).toBeDefined();
expect(globalRole.name).toBe('owner');
expect(globalRole.scope).toBe('global');
const authToken = utils.getAuthToken(response);
expect(authToken).toBeDefined();
}),
);
});
test('GET /login should receive logged in user', async () => {
const owner = await Db.collections.User!.findOneOrFail();
const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner });
const response = await authOwnerAgent.get('/login');
expect(response.statusCode).toBe(200);
const {
id,
email,
firstName,
lastName,
password,
personalizationAnswers,
globalRole,
resetPasswordToken,
} = response.body.data;
expect(validator.isUUID(id)).toBe(true);
expect(email).toBe(TEST_USER.email);
expect(firstName).toBe(TEST_USER.firstName);
expect(lastName).toBe(TEST_USER.lastName);
expect(password).toBeUndefined();
expect(personalizationAnswers).toBeNull();
expect(password).toBeUndefined();
expect(resetPasswordToken).toBeUndefined();
expect(globalRole).toBeDefined();
expect(globalRole.name).toBe('owner');
expect(globalRole.scope).toBe('global');
expect(response.headers['set-cookie']).toBeUndefined();
});
test('POST /logout should log user out', async () => {
const owner = await Db.collections.User!.findOneOrFail();
const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner });
const response = await authOwnerAgent.post('/logout');
expect(response.statusCode).toBe(200);
expect(response.body).toEqual(LOGGED_OUT_RESPONSE_BODY);
const authToken = utils.getAuthToken(response);
expect(authToken).toBeUndefined();
});
const TEST_USER = {
email: randomEmail(),
password: randomValidPassword(),
firstName: randomName(),
lastName: randomName(),
};

View File

@@ -62,14 +62,14 @@ test('POST /credentials should create cred', async () => {
expect(nodesAccess[0].nodeType).toBe(payload.nodesAccess[0].nodeType);
expect(encryptedData).not.toBe(payload.data);
const credential = await Db.collections.Credentials!.findOneOrFail(id);
const credential = await Db.collections.Credentials.findOneOrFail(id);
expect(credential.name).toBe(payload.name);
expect(credential.type).toBe(payload.type);
expect(credential.nodesAccess[0].nodeType).toBe(payload.nodesAccess[0].nodeType);
expect(credential.data).not.toBe(payload.data);
const sharedCredential = await Db.collections.SharedCredentials!.findOneOrFail({
const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
relations: ['user', 'credentials'],
where: { credentials: credential },
});
@@ -131,11 +131,11 @@ test('DELETE /credentials/:id should delete owned cred for owner', async () => {
expect(response.statusCode).toBe(200);
expect(response.body).toEqual({ data: true });
const deletedCredential = await Db.collections.Credentials!.findOne(savedCredential.id);
const deletedCredential = await Db.collections.Credentials.findOne(savedCredential.id);
expect(deletedCredential).toBeUndefined(); // deleted
const deletedSharedCredential = await Db.collections.SharedCredentials!.findOne();
const deletedSharedCredential = await Db.collections.SharedCredentials.findOne();
expect(deletedSharedCredential).toBeUndefined(); // deleted
});
@@ -151,11 +151,11 @@ test('DELETE /credentials/:id should delete non-owned cred for owner', async ()
expect(response.statusCode).toBe(200);
expect(response.body).toEqual({ data: true });
const deletedCredential = await Db.collections.Credentials!.findOne(savedCredential.id);
const deletedCredential = await Db.collections.Credentials.findOne(savedCredential.id);
expect(deletedCredential).toBeUndefined(); // deleted
const deletedSharedCredential = await Db.collections.SharedCredentials!.findOne();
const deletedSharedCredential = await Db.collections.SharedCredentials.findOne();
expect(deletedSharedCredential).toBeUndefined(); // deleted
});
@@ -170,11 +170,11 @@ test('DELETE /credentials/:id should delete owned cred for member', async () =>
expect(response.statusCode).toBe(200);
expect(response.body).toEqual({ data: true });
const deletedCredential = await Db.collections.Credentials!.findOne(savedCredential.id);
const deletedCredential = await Db.collections.Credentials.findOne(savedCredential.id);
expect(deletedCredential).toBeUndefined(); // deleted
const deletedSharedCredential = await Db.collections.SharedCredentials!.findOne();
const deletedSharedCredential = await Db.collections.SharedCredentials.findOne();
expect(deletedSharedCredential).toBeUndefined(); // deleted
});
@@ -189,11 +189,11 @@ test('DELETE /credentials/:id should not delete non-owned cred for member', asyn
expect(response.statusCode).toBe(404);
const shellCredential = await Db.collections.Credentials!.findOne(savedCredential.id);
const shellCredential = await Db.collections.Credentials.findOne(savedCredential.id);
expect(shellCredential).toBeDefined(); // not deleted
const deletedSharedCredential = await Db.collections.SharedCredentials!.findOne();
const deletedSharedCredential = await Db.collections.SharedCredentials.findOne();
expect(deletedSharedCredential).toBeDefined(); // not deleted
});
@@ -226,14 +226,14 @@ test('PATCH /credentials/:id should update owned cred for owner', async () => {
expect(nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(encryptedData).not.toBe(patchPayload.data);
const credential = await Db.collections.Credentials!.findOneOrFail(id);
const credential = await Db.collections.Credentials.findOneOrFail(id);
expect(credential.name).toBe(patchPayload.name);
expect(credential.type).toBe(patchPayload.type);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(credential.data).not.toBe(patchPayload.data);
const sharedCredential = await Db.collections.SharedCredentials!.findOneOrFail({
const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
relations: ['credentials'],
where: { credentials: credential },
});
@@ -261,14 +261,14 @@ test('PATCH /credentials/:id should update non-owned cred for owner', async () =
expect(nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(encryptedData).not.toBe(patchPayload.data);
const credential = await Db.collections.Credentials!.findOneOrFail(id);
const credential = await Db.collections.Credentials.findOneOrFail(id);
expect(credential.name).toBe(patchPayload.name);
expect(credential.type).toBe(patchPayload.type);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(credential.data).not.toBe(patchPayload.data);
const sharedCredential = await Db.collections.SharedCredentials!.findOneOrFail({
const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
relations: ['credentials'],
where: { credentials: credential },
});
@@ -295,14 +295,14 @@ test('PATCH /credentials/:id should update owned cred for member', async () => {
expect(nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(encryptedData).not.toBe(patchPayload.data);
const credential = await Db.collections.Credentials!.findOneOrFail(id);
const credential = await Db.collections.Credentials.findOneOrFail(id);
expect(credential.name).toBe(patchPayload.name);
expect(credential.type).toBe(patchPayload.type);
expect(credential.nodesAccess[0].nodeType).toBe(patchPayload.nodesAccess[0].nodeType);
expect(credential.data).not.toBe(patchPayload.data);
const sharedCredential = await Db.collections.SharedCredentials!.findOneOrFail({
const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
relations: ['credentials'],
where: { credentials: credential },
});
@@ -323,7 +323,7 @@ test('PATCH /credentials/:id should not update non-owned cred for member', async
expect(response.statusCode).toBe(404);
const shellCredential = await Db.collections.Credentials!.findOneOrFail(savedCredential.id);
const shellCredential = await Db.collections.Credentials.findOneOrFail(savedCredential.id);
expect(shellCredential.name).not.toBe(patchPayload.name); // not updated
});

View File

@@ -101,7 +101,7 @@ describe('Owner shell', () => {
expect(globalRole.name).toBe('owner');
expect(globalRole.scope).toBe('global');
const storedOwnerShell = await Db.collections.User!.findOneOrFail(id);
const storedOwnerShell = await Db.collections.User.findOneOrFail(id);
expect(storedOwnerShell.email).toBe(validPayload.email.toLowerCase());
expect(storedOwnerShell.firstName).toBe(validPayload.firstName);
@@ -117,7 +117,7 @@ describe('Owner shell', () => {
const response = await authOwnerShellAgent.patch('/me').send(invalidPayload);
expect(response.statusCode).toBe(400);
const storedOwnerShell = await Db.collections.User!.findOneOrFail();
const storedOwnerShell = await Db.collections.User.findOneOrFail();
expect(storedOwnerShell.email).toBeNull();
expect(storedOwnerShell.firstName).toBeNull();
expect(storedOwnerShell.lastName).toBeNull();
@@ -140,7 +140,7 @@ describe('Owner shell', () => {
const response = await authOwnerShellAgent.patch('/me/password').send(payload);
expect([400, 500].includes(response.statusCode)).toBe(true);
const storedMember = await Db.collections.User!.findOneOrFail();
const storedMember = await Db.collections.User.findOneOrFail();
if (payload.newPassword) {
expect(storedMember.password).not.toBe(payload.newPassword);
@@ -152,7 +152,7 @@ describe('Owner shell', () => {
}),
);
const storedOwnerShell = await Db.collections.User!.findOneOrFail();
const storedOwnerShell = await Db.collections.User.findOneOrFail();
expect(storedOwnerShell.password).toBeNull();
});
@@ -168,7 +168,7 @@ describe('Owner shell', () => {
expect(response.statusCode).toBe(200);
expect(response.body).toEqual(SUCCESS_RESPONSE_BODY);
const storedShellOwner = await Db.collections.User!.findOneOrFail({
const storedShellOwner = await Db.collections.User.findOneOrFail({
where: { email: IsNull() },
});
@@ -181,7 +181,7 @@ describe('Member', () => {
beforeEach(async () => {
config.set('userManagement.isInstanceOwnerSetUp', true);
await Db.collections.Settings!.update(
await Db.collections.Settings.update(
{ key: 'userManagement.isInstanceOwnerSetUp' },
{ value: JSON.stringify(true) },
);
@@ -255,7 +255,7 @@ describe('Member', () => {
expect(globalRole.name).toBe('member');
expect(globalRole.scope).toBe('global');
const storedMember = await Db.collections.User!.findOneOrFail(id);
const storedMember = await Db.collections.User.findOneOrFail(id);
expect(storedMember.email).toBe(validPayload.email.toLowerCase());
expect(storedMember.firstName).toBe(validPayload.firstName);
@@ -271,7 +271,7 @@ describe('Member', () => {
const response = await authMemberAgent.patch('/me').send(invalidPayload);
expect(response.statusCode).toBe(400);
const storedMember = await Db.collections.User!.findOneOrFail();
const storedMember = await Db.collections.User.findOneOrFail();
expect(storedMember.email).toBe(member.email);
expect(storedMember.firstName).toBe(member.firstName);
expect(storedMember.lastName).toBe(member.lastName);
@@ -295,7 +295,7 @@ describe('Member', () => {
expect(response.statusCode).toBe(200);
expect(response.body).toEqual(SUCCESS_RESPONSE_BODY);
const storedMember = await Db.collections.User!.findOneOrFail();
const storedMember = await Db.collections.User.findOneOrFail();
expect(storedMember.password).not.toBe(member.password);
expect(storedMember.password).not.toBe(validPayload.newPassword);
});
@@ -308,7 +308,7 @@ describe('Member', () => {
const response = await authMemberAgent.patch('/me/password').send(payload);
expect([400, 500].includes(response.statusCode)).toBe(true);
const storedMember = await Db.collections.User!.findOneOrFail();
const storedMember = await Db.collections.User.findOneOrFail();
if (payload.newPassword) {
expect(storedMember.password).not.toBe(payload.newPassword);
@@ -330,7 +330,7 @@ describe('Member', () => {
expect(response.statusCode).toBe(200);
expect(response.body).toEqual(SUCCESS_RESPONSE_BODY);
const { personalizationAnswers: storedAnswers } = await Db.collections.User!.findOneOrFail();
const { personalizationAnswers: storedAnswers } = await Db.collections.User.findOneOrFail();
expect(storedAnswers).toEqual(validPayload);
}
@@ -410,7 +410,7 @@ describe('Owner', () => {
expect(globalRole.name).toBe('owner');
expect(globalRole.scope).toBe('global');
const storedOwner = await Db.collections.User!.findOneOrFail(id);
const storedOwner = await Db.collections.User.findOneOrFail(id);
expect(storedOwner.email).toBe(validPayload.email.toLowerCase());
expect(storedOwner.firstName).toBe(validPayload.firstName);

View File

@@ -81,7 +81,7 @@ test('POST /owner should create owner and enable isInstanceOwnerSetUp', async ()
expect(globalRole.name).toBe('owner');
expect(globalRole.scope).toBe('global');
const storedOwner = await Db.collections.User!.findOneOrFail(id);
const storedOwner = await Db.collections.User.findOneOrFail(id);
expect(storedOwner.password).not.toBe(newOwnerData.password);
expect(storedOwner.email).toBe(newOwnerData.email);
expect(storedOwner.firstName).toBe(newOwnerData.firstName);
@@ -113,7 +113,7 @@ test('POST /owner should create owner with lowercased email', async () => {
expect(email).toBe(newOwnerData.email.toLowerCase());
const storedOwner = await Db.collections.User!.findOneOrFail(id);
const storedOwner = await Db.collections.User.findOneOrFail(id);
expect(storedOwner.email).toBe(newOwnerData.email.toLowerCase());
});
@@ -140,7 +140,7 @@ test('POST /owner/skip-setup should persist skipping setup to the DB', async ()
const skipConfig = config.getEnv('userManagement.skipInstanceOwnerSetup');
expect(skipConfig).toBe(true);
const { value } = await Db.collections.Settings!.findOneOrFail({
const { value } = await Db.collections.Settings.findOneOrFail({
key: 'userManagement.skipInstanceOwnerSetup',
});
expect(value).toBe('true');

View File

@@ -67,7 +67,7 @@ test(
expect(response.statusCode).toBe(200);
expect(response.body).toEqual({});
const user = await Db.collections.User!.findOneOrFail({ email: payload.email });
const user = await Db.collections.User.findOneOrFail({ email: payload.email });
expect(user.resetPasswordToken).toBeDefined();
expect(user.resetPasswordTokenExpiration).toBeGreaterThan(Math.ceil(Date.now() / 1000));
}),
@@ -85,7 +85,7 @@ test('POST /forgot-password should fail if emailing is not set up', async () =>
expect(response.statusCode).toBe(500);
const storedOwner = await Db.collections.User!.findOneOrFail({ email: owner.email });
const storedOwner = await Db.collections.User.findOneOrFail({ email: owner.email });
expect(storedOwner.resetPasswordToken).toBeNull();
});
@@ -109,7 +109,7 @@ test('POST /forgot-password should fail with invalid inputs', async () => {
const response = await authlessAgent.post('/forgot-password').send(invalidPayload);
expect(response.statusCode).toBe(400);
const storedOwner = await Db.collections.User!.findOneOrFail({ email: owner.email });
const storedOwner = await Db.collections.User.findOneOrFail({ email: owner.email });
expect(storedOwner.resetPasswordToken).toBeNull();
}),
);
@@ -133,7 +133,7 @@ test('GET /resolve-password-token should succeed with valid inputs', async () =>
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) + 100;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});
@@ -183,7 +183,7 @@ test('GET /resolve-password-token should fail if token is expired', async () =>
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) - 1;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});
@@ -205,7 +205,7 @@ test('POST /change-password should succeed with valid inputs', async () => {
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) + 100;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});
@@ -223,7 +223,7 @@ test('POST /change-password should succeed with valid inputs', async () => {
const authToken = utils.getAuthToken(response);
expect(authToken).toBeDefined();
const { password: storedPassword } = await Db.collections.User!.findOneOrFail(owner.id);
const { password: storedPassword } = await Db.collections.User.findOneOrFail(owner.id);
const comparisonResult = await compare(passwordToStore, storedPassword);
expect(comparisonResult).toBe(true);
@@ -238,7 +238,7 @@ test('POST /change-password should fail with invalid inputs', async () => {
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) + 100;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});
@@ -267,7 +267,7 @@ test('POST /change-password should fail with invalid inputs', async () => {
const response = await authlessAgent.post('/change-password').query(invalidPayload);
expect(response.statusCode).toBe(400);
const { password: storedPassword } = await Db.collections.User!.findOneOrFail();
const { password: storedPassword } = await Db.collections.User.findOneOrFail();
expect(owner.password).toBe(storedPassword);
}),
);
@@ -281,7 +281,7 @@ test('POST /change-password should fail when token has expired', async () => {
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) - 1;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});

View File

@@ -109,7 +109,7 @@ export async function truncate(collections: CollectionName[], testDbName: string
if (dbType === 'sqlite') {
await testDb.query('PRAGMA foreign_keys=OFF');
await Promise.all(collections.map((collection) => Db.collections[collection]!.clear()));
await Promise.all(collections.map((collection) => Db.collections[collection].clear()));
return testDb.query('PRAGMA foreign_keys=ON');
}
@@ -182,11 +182,11 @@ export async function saveCredential(
Object.assign(newCredential, encryptedData);
const savedCredential = await Db.collections.Credentials!.save(newCredential);
const savedCredential = await Db.collections.Credentials.save(newCredential);
savedCredential.data = newCredential.data;
await Db.collections.SharedCredentials!.save({
await Db.collections.SharedCredentials.save({
user,
credentials: savedCredential,
role,
@@ -211,7 +211,7 @@ export async function createUser(attributes: Partial<User> & { globalRole: Role
...rest,
};
return Db.collections.User!.save(user);
return Db.collections.User.save(user);
}
export function createUserShell(globalRole: Role): Promise<User> {
@@ -225,7 +225,7 @@ export function createUserShell(globalRole: Role): Promise<User> {
shell.email = randomEmail();
}
return Db.collections.User!.save(shell);
return Db.collections.User.save(shell);
}
// ----------------------------------
@@ -233,28 +233,28 @@ export function createUserShell(globalRole: Role): Promise<User> {
// ----------------------------------
export function getGlobalOwnerRole() {
return Db.collections.Role!.findOneOrFail({
return Db.collections.Role.findOneOrFail({
name: 'owner',
scope: 'global',
});
}
export function getGlobalMemberRole() {
return Db.collections.Role!.findOneOrFail({
return Db.collections.Role.findOneOrFail({
name: 'member',
scope: 'global',
});
}
export function getWorkflowOwnerRole() {
return Db.collections.Role!.findOneOrFail({
return Db.collections.Role.findOneOrFail({
name: 'owner',
scope: 'workflow',
});
}
export function getCredentialOwnerRole() {
return Db.collections.Role!.findOneOrFail({
return Db.collections.Role.findOneOrFail({
name: 'owner',
scope: 'credential',
});

View File

@@ -198,7 +198,7 @@ export function getAuthToken(response: request.Response, authCookieName = AUTH_C
// ----------------------------------
export async function isInstanceOwnerSetUp() {
const { value } = await Db.collections.Settings!.findOneOrFail({
const { value } = await Db.collections.Settings.findOneOrFail({
key: 'userManagement.isInstanceOwnerSetUp',
});

View File

@@ -119,9 +119,9 @@ test('DELETE /users/:id should delete the user', async () => {
nodes: [],
});
const savedWorkflow = await Db.collections.Workflow!.save(newWorkflow);
const savedWorkflow = await Db.collections.Workflow.save(newWorkflow);
await Db.collections.SharedWorkflow!.save({
await Db.collections.SharedWorkflow.save({
role: workflowOwnerRole,
user: userToDelete,
workflow: savedWorkflow,
@@ -136,9 +136,9 @@ test('DELETE /users/:id should delete the user', async () => {
nodesAccess: [],
});
const savedCredential = await Db.collections.Credentials!.save(newCredential);
const savedCredential = await Db.collections.Credentials.save(newCredential);
await Db.collections.SharedCredentials!.save({
await Db.collections.SharedCredentials.save({
role: credentialOwnerRole,
user: userToDelete,
credentials: savedCredential,
@@ -149,27 +149,27 @@ test('DELETE /users/:id should delete the user', async () => {
expect(response.statusCode).toBe(200);
expect(response.body).toEqual(SUCCESS_RESPONSE_BODY);
const user = await Db.collections.User!.findOne(userToDelete.id);
const user = await Db.collections.User.findOne(userToDelete.id);
expect(user).toBeUndefined(); // deleted
const sharedWorkflow = await Db.collections.SharedWorkflow!.findOne({
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
relations: ['user'],
where: { user: userToDelete },
});
expect(sharedWorkflow).toBeUndefined(); // deleted
const sharedCredential = await Db.collections.SharedCredentials!.findOne({
const sharedCredential = await Db.collections.SharedCredentials.findOne({
relations: ['user'],
where: { user: userToDelete },
});
expect(sharedCredential).toBeUndefined(); // deleted
const workflow = await Db.collections.Workflow!.findOne(savedWorkflow.id);
const workflow = await Db.collections.Workflow.findOne(savedWorkflow.id);
expect(workflow).toBeUndefined(); // deleted
// TODO: Include active workflow and check whether webhook has been removed
const credential = await Db.collections.Credentials!.findOne(savedCredential.id);
const credential = await Db.collections.Credentials.findOne(savedCredential.id);
expect(credential).toBeUndefined(); // deleted
});
@@ -181,7 +181,7 @@ test('DELETE /users/:id should fail to delete self', async () => {
expect(response.statusCode).toBe(400);
const user = await Db.collections.User!.findOne(owner.id);
const user = await Db.collections.User.findOne(owner.id);
expect(user).toBeDefined();
});
@@ -197,7 +197,7 @@ test('DELETE /users/:id should fail if user to delete is transferee', async () =
expect(response.statusCode).toBe(400);
const user = await Db.collections.User!.findOne(idToDelete);
const user = await Db.collections.User.findOne(idToDelete);
expect(user).toBeDefined();
});
@@ -205,7 +205,7 @@ test('DELETE /users/:id with transferId should perform transfer', async () => {
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner });
const userToDelete = await Db.collections.User!.save({
const userToDelete = await Db.collections.User.save({
id: uuid(),
email: randomEmail(),
password: randomValidPassword(),
@@ -225,9 +225,9 @@ test('DELETE /users/:id with transferId should perform transfer', async () => {
nodes: [],
});
const savedWorkflow = await Db.collections.Workflow!.save(newWorkflow);
const savedWorkflow = await Db.collections.Workflow.save(newWorkflow);
await Db.collections.SharedWorkflow!.save({
await Db.collections.SharedWorkflow.save({
role: workflowOwnerRole,
user: userToDelete,
workflow: savedWorkflow,
@@ -242,9 +242,9 @@ test('DELETE /users/:id with transferId should perform transfer', async () => {
nodesAccess: [],
});
const savedCredential = await Db.collections.Credentials!.save(newCredential);
const savedCredential = await Db.collections.Credentials.save(newCredential);
await Db.collections.SharedCredentials!.save({
await Db.collections.SharedCredentials.save({
role: credentialOwnerRole,
user: userToDelete,
credentials: savedCredential,
@@ -256,17 +256,17 @@ test('DELETE /users/:id with transferId should perform transfer', async () => {
expect(response.statusCode).toBe(200);
const sharedWorkflow = await Db.collections.SharedWorkflow!.findOneOrFail({
const sharedWorkflow = await Db.collections.SharedWorkflow.findOneOrFail({
relations: ['user'],
where: { user: owner },
});
const sharedCredential = await Db.collections.SharedCredentials!.findOneOrFail({
const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
relations: ['user'],
where: { user: owner },
});
const deletedUser = await Db.collections.User!.findOne(userToDelete);
const deletedUser = await Db.collections.User.findOne(userToDelete);
expect(sharedWorkflow.user.id).toBe(owner.id);
expect(sharedCredential.user.id).toBe(owner.id);
@@ -317,7 +317,7 @@ test('GET /resolve-signup-token should fail with invalid inputs', async () => {
.query({ inviteeId });
// cause inconsistent DB state
await Db.collections.User!.update(owner.id, { email: '' });
await Db.collections.User.update(owner.id, { email: '' });
const fifth = await authOwnerAgent
.get('/resolve-signup-token')
.query({ inviterId: owner.id })
@@ -369,7 +369,7 @@ test('POST /users/:id should fill out a user shell', async () => {
const authToken = utils.getAuthToken(response);
expect(authToken).toBeDefined();
const member = await Db.collections.User!.findOneOrFail(memberShell.id);
const member = await Db.collections.User.findOneOrFail(memberShell.id);
expect(member.firstName).toBe(memberData.firstName);
expect(member.lastName).toBe(memberData.lastName);
expect(member.password).not.toBe(memberData.password);
@@ -382,7 +382,7 @@ test('POST /users/:id should fail with invalid inputs', async () => {
const memberShellEmail = randomEmail();
const memberShell = await Db.collections.User!.save({
const memberShell = await Db.collections.User.save({
email: memberShellEmail,
globalRole: globalMemberRole,
});
@@ -421,7 +421,7 @@ test('POST /users/:id should fail with invalid inputs', async () => {
const response = await authlessAgent.post(`/users/${memberShell.id}`).send(invalidPayload);
expect(response.statusCode).toBe(400);
const storedUser = await Db.collections.User!.findOneOrFail({
const storedUser = await Db.collections.User.findOneOrFail({
where: { email: memberShellEmail },
});
expect(storedUser.firstName).toBeNull();
@@ -448,7 +448,7 @@ test('POST /users/:id should fail with already accepted invite', async () => {
expect(response.statusCode).toBe(400);
const storedMember = await Db.collections.User!.findOneOrFail({
const storedMember = await Db.collections.User.findOneOrFail({
where: { email: member.email },
});
expect(storedMember.firstName).not.toBe(newMemberData.firstName);
@@ -517,7 +517,7 @@ test(
expect(error).toBe('Email could not be sent');
}
const storedUser = await Db.collections.User!.findOneOrFail(id);
const storedUser = await Db.collections.User.findOneOrFail(id);
const { firstName, lastName, personalizationAnswers, password, resetPasswordToken } =
storedUser;
@@ -552,7 +552,7 @@ test(
const response = await authOwnerAgent.post('/users').send(invalidPayload);
expect(response.statusCode).toBe(400);
const users = await Db.collections.User!.find();
const users = await Db.collections.User.find();
expect(users.length).toBe(1); // DB unaffected
}),
);
@@ -576,7 +576,7 @@ test(
expect(Array.isArray(data)).toBe(true);
expect(data.length).toBe(0);
const users = await Db.collections.User!.find();
const users = await Db.collections.User.find();
expect(users.length).toBe(1);
},
SMTP_TEST_TIMEOUT,
@@ -586,7 +586,7 @@ test(
// TODO: UserManagementMailer is a singleton - cannot reinstantiate with wrong creds
// test('POST /users should error for wrong SMTP config', async () => {
// const owner = await Db.collections.User!.findOneOrFail();
// const owner = await Db.collections.User.findOneOrFail();
// const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner });
// config.set('userManagement.emails.mode', 'smtp');