mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
test(core): Implement timeout in SMTP tests (#3152)
* ⚡ Implement timeout in SMTP tests * 🚚 Move timeout to constants
This commit is contained in:
parent
1c2ca6244c
commit
bc5749b7ae
|
@ -13,6 +13,7 @@ import {
|
||||||
} from './shared/random';
|
} from './shared/random';
|
||||||
import * as testDb from './shared/testDb';
|
import * as testDb from './shared/testDb';
|
||||||
import type { Role } from '../../src/databases/entities/Role';
|
import type { Role } from '../../src/databases/entities/Role';
|
||||||
|
import { SMTP_TEST_TIMEOUT } from './shared/constants';
|
||||||
|
|
||||||
jest.mock('../../src/telemetry');
|
jest.mock('../../src/telemetry');
|
||||||
|
|
||||||
|
@ -40,19 +41,22 @@ beforeEach(async () => {
|
||||||
|
|
||||||
config.set('userManagement.isInstanceOwnerSetUp', true);
|
config.set('userManagement.isInstanceOwnerSetUp', true);
|
||||||
config.set('userManagement.emails.mode', '');
|
config.set('userManagement.emails.mode', '');
|
||||||
|
|
||||||
jest.setTimeout(30000); // fake SMTP service might be slow
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await testDb.terminate(testDbName);
|
await testDb.terminate(testDbName);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('POST /forgot-password should send password reset email', async () => {
|
test(
|
||||||
|
'POST /forgot-password should send password reset email',
|
||||||
|
async () => {
|
||||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||||
|
|
||||||
const authlessAgent = utils.createAgent(app);
|
const authlessAgent = utils.createAgent(app);
|
||||||
const member = await testDb.createUser({ email: 'test@test.com', globalRole: globalMemberRole });
|
const member = await testDb.createUser({
|
||||||
|
email: 'test@test.com',
|
||||||
|
globalRole: globalMemberRole,
|
||||||
|
});
|
||||||
|
|
||||||
await utils.configureSmtp();
|
await utils.configureSmtp();
|
||||||
|
|
||||||
|
@ -68,7 +72,9 @@ test('POST /forgot-password should send password reset email', async () => {
|
||||||
expect(user.resetPasswordTokenExpiration).toBeGreaterThan(Math.ceil(Date.now() / 1000));
|
expect(user.resetPasswordTokenExpiration).toBeGreaterThan(Math.ceil(Date.now() / 1000));
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
SMTP_TEST_TIMEOUT,
|
||||||
|
);
|
||||||
|
|
||||||
test('POST /forgot-password should fail if emailing is not set up', async () => {
|
test('POST /forgot-password should fail if emailing is not set up', async () => {
|
||||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||||
|
|
|
@ -57,3 +57,8 @@ export const BOOTSTRAP_POSTGRES_CONNECTION_NAME: Readonly<string> = 'n8n_bs_post
|
||||||
* for each suite test run.
|
* for each suite test run.
|
||||||
*/
|
*/
|
||||||
export const BOOTSTRAP_MYSQL_CONNECTION_NAME: Readonly<string> = 'n8n_bs_mysql';
|
export const BOOTSTRAP_MYSQL_CONNECTION_NAME: Readonly<string> = 'n8n_bs_mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timeout (in milliseconds) to account for fake SMTP service being slow to respond.
|
||||||
|
*/
|
||||||
|
export const SMTP_TEST_TIMEOUT = 30_000;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
import { Db } from '../../src';
|
import { Db } from '../../src';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import { SUCCESS_RESPONSE_BODY } from './shared/constants';
|
import { SMTP_TEST_TIMEOUT, SUCCESS_RESPONSE_BODY } from './shared/constants';
|
||||||
import {
|
import {
|
||||||
randomEmail,
|
randomEmail,
|
||||||
randomValidPassword,
|
randomValidPassword,
|
||||||
|
@ -47,8 +47,6 @@ beforeAll(async () => {
|
||||||
|
|
||||||
utils.initTestTelemetry();
|
utils.initTestTelemetry();
|
||||||
utils.initTestLogger();
|
utils.initTestLogger();
|
||||||
|
|
||||||
jest.setTimeout(30000); // fake SMTP service might be slow
|
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
@ -481,7 +479,9 @@ test('POST /users should fail if user management is disabled', async () => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('POST /users should email invites and create user shells but ignore existing', async () => {
|
test(
|
||||||
|
'POST /users should email invites and create user shells but ignore existing',
|
||||||
|
async () => {
|
||||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||||
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
||||||
const memberShell = await testDb.createUserShell(globalMemberRole);
|
const memberShell = await testDb.createUserShell(globalMemberRole);
|
||||||
|
@ -489,7 +489,12 @@ test('POST /users should email invites and create user shells but ignore existin
|
||||||
|
|
||||||
await utils.configureSmtp();
|
await utils.configureSmtp();
|
||||||
|
|
||||||
const testEmails = [randomEmail(), randomEmail().toUpperCase(), memberShell.email, member.email];
|
const testEmails = [
|
||||||
|
randomEmail(),
|
||||||
|
randomEmail().toUpperCase(),
|
||||||
|
memberShell.email,
|
||||||
|
member.email,
|
||||||
|
];
|
||||||
|
|
||||||
const payload = testEmails.map((e) => ({ email: e }));
|
const payload = testEmails.map((e) => ({ email: e }));
|
||||||
|
|
||||||
|
@ -522,9 +527,13 @@ test('POST /users should email invites and create user shells but ignore existin
|
||||||
expect(password).toBeNull();
|
expect(password).toBeNull();
|
||||||
expect(resetPasswordToken).toBeNull();
|
expect(resetPasswordToken).toBeNull();
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
SMTP_TEST_TIMEOUT,
|
||||||
|
);
|
||||||
|
|
||||||
test('POST /users should fail with invalid inputs', async () => {
|
test(
|
||||||
|
'POST /users should fail with invalid inputs',
|
||||||
|
async () => {
|
||||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||||
const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner });
|
||||||
|
|
||||||
|
@ -547,9 +556,13 @@ test('POST /users should fail with invalid inputs', async () => {
|
||||||
expect(users.length).toBe(1); // DB unaffected
|
expect(users.length).toBe(1); // DB unaffected
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
SMTP_TEST_TIMEOUT,
|
||||||
|
);
|
||||||
|
|
||||||
test('POST /users should ignore an empty payload', async () => {
|
test(
|
||||||
|
'POST /users should ignore an empty payload',
|
||||||
|
async () => {
|
||||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||||
const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { auth: true, user: owner });
|
||||||
|
|
||||||
|
@ -565,7 +578,9 @@ test('POST /users should ignore an empty payload', async () => {
|
||||||
|
|
||||||
const users = await Db.collections.User!.find();
|
const users = await Db.collections.User!.find();
|
||||||
expect(users.length).toBe(1);
|
expect(users.length).toBe(1);
|
||||||
});
|
},
|
||||||
|
SMTP_TEST_TIMEOUT,
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: /users/:id/reinvite route tests missing
|
// TODO: /users/:id/reinvite route tests missing
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue