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

@@ -1,8 +1,6 @@
import type { SuperAgentTest } from 'supertest';
import { License } from '@/License';
import type { User } from '@db/entities/User';
import { mockInstance } from '../shared/mocking';
import * as testDb from './shared/testDb';
import * as utils from './shared/utils/';
import { createOwner, createUser } from './shared/db/users';
@@ -14,13 +12,11 @@ let authOwnerAgent: SuperAgentTest;
let member: User;
let authMemberAgent: SuperAgentTest;
const licenseLike = mockInstance(License, {
isWorkflowHistoryLicensed: jest.fn().mockReturnValue(true),
isWithinUsersLimit: jest.fn().mockReturnValue(true),
const testServer = utils.setupTestServer({
endpointGroups: ['workflowHistory'],
enabledFeatures: ['feat:workflowHistory'],
});
const testServer = utils.setupTestServer({ endpointGroups: ['workflowHistory'] });
beforeAll(async () => {
owner = await createOwner();
authOwnerAgent = testServer.authAgentFor(owner);
@@ -28,17 +24,13 @@ beforeAll(async () => {
authMemberAgent = testServer.authAgentFor(member);
});
beforeEach(() => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(true);
});
afterEach(async () => {
await testDb.truncate(['Workflow', 'SharedWorkflow', 'WorkflowHistory']);
});
describe('GET /workflow-history/:workflowId', () => {
test('should not work when license is not available', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
testServer.license.disable('feat:workflowHistory');
const resp = await authOwnerAgent.get('/workflow-history/workflow/badid');
expect(resp.status).toBe(403);
expect(resp.text).toBe('Workflow History license data not found');
@@ -165,7 +157,7 @@ describe('GET /workflow-history/:workflowId', () => {
describe('GET /workflow-history/workflow/:workflowId/version/:versionId', () => {
test('should not work when license is not available', async () => {
licenseLike.isWorkflowHistoryLicensed.mockReturnValue(false);
testServer.license.disable('feat:workflowHistory');
const resp = await authOwnerAgent.get('/workflow-history/workflow/badid/version/badid');
expect(resp.status).toBe(403);
expect(resp.text).toBe('Workflow History license data not found');