-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove image file when uploaded successfully
- Loading branch information
1 parent
05f9da4
commit c4b0d1a
Showing
7 changed files
with
100 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { removeFile } from '../../src/lib/lib-utils'; // Adjust the import path as necessary | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { vi, expect, test, beforeAll, afterAll, describe } from 'vitest'; | ||
|
||
describe('removeFile', () => { | ||
const testFilePath = path.join(__dirname, 'test-file.txt'); | ||
|
||
beforeAll(() => { | ||
// Create a test file to remove | ||
fs.writeFileSync(testFilePath, 'This is a test file.'); | ||
}); | ||
|
||
afterAll(() => { | ||
// Clean up: remove the test file if it exists | ||
if (fs.existsSync(testFilePath)) { | ||
fs.unlinkSync(testFilePath); | ||
} | ||
}); | ||
|
||
test('should remove an existing file', async () => { | ||
await removeFile(testFilePath); | ||
expect(fs.existsSync(testFilePath)).toBe(false); | ||
}); | ||
|
||
test('should handle removing a non-existent file', async () => { | ||
const nonExistentFilePath = path.join(__dirname, 'non-existent-file.txt'); | ||
const result = await removeFile(nonExistentFilePath); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test('it logs an error if file does not exist', async () => { | ||
const nonExistentFilePath = path.join(__dirname, 'non-existent-file.txt'); | ||
const spy = vi.spyOn(console, 'error'); | ||
await removeFile(nonExistentFilePath); | ||
expect(spy).toHaveBeenCalledOnce(); | ||
expect(spy).toHaveBeenCalledWith( | ||
expect.stringContaining(`File ${nonExistentFilePath} does not exist`) | ||
); | ||
spy.mockRestore(); | ||
}); | ||
}); |