n8n/packages/cli/test/unit/services/role.service.test.ts
कारतोफ्फेलस्क्रिप्ट™ b895ba438a
refactor(core): Reduce boilterplate code in between tests 🧹, and fix the tests in node.js 20 (no-changelog) (#6654)
refactor(core): Reduce boilterplate code in between tests

also cleaned up some imports, and fixed the tests in node.js 20
2023-07-13 10:14:48 +02:00

29 lines
1.2 KiB
TypeScript

import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
import { Role } from '@db/entities/Role';
import { SharedWorkflow } from '@db/entities/SharedWorkflow';
import { RoleService } from '@/role/role.service';
import { mockInstance } from '../../integration/shared/utils/';
describe('RoleService', () => {
const sharedWorkflowRepository = mockInstance(SharedWorkflowRepository);
const roleService = new RoleService(sharedWorkflowRepository);
const userId = '1';
const workflowId = '42';
describe('getUserRoleForWorkflow', () => {
test('should return the role if a shared workflow is found', async () => {
const sharedWorkflow = Object.assign(new SharedWorkflow(), { role: new Role() });
sharedWorkflowRepository.findOne.mockResolvedValueOnce(sharedWorkflow);
const role = await roleService.getUserRoleForWorkflow(userId, workflowId);
expect(role).toBe(sharedWorkflow.role);
});
test('should return undefined if no shared workflow is found', async () => {
sharedWorkflowRepository.findOne.mockResolvedValueOnce(null);
const role = await roleService.getUserRoleForWorkflow(userId, workflowId);
expect(role).toBeUndefined();
});
});
});