mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
refactor: Refactor variables controller into a RestController (no-changelog) (#7822)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
@@ -4,7 +4,7 @@ import type { Variables } from '@db/entities/Variables';
|
||||
import { VariablesRepository } from '@db/repositories/variables.repository';
|
||||
import { generateNanoId } from '@db/utils/generators';
|
||||
import { License } from '@/License';
|
||||
import { VariablesService } from '@/environments/variables/variables.service';
|
||||
import { VariablesService } from '@/environments/variables/variables.service.ee';
|
||||
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
import * as testDb from './shared/testDb';
|
||||
@@ -15,7 +15,8 @@ let authOwnerAgent: SuperAgentTest;
|
||||
let authMemberAgent: SuperAgentTest;
|
||||
|
||||
const licenseLike = {
|
||||
isVariablesEnabled: jest.fn().mockReturnValue(true),
|
||||
isFeatureEnabled: jest.fn().mockReturnValue(true),
|
||||
isVariablesEnabled: () => licenseLike.isFeatureEnabled(),
|
||||
getVariablesLimit: jest.fn().mockReturnValue(-1),
|
||||
isWithinUsersLimit: jest.fn().mockReturnValue(true),
|
||||
};
|
||||
@@ -59,7 +60,7 @@ beforeAll(async () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['Variables']);
|
||||
licenseLike.isVariablesEnabled.mockReturnValue(true);
|
||||
licenseLike.isFeatureEnabled.mockReturnValue(true);
|
||||
licenseLike.getVariablesLimit.mockReturnValue(-1);
|
||||
});
|
||||
|
||||
@@ -149,7 +150,7 @@ describe('POST /variables', () => {
|
||||
|
||||
test('should not create a new variable and return it for a member', async () => {
|
||||
const response = await authMemberAgent.post('/variables').send(toCreate);
|
||||
expect(response.statusCode).toBe(401);
|
||||
expect(response.statusCode).toBe(403);
|
||||
expect(response.body.data?.key).not.toBe(toCreate.key);
|
||||
expect(response.body.data?.value).not.toBe(toCreate.value);
|
||||
|
||||
@@ -158,9 +159,9 @@ describe('POST /variables', () => {
|
||||
});
|
||||
|
||||
test("POST /variables should not create a new variable and return it if the instance doesn't have a license", async () => {
|
||||
licenseLike.isVariablesEnabled.mockReturnValue(false);
|
||||
licenseLike.isFeatureEnabled.mockReturnValue(false);
|
||||
const response = await authOwnerAgent.post('/variables').send(toCreate);
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.statusCode).toBe(403);
|
||||
expect(response.body.data?.key).not.toBe(toCreate.key);
|
||||
expect(response.body.data?.value).not.toBe(toCreate.value);
|
||||
|
||||
@@ -298,7 +299,7 @@ describe('PATCH /variables/:id', () => {
|
||||
test('should not modify existing variable if use is a member', async () => {
|
||||
const variable = await createVariable('test1', 'value1');
|
||||
const response = await authMemberAgent.patch(`/variables/${variable.id}`).send(toModify);
|
||||
expect(response.statusCode).toBe(401);
|
||||
expect(response.statusCode).toBe(403);
|
||||
expect(response.body.data?.key).not.toBe(toModify.key);
|
||||
expect(response.body.data?.value).not.toBe(toModify.value);
|
||||
|
||||
@@ -354,7 +355,7 @@ describe('DELETE /variables/:id', () => {
|
||||
]);
|
||||
|
||||
const delResponse = await authMemberAgent.delete(`/variables/${var1.id}`);
|
||||
expect(delResponse.statusCode).toBe(401);
|
||||
expect(delResponse.statusCode).toBe(403);
|
||||
|
||||
const byId = await getVariableById(var1.id);
|
||||
expect(byId).not.toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user