diff --git a/src/stores/files.js b/src/stores/files.js index 18a7543..0173297 100644 --- a/src/stores/files.js +++ b/src/stores/files.js @@ -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.'); diff --git a/tests/stores/files.test.js b/tests/stores/files.test.js index 22f7a61..ac11e5a 100644 --- a/tests/stores/files.test.js +++ b/tests/stores/files.test.js @@ -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(); }); });