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,6 +1,5 @@
import type { SuperAgentTest } from 'supertest';
import { Container } from 'typedi';
import { License } from '@/License';
import validator from 'validator';
import config from '@/config';
import { AUTH_COOKIE_NAME } from '@/constants';
@@ -21,6 +20,7 @@ let authOwnerAgent: SuperAgentTest;
const ownerPassword = randomValidPassword();
const testServer = utils.setupTestServer({ endpointGroups: ['auth'] });
const license = testServer.license;
beforeAll(async () => {
globalOwnerRole = await getGlobalOwnerRole();
@@ -79,7 +79,7 @@ describe('POST /login', () => {
});
test('should throw AuthError for non-owner if not within users limit quota', async () => {
jest.spyOn(Container.get(License), 'isWithinUsersLimit').mockReturnValueOnce(false);
license.setQuota('quota:users', 0);
const password = 'testpassword';
const member = await createUser({
password,
@@ -93,7 +93,7 @@ describe('POST /login', () => {
});
test('should not throw AuthError for owner if not within users limit quota', async () => {
jest.spyOn(Container.get(License), 'isWithinUsersLimit').mockReturnValueOnce(false);
license.setQuota('quota:users', 0);
const ownerUser = await createUser({
password: randomValidPassword(),
globalRole: globalOwnerRole,
@@ -315,7 +315,7 @@ describe('GET /resolve-signup-token', () => {
});
test('should return 403 if user quota reached', async () => {
jest.spyOn(Container.get(License), 'isWithinUsersLimit').mockReturnValueOnce(false);
license.setQuota('quota:users', 0);
const memberShell = await createUserShell(globalMemberRole);
const response = await authOwnerAgent