mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
ci: Refactor cli tests to speed up CI (no-changelog) (#5718)
* ci: Refactor cli tests to speed up CI (no-changelog) * upgrade jest to address memory leaks
This commit is contained in:
committed by
GitHub
parent
be172cb720
commit
6242cac53b
@@ -1,18 +1,14 @@
|
||||
import express from 'express';
|
||||
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
import config from '@/config';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { setSamlLoginEnabled } from '@/sso/saml/samlHelpers';
|
||||
import { setCurrentAuthenticationMethod } from '@/sso/ssoHelpers';
|
||||
import { randomEmail, randomName, randomValidPassword } from '../shared/random';
|
||||
import * as testDb from '../shared/testDb';
|
||||
import type { AuthAgent } from '../shared/types';
|
||||
import * as utils from '../shared/utils';
|
||||
import { setSamlLoginEnabled } from '../../../src/sso/saml/samlHelpers';
|
||||
import { setCurrentAuthenticationMethod } from '../../../src/sso/ssoHelpers';
|
||||
|
||||
let app: express.Application;
|
||||
let globalOwnerRole: Role;
|
||||
let globalMemberRole: Role;
|
||||
let authAgent: AuthAgent;
|
||||
let owner: User;
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
|
||||
function enableSaml(enable: boolean) {
|
||||
setSamlLoginEnabled(enable);
|
||||
@@ -21,58 +17,59 @@ function enableSaml(enable: boolean) {
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await utils.initTestServer({ endpointGroups: ['me'] });
|
||||
|
||||
globalOwnerRole = await testDb.getGlobalOwnerRole();
|
||||
globalMemberRole = await testDb.getGlobalMemberRole();
|
||||
|
||||
authAgent = utils.createAuthAgent(app);
|
||||
const app = await utils.initTestServer({ endpointGroups: ['me'] });
|
||||
owner = await testDb.createOwner();
|
||||
authOwnerAgent = utils.createAuthAgent(app)(owner);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['User']);
|
||||
});
|
||||
// beforeEach(async () => {
|
||||
// await testDb.truncate(['User']);
|
||||
// });
|
||||
|
||||
afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
describe('Instance owner', () => {
|
||||
test('PATCH /me should succeed with valid inputs', async () => {
|
||||
const owner = await testDb.createOwner();
|
||||
const authOwnerAgent = authAgent(owner);
|
||||
const response = await authOwnerAgent.patch('/me').send({
|
||||
email: randomEmail(),
|
||||
firstName: randomName(),
|
||||
lastName: randomName(),
|
||||
password: randomValidPassword(),
|
||||
describe('PATCH /me', () => {
|
||||
test('should succeed with valid inputs', async () => {
|
||||
enableSaml(false);
|
||||
await authOwnerAgent
|
||||
.patch('/me')
|
||||
.send({
|
||||
email: randomEmail(),
|
||||
firstName: randomName(),
|
||||
lastName: randomName(),
|
||||
password: randomValidPassword(),
|
||||
})
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
test('should throw BadRequestError if email is changed when SAML is enabled', async () => {
|
||||
enableSaml(true);
|
||||
await authOwnerAgent
|
||||
.patch('/me')
|
||||
.send({
|
||||
email: randomEmail(),
|
||||
firstName: randomName(),
|
||||
lastName: randomName(),
|
||||
})
|
||||
.expect(400, { code: 400, message: 'SAML user may not change their email' });
|
||||
});
|
||||
expect(response.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
test('PATCH /me should throw BadRequestError if email is changed when SAML is enabled', async () => {
|
||||
enableSaml(true);
|
||||
const owner = await testDb.createOwner();
|
||||
const authOwnerAgent = authAgent(owner);
|
||||
const response = await authOwnerAgent.patch('/me').send({
|
||||
email: randomEmail(),
|
||||
firstName: randomName(),
|
||||
lastName: randomName(),
|
||||
describe('PATCH /password', () => {
|
||||
test('should throw BadRequestError if password is changed when SAML is enabled', async () => {
|
||||
enableSaml(true);
|
||||
await authOwnerAgent
|
||||
.patch('/me/password')
|
||||
.send({
|
||||
password: randomValidPassword(),
|
||||
})
|
||||
.expect(400, {
|
||||
code: 400,
|
||||
message: 'With SAML enabled, users need to use their SAML provider to change passwords',
|
||||
});
|
||||
});
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.body.message).toContain('SAML');
|
||||
enableSaml(false);
|
||||
});
|
||||
|
||||
test('PATCH /password should throw BadRequestError if password is changed when SAML is enabled', async () => {
|
||||
enableSaml(true);
|
||||
const owner = await testDb.createOwner();
|
||||
const authOwnerAgent = authAgent(owner);
|
||||
const response = await authOwnerAgent.patch('/me/password').send({
|
||||
password: randomValidPassword(),
|
||||
});
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.body.message).toContain('SAML');
|
||||
enableSaml(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user