feat(core): Allow filtering executions and users by project in Public API (#10250)

This commit is contained in:
Iván Ovejero
2024-08-02 14:16:17 +02:00
committed by GitHub
parent ae50bb95a8
commit 7056e50b00
12 changed files with 138 additions and 9 deletions

View File

@@ -20,6 +20,8 @@ import {
import type { SuperAgentTest } from '../shared/types';
import { mockInstance } from '@test/mocking';
import { Telemetry } from '@/telemetry';
import { createTeamProject } from '@test-integration/db/projects';
import type { ExecutionEntity } from '@/databases/entities/ExecutionEntity';
let owner: User;
let user1: User;
@@ -447,6 +449,42 @@ describe('GET /executions', () => {
}
});
test('should return executions filtered by project ID', async () => {
/**
* Arrange
*/
const [firstProject, secondProject] = await Promise.all([
createTeamProject(),
createTeamProject(),
]);
const [firstWorkflow, secondWorkflow] = await Promise.all([
createWorkflow({}, firstProject),
createWorkflow({}, secondProject),
]);
const [firstExecution, secondExecution, _] = await Promise.all([
createExecution({}, firstWorkflow),
createExecution({}, firstWorkflow),
createExecution({}, secondWorkflow),
]);
/**
* Act
*/
const response = await authOwnerAgent.get('/executions').query({
projectId: firstProject.id,
});
/**
* Assert
*/
expect(response.statusCode).toBe(200);
expect(response.body.data.length).toBe(2);
expect(response.body.nextCursor).toBeNull();
expect(response.body.data.map((execution: ExecutionEntity) => execution.id)).toEqual(
expect.arrayContaining([firstExecution.id, secondExecution.id]),
);
});
test('owner should retrieve all executions regardless of ownership', async () => {
const [firstWorkflowForUser1, secondWorkflowForUser1] = await createManyWorkflows(2, {}, user1);
await createManyExecutions(2, firstWorkflowForUser1, createSuccessfulExecution);

View File

@@ -7,8 +7,10 @@ import { mockInstance } from '../../shared/mocking';
import { randomApiKey } from '../shared/random';
import * as utils from '../shared/utils/';
import * as testDb from '../shared/testDb';
import { createUser, createUserShell } from '../shared/db/users';
import { createOwner, createUser, createUserShell } from '../shared/db/users';
import type { SuperAgentTest } from '../shared/types';
import { createTeamProject, linkUserToProject } from '@test-integration/db/projects';
import type { User } from '@/databases/entities/User';
mockInstance(License, {
getUsersLimit: jest.fn().mockReturnValue(-1),
@@ -84,6 +86,46 @@ describe('With license unlimited quota:users', () => {
expect(updatedAt).toBeDefined();
}
});
it('should return users filtered by project ID', async () => {
/**
* Arrange
*/
const [owner, firstMember, secondMember, thirdMember] = await Promise.all([
createOwner({ withApiKey: true }),
createUser({ role: 'global:member' }),
createUser({ role: 'global:member' }),
createUser({ role: 'global:member' }),
]);
const [firstProject, secondProject] = await Promise.all([
createTeamProject(),
createTeamProject(),
]);
await Promise.all([
linkUserToProject(firstMember, firstProject, 'project:admin'),
linkUserToProject(secondMember, firstProject, 'project:viewer'),
linkUserToProject(thirdMember, secondProject, 'project:admin'),
]);
/**
* Act
*/
const response = await testServer.publicApiAgentFor(owner).get('/users').query({
projectId: firstProject.id,
});
/**
* Assert
*/
expect(response.status).toBe(200);
expect(response.body.data.length).toBe(2);
expect(response.body.nextCursor).toBeNull();
expect(response.body.data.map((user: User) => user.id)).toEqual(
expect.arrayContaining([firstMember.id, secondMember.id]),
);
});
});
describe('GET /users/:id', () => {