mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +00:00
refactor: remove new feature, leave only tests
This commit is contained in:
parent
69ec37d8ab
commit
ff5678cd34
@ -1,11 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs', () => {
|
||||
return { writeFile: jest.fn((_path, _buffer, callback) => callback()) };
|
||||
return {
|
||||
writeFile: jest.fn((_path, _buffer, callback) => callback()),
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('fs-extra', () => {
|
||||
return { pathExistsSync: jest.fn(() => true) };
|
||||
return {
|
||||
pathExistsSync: jest.fn(() => true),
|
||||
};
|
||||
});
|
||||
|
||||
const localProvider = require('../index');
|
||||
@ -14,16 +18,14 @@ describe('Local provider', () => {
|
||||
beforeAll(() => {
|
||||
globalThis.strapi = globalThis.strapi ?? {};
|
||||
globalThis.strapi.dirs = { static: { public: '' } };
|
||||
globalThis.strapi.config = { server: { url: 'http://localhost:1337' } };
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
globalThis.strapi.dirs = undefined;
|
||||
globalThis.strapi.config = undefined;
|
||||
});
|
||||
|
||||
describe('upload', () => {
|
||||
test('Should have relative url to file object without providing useRelateiveUrl', async () => {
|
||||
test('Should have relative url to file object', async () => {
|
||||
const providerInstance = localProvider.init({});
|
||||
|
||||
const file = {
|
||||
@ -39,39 +41,5 @@ describe('Local provider', () => {
|
||||
expect(file.url).toBeDefined();
|
||||
expect(file.url).toEqual('/uploads/test.json');
|
||||
});
|
||||
|
||||
test('Should have relative url to file object with providing true useRelateiveUrl', async () => {
|
||||
const providerInstance = localProvider.init({ useRelativeUrl: true });
|
||||
|
||||
const file = {
|
||||
path: '/tmp/',
|
||||
hash: 'test',
|
||||
ext: '.json',
|
||||
mime: 'application/json',
|
||||
buffer: '',
|
||||
};
|
||||
|
||||
await providerInstance.upload(file);
|
||||
|
||||
expect(file.url).toBeDefined();
|
||||
expect(file.url).toEqual('/uploads/test.json');
|
||||
});
|
||||
|
||||
test('Should have absolute url to file object with providing false useRelateiveUrl', async () => {
|
||||
const providerInstance = localProvider.init({ useRelativeUrl: false });
|
||||
|
||||
const file = {
|
||||
path: '/tmp/',
|
||||
hash: 'test',
|
||||
ext: '.json',
|
||||
mime: 'application/json',
|
||||
buffer: '',
|
||||
};
|
||||
|
||||
await providerInstance.upload(file);
|
||||
|
||||
expect(file.url).toBeDefined();
|
||||
expect(file.url).toEqual('http://localhost:1337/uploads/test.json');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -17,7 +17,7 @@ const {
|
||||
const UPLOADS_FOLDER_NAME = 'uploads';
|
||||
|
||||
module.exports = {
|
||||
init({ sizeLimit: providerOptionsSizeLimit, useRelativeUrl = true } = {}) {
|
||||
init({ sizeLimit: providerOptionsSizeLimit } = {}) {
|
||||
// TODO V5: remove providerOptions sizeLimit
|
||||
if (providerOptionsSizeLimit) {
|
||||
process.emitWarning(
|
||||
@ -60,7 +60,7 @@ module.exports = {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
file.url = getFileUrl(file, useRelativeUrl);
|
||||
file.url = `/${UPLOADS_FOLDER_NAME}/${file.hash}${file.ext}`;
|
||||
|
||||
resolve();
|
||||
}
|
||||
@ -75,7 +75,7 @@ module.exports = {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
file.url = getFileUrl(file, useRelativeUrl);
|
||||
file.url = `/${UPLOADS_FOLDER_NAME}/${file.hash}${file.ext}`;
|
||||
|
||||
resolve();
|
||||
});
|
||||
@ -103,13 +103,3 @@ module.exports = {
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {*} file
|
||||
* @param {boolean} relative
|
||||
* @returns {string}
|
||||
*/
|
||||
function getFileUrl(file, relative) {
|
||||
const pathname = `/${UPLOADS_FOLDER_NAME}/${file.hash}${file.ext}`;
|
||||
return relative ? pathname : `${strapi.config.server.url}${pathname}`;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user