From 0e044f76849499250926cb0e2e99b4058685d818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 20 Oct 2022 09:25:39 +0200 Subject: [PATCH] test(core): fix spy in EE credentials tests (#4369) :test_tube: Fix spy in EE credentials tests --- .../cli/test/integration/credentials.ee.test.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/cli/test/integration/credentials.ee.test.ts b/packages/cli/test/integration/credentials.ee.test.ts index 83f8782adb..b59682231c 100644 --- a/packages/cli/test/integration/credentials.ee.test.ts +++ b/packages/cli/test/integration/credentials.ee.test.ts @@ -2,7 +2,7 @@ import express from 'express'; import { UserSettings } from 'n8n-core'; import { In } from 'typeorm'; -import { Db, IUser } from '../../src'; +import { Db } from '../../src'; import { RESPONSE_ERROR_MESSAGES } from '../../src/constants'; import type { CredentialWithSharings } from '../../src/credentials/credentials.types'; import * as UserManagementHelpers from '../../src/UserManagement/UserManagementHelper'; @@ -11,13 +11,10 @@ import { randomCredentialPayload } from './shared/random'; import * as testDb from './shared/testDb'; import type { AuthAgent, SaveCredentialFunction } from './shared/types'; import * as utils from './shared/utils'; +import type { IUser } from 'n8n-workflow'; jest.mock('../../src/telemetry'); -// mock whether credentialsSharing is enabled or not -const mockIsCredentialsSharingEnabled = jest.spyOn(UserManagementHelpers, 'isSharingEnabled'); -mockIsCredentialsSharingEnabled.mockReturnValue(true); - let app: express.Application; let testDbName = ''; let globalOwnerRole: Role; @@ -25,6 +22,7 @@ let globalMemberRole: Role; let credentialOwnerRole: Role; let saveCredential: SaveCredentialFunction; let authAgent: AuthAgent; +let sharingSpy: jest.SpyInstance; beforeAll(async () => { app = await utils.initTestServer({ @@ -45,6 +43,8 @@ beforeAll(async () => { utils.initTestLogger(); utils.initTestTelemetry(); + + sharingSpy = jest.spyOn(UserManagementHelpers, 'isSharingEnabled').mockReturnValue(true); }); beforeEach(async () => { @@ -65,7 +65,7 @@ test('router should switch based on flag', async () => { const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner }); // free router - mockIsCredentialsSharingEnabled.mockReturnValueOnce(false); + sharingSpy.mockReturnValueOnce(false); const freeShareResponse = authAgent(owner) .put(`/credentials/${savedCredential.id}/share`) @@ -82,7 +82,6 @@ test('router should switch based on flag', async () => { expect(freeGetStatus).toBe(200); // EE router - mockIsCredentialsSharingEnabled.mockReturnValueOnce(true); const eeShareResponse = authAgent(owner) .put(`/credentials/${savedCredential.id}/share`)