refactor(core): Add central license mock for integration tests (no-changelog) (#7871)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Val
2023-11-30 08:23:09 +00:00
committed by GitHub
parent b16dd21909
commit 5f4a9524ec
12 changed files with 124 additions and 94 deletions

View File

@@ -6,7 +6,6 @@ import type { INode } from 'n8n-workflow';
import * as UserManagementHelpers from '@/UserManagement/UserManagementHelper';
import type { User } from '@db/entities/User';
import { getSharedWorkflowIds } from '@/WorkflowHelpers';
import { License } from '@/License';
import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository';
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
@@ -31,10 +30,6 @@ let authMemberAgent: SuperAgentTest;
let authAnotherMemberAgent: SuperAgentTest;
let saveCredential: SaveCredentialFunction;
const licenseLike = mockInstance(License, {
isWorkflowHistoryLicensed: jest.fn().mockReturnValue(false),
isWithinUsersLimit: jest.fn().mockReturnValue(true),
});
const activeWorkflowRunnerLike = mockInstance(ActiveWorkflowRunner);
const sharingSpy = jest.spyOn(UserManagementHelpers, 'isSharingEnabled').mockReturnValue(true);
@@ -42,6 +37,7 @@ const testServer = utils.setupTestServer({
endpointGroups: ['workflows'],
enabledFeatures: ['feat:sharing'],
});
const license = testServer.license;
beforeAll(async () => {
const globalOwnerRole = await getGlobalOwnerRole();
@@ -66,7 +62,6 @@ beforeEach(async () => {
activeWorkflowRunnerLike.remove.mockReset();
await testDb.truncate(['Workflow', 'SharedWorkflow', 'WorkflowHistory']);
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
});
describe('router should switch based on flag', () => {
@@ -490,7 +485,7 @@ describe('POST /workflows', () => {
});
test('Should create workflow history version when licensed', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(true);
license.enable('feat:workflowHistory');
const payload = {
name: 'testing',
nodes: [
@@ -539,7 +534,7 @@ describe('POST /workflows', () => {
});
test('Should not create workflow history version when not licensed', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
license.disable('feat:workflowHistory');
const payload = {
name: 'testing',
nodes: [
@@ -1013,7 +1008,7 @@ describe('getSharedWorkflowIds', () => {
describe('PATCH /workflows/:id - workflow history', () => {
test('Should create workflow history version when licensed', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(true);
license.enable('feat:workflowHistory');
const workflow = await createWorkflow({}, owner);
const payload = {
name: 'name updated',
@@ -1071,7 +1066,7 @@ describe('PATCH /workflows/:id - workflow history', () => {
});
test('Should not create workflow history version when not licensed', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
license.disable('feat:workflowHistory');
const workflow = await createWorkflow({}, owner);
const payload = {
name: 'name updated',
@@ -1123,7 +1118,7 @@ describe('PATCH /workflows/:id - workflow history', () => {
describe('PATCH /workflows/:id - activate workflow', () => {
test('should activate workflow without changing version ID', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
license.disable('feat:workflowHistory');
const workflow = await createWorkflow({}, owner);
const payload = {
versionId: workflow.versionId,
@@ -1145,7 +1140,7 @@ describe('PATCH /workflows/:id - activate workflow', () => {
});
test('should deactivate workflow without changing version ID', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
license.disable('feat:workflowHistory');
const workflow = await createWorkflow({ active: true }, owner);
const payload = {
versionId: workflow.versionId,