Init test for upload service

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-03-03 16:31:18 +01:00
parent e5b319d81e
commit dd93ccd590
2 changed files with 22 additions and 1 deletions

View File

@ -21,7 +21,7 @@ const generateFileName = name => {
};
module.exports = {
formatFileInfo({ filename, type, size }, fileInfo, metas) {
formatFileInfo({ filename, type, size }, fileInfo = {}, metas = {}) {
const ext = path.extname(filename);
const baseName = path.basename(filename, ext);

View File

@ -0,0 +1,21 @@
const uploadService = require('../Upload');
describe('Upload service', () => {
describe('formatFileInfo', () => {
test('Generates hash', () => {
const fileData = {
filename: 'File Name.png',
type: 'image/png',
size: 1000 * 1000,
};
expect(uploadService.formatFileInfo(fileData)).toMatchObject({
name: 'File Name',
hash: expect.stringContaining('File_Name'),
ext: '.png',
mime: 'image/png',
size: 1000,
});
});
});
});