address review feedback
Signed-off-by: John Collier <jcollier@redhat.com>
This commit is contained in:
@@ -199,7 +199,7 @@ describe('createListScaffolderTasksAction', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should filter tasks by status when status is provided', async () => {
|
||||
it('should filter tasks by a single status when status is provided', async () => {
|
||||
const mockActionsRegistry = actionsRegistryServiceMock();
|
||||
const mockAuth = mockServices.auth.mock();
|
||||
const mockScaffolderService = scaffolderServiceMock.mock();
|
||||
@@ -244,6 +244,51 @@ describe('createListScaffolderTasksAction', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should filter tasks by multiple statuses when an array is provided', async () => {
|
||||
const mockActionsRegistry = actionsRegistryServiceMock();
|
||||
const mockAuth = mockServices.auth.mock();
|
||||
const mockScaffolderService = scaffolderServiceMock.mock();
|
||||
const matchingTasks = generateMockTasks().tasks.filter(
|
||||
t => t.status === 'completed' || t.status === 'failed',
|
||||
);
|
||||
|
||||
mockScaffolderService.listTasks.mockResolvedValue({
|
||||
items: matchingTasks as ScaffolderTask[],
|
||||
totalItems: matchingTasks.length,
|
||||
});
|
||||
|
||||
createListScaffolderTasksAction({
|
||||
actionsRegistry: mockActionsRegistry,
|
||||
auth: mockAuth,
|
||||
scaffolderService: mockScaffolderService,
|
||||
});
|
||||
|
||||
const result = await mockActionsRegistry.invoke({
|
||||
id: 'test:list-scaffolder-tasks',
|
||||
input: { status: ['completed', 'failed'] },
|
||||
});
|
||||
|
||||
expect(mockScaffolderService.listTasks).toHaveBeenCalledWith(
|
||||
{
|
||||
createdBy: undefined,
|
||||
limit: undefined,
|
||||
offset: undefined,
|
||||
status: ['completed', 'failed'],
|
||||
},
|
||||
expect.objectContaining({ credentials: expect.anything() }),
|
||||
);
|
||||
expect(result.output).toEqual({
|
||||
tasks: matchingTasks.map(task => ({
|
||||
id: task.id,
|
||||
spec: task.spec,
|
||||
status: task.status,
|
||||
createdAt: task.createdAt,
|
||||
lastHeartbeatAt: task.lastHeartbeatAt,
|
||||
})),
|
||||
totalTasks: matchingTasks.length,
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw NotAllowedError when owned is true without user identity', async () => {
|
||||
const mockActionsRegistry = actionsRegistryServiceMock();
|
||||
const mockAuth = mockServices.auth.mock();
|
||||
|
||||
@@ -40,7 +40,7 @@ This allows you to list scaffolder tasks that have been created.
|
||||
Each task has a unique id, specification, and status (one of open, processing, completed, failed, cancelled, skipped).
|
||||
Each task includes a timestamp for when it was created, and an optional last heartbeat timestamp indicating the most recent activity.
|
||||
Set owned to true to return only tasks created by the current user; omit or set to false for all tasks the credentials can see.
|
||||
Pagination is supported via limit and offset.
|
||||
Filtering by one or multiple statuses is supported. Pagination is supported via limit and offset.
|
||||
`,
|
||||
schema: {
|
||||
input: z =>
|
||||
@@ -66,16 +66,28 @@ Pagination is supported via limit and offset.
|
||||
.describe('The offset to start from for pagination')
|
||||
.optional(),
|
||||
status: z
|
||||
.enum([
|
||||
'open',
|
||||
'processing',
|
||||
'completed',
|
||||
'failed',
|
||||
'cancelled',
|
||||
'skipped',
|
||||
.union([
|
||||
z.enum([
|
||||
'open',
|
||||
'processing',
|
||||
'completed',
|
||||
'failed',
|
||||
'cancelled',
|
||||
'skipped',
|
||||
]),
|
||||
z.array(
|
||||
z.enum([
|
||||
'open',
|
||||
'processing',
|
||||
'completed',
|
||||
'failed',
|
||||
'cancelled',
|
||||
'skipped',
|
||||
]),
|
||||
),
|
||||
])
|
||||
.optional()
|
||||
.describe('Filter tasks by status'),
|
||||
.describe('Filter tasks by status, or an array of statuses'),
|
||||
}),
|
||||
output: z =>
|
||||
z
|
||||
|
||||
@@ -80,7 +80,7 @@ export interface ScaffolderService {
|
||||
createdBy?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
status?: ScaffolderTaskStatus;
|
||||
status?: ScaffolderTaskStatus | ScaffolderTaskStatus[];
|
||||
},
|
||||
options: ScaffolderServiceRequestOptions,
|
||||
): Promise<{
|
||||
|
||||
@@ -391,7 +391,7 @@ export interface ScaffolderService {
|
||||
createdBy?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
status?: ScaffolderTaskStatus;
|
||||
status?: ScaffolderTaskStatus | ScaffolderTaskStatus[];
|
||||
},
|
||||
options: ScaffolderServiceRequestOptions,
|
||||
): Promise<{
|
||||
|
||||
@@ -83,7 +83,7 @@ export interface ScaffolderService {
|
||||
createdBy?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
status?: ScaffolderTaskStatus;
|
||||
status?: ScaffolderTaskStatus | ScaffolderTaskStatus[];
|
||||
},
|
||||
options: ScaffolderServiceRequestOptions,
|
||||
): Promise<{ items: ScaffolderTask[]; totalItems: number }>;
|
||||
@@ -186,7 +186,7 @@ class DefaultScaffolderService implements ScaffolderService {
|
||||
createdBy?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
status?: ScaffolderTaskStatus;
|
||||
status?: ScaffolderTaskStatus | ScaffolderTaskStatus[];
|
||||
},
|
||||
options: ScaffolderServiceRequestOptions,
|
||||
): Promise<{ items: ScaffolderTask[]; totalItems: number }> {
|
||||
@@ -204,7 +204,9 @@ class DefaultScaffolderService implements ScaffolderService {
|
||||
params.set('offset', String(request.offset));
|
||||
}
|
||||
if (request.status !== undefined) {
|
||||
params.set('status', request.status);
|
||||
for (const s of [request.status].flat()) {
|
||||
params.append('status', s);
|
||||
}
|
||||
}
|
||||
|
||||
const query = params.toString();
|
||||
|
||||
Reference in New Issue
Block a user