Fix deleteFile undefined $toast and reversed delete/fetch order

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 08:09:37 +08:00
parent 6178f09cfe
commit 833427b224
2 changed files with 24 additions and 5 deletions

View File

@@ -256,7 +256,8 @@ export default defineStore('filesStore', {
let api;
if(id == null || isNaN(id)) {
return $toast.default('Delete File API Error.', {position: 'bottom'});
console.error('Delete File API Error: invalid id');
return;
};
const loading = loadingStore();
loading.isLoading = true;
@@ -275,8 +276,8 @@ export default defineStore('filesStore', {
break;
}
try {
await this.fetchAllFiles();
await axios.delete(api);
await this.fetchAllFiles();
await deleteSuccess();
} catch(error) {
apiError(error, 'Failed to delete.');

View File

@@ -159,13 +159,31 @@ describe('filesStore', () => {
});
describe('deleteFile', () => {
it('deletes a log file via axios.delete', async () => {
axios.get.mockResolvedValue({ data: [] });
axios.delete.mockResolvedValue({});
it('calls axios.delete before fetchAllFiles', async () => {
const callOrder = [];
axios.delete.mockImplementation(async () => {
callOrder.push('delete');
return {};
});
axios.get.mockImplementation(async () => {
callOrder.push('get');
return { data: [] };
});
await store.deleteFile('log', 1);
expect(axios.delete).toHaveBeenCalledWith('/api/logs/1');
expect(callOrder.indexOf('delete')).toBeLessThan(
callOrder.indexOf('get'),
);
});
it('returns early for invalid id without throwing', async () => {
await expect(
store.deleteFile('log', null),
).resolves.toBeUndefined();
expect(axios.delete).not.toHaveBeenCalled();
});
});