mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Modernize credentials controllers and services (no-changelog) (#8488)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -6,7 +6,6 @@ import type { IUser } from 'n8n-workflow';
|
||||
import type { ListQuery } from '@/requests';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository';
|
||||
import { License } from '@/License';
|
||||
|
||||
import { randomCredentialPayload } from './shared/random';
|
||||
import * as testDb from './shared/testDb';
|
||||
@@ -19,8 +18,10 @@ import { UserManagementMailer } from '@/UserManagement/email';
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
import config from '@/config';
|
||||
|
||||
const sharingSpy = jest.spyOn(License.prototype, 'isSharingEnabled').mockReturnValue(true);
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['credentials'] });
|
||||
const testServer = utils.setupTestServer({
|
||||
endpointGroups: ['credentials'],
|
||||
enabledFeatures: ['feat:sharing'],
|
||||
});
|
||||
|
||||
let owner: User;
|
||||
let member: User;
|
||||
@@ -49,38 +50,6 @@ afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// ----------------------------------------
|
||||
// dynamic router switching
|
||||
// ----------------------------------------
|
||||
describe('router should switch based on flag', () => {
|
||||
let savedCredentialId: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });
|
||||
savedCredentialId = savedCredential.id;
|
||||
});
|
||||
|
||||
test('when sharing is disabled', async () => {
|
||||
sharingSpy.mockReturnValueOnce(false);
|
||||
|
||||
await authOwnerAgent
|
||||
.put(`/credentials/${savedCredentialId}/share`)
|
||||
.send({ shareWithIds: [member.id] })
|
||||
.expect(404);
|
||||
|
||||
await authOwnerAgent.get(`/credentials/${savedCredentialId}`).send().expect(200);
|
||||
});
|
||||
|
||||
test('when sharing is enabled', async () => {
|
||||
await authOwnerAgent
|
||||
.put(`/credentials/${savedCredentialId}/share`)
|
||||
.send({ shareWithIds: [member.id] })
|
||||
.expect(200);
|
||||
|
||||
await authOwnerAgent.get(`/credentials/${savedCredentialId}`).send().expect(200);
|
||||
});
|
||||
});
|
||||
|
||||
// ----------------------------------------
|
||||
// GET /credentials - fetch all credentials
|
||||
// ----------------------------------------
|
||||
@@ -521,6 +490,7 @@ describe('PUT /credentials/:id/share', () => {
|
||||
responses.forEach((response) => expect(response.statusCode).toBe(400));
|
||||
expect(mailer.notifyCredentialsShared).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('should unshare the credential', async () => {
|
||||
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });
|
||||
|
||||
|
||||
@@ -123,8 +123,8 @@ export const setupTestServer = ({
|
||||
for (const group of endpointGroups) {
|
||||
switch (group) {
|
||||
case 'credentials':
|
||||
const { credentialsController } = await import('@/credentials/credentials.controller');
|
||||
app.use(`/${REST_PATH_SEGMENT}/credentials`, credentialsController);
|
||||
const { CredentialsController } = await import('@/credentials/credentials.controller');
|
||||
registerController(app, CredentialsController);
|
||||
break;
|
||||
|
||||
case 'workflows':
|
||||
|
||||
Reference in New Issue
Block a user