mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(core): Add ownership, sharing and credential details to GET /workflows (#4510)
* ⚡ Abstract into `getMany()` * ⚡ Use `getMany()` from free controller * ⚡ Use `getMany()` from paid controller * 🧪 Add tests * 🧪 Fix tests * ⚡ Add credential usage info * 🧪 Update tests * ⚡ Add type and adjust test
This commit is contained in:
@@ -16,9 +16,6 @@ import { INode } from 'n8n-workflow';
|
||||
|
||||
jest.mock('../../src/telemetry');
|
||||
|
||||
// mock whether sharing is enabled or not
|
||||
jest.spyOn(UserManagementHelpers, 'isSharingEnabled').mockReturnValue(true);
|
||||
|
||||
let app: express.Application;
|
||||
let testDbName = '';
|
||||
|
||||
@@ -28,6 +25,7 @@ let credentialOwnerRole: Role;
|
||||
let authAgent: AuthAgent;
|
||||
let saveCredential: SaveCredentialFunction;
|
||||
let workflowRunner: ActiveWorkflowRunner.ActiveWorkflowRunner;
|
||||
let sharingSpy: jest.SpyInstance<boolean>;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await utils.initTestServer({
|
||||
@@ -52,6 +50,9 @@ beforeAll(async () => {
|
||||
|
||||
await utils.initNodeTypes();
|
||||
workflowRunner = await utils.initActiveWorkflowRunner();
|
||||
|
||||
config.set('enterprise.features.sharing', true);
|
||||
sharingSpy = jest.spyOn(UserManagementHelpers, 'isSharingEnabled').mockReturnValue(true); // @TODO: Remove on release
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -135,6 +136,73 @@ describe('PUT /workflows/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /workflows', () => {
|
||||
test('should return workflows with ownership, sharing and credential usage details', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||
const member = await testDb.createUser({ globalRole: globalMemberRole });
|
||||
|
||||
const savedCredential = await saveCredential(randomCredentialPayload(), { user: owner });
|
||||
|
||||
const workflow = await createWorkflow(
|
||||
{
|
||||
nodes: [
|
||||
{
|
||||
id: uuid(),
|
||||
name: 'Action Network',
|
||||
type: 'n8n-nodes-base.actionNetwork',
|
||||
parameters: {},
|
||||
typeVersion: 1,
|
||||
position: [0, 0],
|
||||
credentials: {
|
||||
actionNetworkApi: {
|
||||
id: savedCredential.id.toString(),
|
||||
name: savedCredential.name,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
owner,
|
||||
);
|
||||
|
||||
await testDb.shareWorkflowWithUsers(workflow, [member]);
|
||||
|
||||
const response = await authAgent(owner).get('/workflows');
|
||||
|
||||
const [fetchedWorkflow] = response.body.data;
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(fetchedWorkflow.ownedBy).toMatchObject({
|
||||
id: owner.id,
|
||||
email: owner.email,
|
||||
firstName: owner.firstName,
|
||||
lastName: owner.lastName,
|
||||
});
|
||||
|
||||
expect(fetchedWorkflow.sharedWith).toHaveLength(1);
|
||||
|
||||
const [sharee] = fetchedWorkflow.sharedWith;
|
||||
|
||||
expect(sharee).toMatchObject({
|
||||
id: member.id,
|
||||
email: member.email,
|
||||
firstName: member.firstName,
|
||||
lastName: member.lastName,
|
||||
});
|
||||
|
||||
expect(fetchedWorkflow.usedCredentials).toHaveLength(1);
|
||||
|
||||
const [usedCredential] = fetchedWorkflow.usedCredentials;
|
||||
|
||||
expect(usedCredential).toMatchObject({
|
||||
id: savedCredential.id.toString(),
|
||||
name: savedCredential.name,
|
||||
type: savedCredential.type,
|
||||
currentUserHasAccess: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /workflows/:id', () => {
|
||||
test('GET should fail with invalid id due to route rule', async () => {
|
||||
const owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||
|
||||
Reference in New Issue
Block a user