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

@@ -2,7 +2,6 @@ import type { SuperAgentTest } from 'supertest';
import Container from 'typedi';
import type { INode } from 'n8n-workflow';
import { STARTING_NODES } from '@/constants';
import { License } from '@/License';
import type { Role } from '@db/entities/Role';
import type { TagEntity } from '@db/entities/TagEntity';
import type { User } from '@db/entities/User';
@@ -10,7 +9,6 @@ import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.reposi
import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository';
import type { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
import { mockInstance } from '../../shared/mocking';
import { randomApiKey } from '../shared/random';
import * as utils from '../shared/utils/';
import * as testDb from '../shared/testDb';
@@ -27,11 +25,7 @@ let authMemberAgent: SuperAgentTest;
let workflowRunner: ActiveWorkflowRunner;
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
const licenseLike = mockInstance(License, {
isWorkflowHistoryLicensed: jest.fn().mockReturnValue(false),
isWithinUsersLimit: jest.fn().mockReturnValue(true),
});
const license = testServer.license;
beforeAll(async () => {
const [globalOwnerRole, globalMemberRole, fetchedWorkflowOwnerRole] = await getAllRoles();
@@ -64,7 +58,6 @@ beforeEach(async () => {
authOwnerAgent = testServer.publicApiAgentFor(owner);
authMemberAgent = testServer.publicApiAgentFor(member);
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
});
afterEach(async () => {
@@ -700,7 +693,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: [
@@ -746,7 +739,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: [
@@ -940,7 +933,7 @@ describe('PUT /workflows/:id', () => {
});
test('should create workflow history version when licensed', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(true);
license.enable('feat:workflowHistory');
const workflow = await createWorkflow({}, member);
const payload = {
name: 'name updated',
@@ -995,7 +988,7 @@ describe('PUT /workflows/:id', () => {
});
test('should not create workflow history when not licensed', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
license.disable('feat:workflowHistory');
const workflow = await createWorkflow({}, member);
const payload = {
name: 'name updated',