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 { v4 as uuid } from 'uuid';
import { RoleService } from '@/services/role.service';
import Container from 'typedi';
import type { ListQuery } from '@/requests';
import { License } from '@/License';
import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository';
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
@@ -25,14 +24,10 @@ let authOwnerAgent: SuperAgentTest;
jest.spyOn(UserManagementHelpers, 'isSharingEnabled').mockReturnValue(false);
const testServer = utils.setupTestServer({ endpointGroups: ['workflows'] });
const license = testServer.license;
const { objectContaining, arrayContaining, any } = expect;
const licenseLike = mockInstance(License, {
isWorkflowHistoryLicensed: jest.fn().mockReturnValue(false),
isWithinUsersLimit: jest.fn().mockReturnValue(true),
});
const activeWorkflowRunnerLike = mockInstance(ActiveWorkflowRunner);
beforeAll(async () => {
@@ -43,7 +38,6 @@ beforeAll(async () => {
beforeEach(async () => {
jest.resetAllMocks();
await testDb.truncate(['Workflow', 'SharedWorkflow', 'Tag', 'WorkflowHistory']);
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
});
describe('POST /workflows', () => {
@@ -65,7 +59,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: [
@@ -114,7 +108,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: [
@@ -428,7 +422,7 @@ describe('GET /workflows', () => {
describe('PATCH /workflows/:id', () => {
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',
@@ -486,7 +480,7 @@ describe('PATCH /workflows/:id', () => {
});
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',
@@ -536,7 +530,7 @@ describe('PATCH /workflows/:id', () => {
});
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,
@@ -558,7 +552,7 @@ describe('PATCH /workflows/:id', () => {
});
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,