fix(editor): Fix delete all existing executions (#11352)

This commit is contained in:
Csaba Tuncsik 2024-10-23 12:46:34 +02:00 committed by GitHub
parent d309112647
commit 3ec103f8ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 71 additions and 1 deletions

View file

@ -143,7 +143,7 @@ async function handleDeleteSelected() {
await executionsStore.deleteExecutions({
filters: executionsStore.executionsFilters,
...(allExistingSelected.value
? { deleteBefore: props.executions[0].startedAt }
? { deleteBefore: new Date() }
: {
ids: Object.keys(selectedItems.value),
}),

View file

@ -0,0 +1,69 @@
import { vi } from 'vitest';
import { setActivePinia, createPinia } from 'pinia';
import type { ExecutionSummaryWithScopes } from '@/Interface';
import { useExecutionsStore } from '@/stores/executions.store';
vi.mock('@/utils/apiUtils', () => ({
makeRestApiRequest: vi.fn(),
}));
describe('executions.store', () => {
let executionsStore: ReturnType<typeof useExecutionsStore>;
beforeEach(() => {
setActivePinia(createPinia());
executionsStore = useExecutionsStore();
});
describe('deleteExecutions', () => {
const mockExecutions: ExecutionSummaryWithScopes[] = [
{
id: '3',
mode: 'manual',
status: 'success',
startedAt: new Date('2021-01-03T00:00:00Z'),
workflowId: '1',
scopes: [],
},
{
id: '2',
mode: 'manual',
status: 'success',
startedAt: new Date('2021-01-02T00:00:00Z'),
workflowId: '1',
scopes: [],
},
{
id: '1',
mode: 'manual',
status: 'success',
startedAt: new Date('2021-01-01T00:00:00Z'),
workflowId: '1',
scopes: [],
},
];
beforeEach(() => {
mockExecutions.forEach(executionsStore.addExecution);
});
it('should delete executions by ID', async () => {
await executionsStore.deleteExecutions({ ids: ['1', '3'] });
expect(executionsStore.executions).toEqual([mockExecutions[1]]);
});
it('should delete executions started before given date', async () => {
await executionsStore.deleteExecutions({ deleteBefore: mockExecutions[1].startedAt });
expect(executionsStore.executions).toEqual([mockExecutions[0], mockExecutions[1]]);
});
it('should delete all executions if given date is now', async () => {
await executionsStore.deleteExecutions({ deleteBefore: new Date() });
expect(executionsStore.executions).toEqual([]);
});
});
});

View file

@ -290,6 +290,7 @@ export const useExecutionsStore = defineStore('executions', () => {
stopCurrentExecution,
retryExecution,
deleteExecutions,
addExecution,
resetData,
reset,
};