You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-08-10 22:11:50 +02:00
This commit is contained in:
@@ -3,6 +3,9 @@ import initiateLogger from '../../services/initiateLogger';
|
||||
import { BaseQueue, JobData } from '../../types';
|
||||
import createJob from './createJob';
|
||||
import { cleanUpDb, initDb } from '../../testUtils';
|
||||
import FileStorage from '../../services/FileStorage';
|
||||
import { copyFile, exists, remove } from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('createJob', () => {
|
||||
let queue: BaseQueue;
|
||||
@@ -17,6 +20,10 @@ describe('createJob', () => {
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const job = await queue.fetch();
|
||||
if (job) {
|
||||
await remove(join('images', job.data.filePath));
|
||||
}
|
||||
await queue.stop();
|
||||
await cleanUpDb('./createJob.test.sqlite3');
|
||||
});
|
||||
@@ -54,4 +61,20 @@ describe('createJob', () => {
|
||||
const job = await queue.fetch();
|
||||
expect(job).toBeNull();
|
||||
});
|
||||
|
||||
it('should delete the original file after storing', async () => {
|
||||
await copyFile('./images/htr_sample.png', './test_file.png');
|
||||
|
||||
const fs = new FileStorage();
|
||||
const requirements = {
|
||||
filepath: './test_file.png',
|
||||
storeImage: fs.store,
|
||||
sendToQueue: (data: JobData) => queue.send(data),
|
||||
};
|
||||
|
||||
await createJob(requirements);
|
||||
|
||||
const originalFile = await exists('./test_file.png');
|
||||
expect(originalFile).toBe(false);
|
||||
});
|
||||
});
|
||||
|
34
packages/transcribe/src/services/FileStorage.test.ts
Normal file
34
packages/transcribe/src/services/FileStorage.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { copyFile, exists, remove } from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
import FileStorage from './FileStorage';
|
||||
|
||||
describe('FileStorage', () => {
|
||||
|
||||
it('should move file to storage folder', async () => {
|
||||
await copyFile('./images/htr_sample.png', './test_file.png');
|
||||
|
||||
const fs = new FileStorage();
|
||||
const name = await fs.store('./test_file.png');
|
||||
|
||||
const destination = join('images', name);
|
||||
const destinationStillExists = await exists(destination);
|
||||
expect(destinationStillExists).toBe(true);
|
||||
|
||||
await remove(destination);
|
||||
});
|
||||
|
||||
|
||||
it('should remove the original file', async () => {
|
||||
await copyFile('./images/htr_sample.png', './test_file.png');
|
||||
|
||||
const fs = new FileStorage();
|
||||
const name = await fs.store('./test_file.png');
|
||||
|
||||
const originalStillExists = await exists('./test_file.png');
|
||||
expect(originalStillExists).toBe(false);
|
||||
|
||||
await remove(join('images', name));
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { join } from 'path';
|
||||
import { copyFile } from 'fs-extra';
|
||||
import { move } from 'fs-extra';
|
||||
import { randomBytes } from 'crypto';
|
||||
import { ContentStorage } from '../types';
|
||||
|
||||
@@ -7,7 +7,7 @@ export default class FileStorage implements ContentStorage {
|
||||
|
||||
public async store(filepath: string) {
|
||||
const randomName = randomBytes(16).toString('hex');
|
||||
await copyFile(filepath, join('images', randomName));
|
||||
await move(filepath, join('images', randomName));
|
||||
return randomName;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user