mirror of
https://github.com/strapi/strapi.git
synced 2025-12-29 16:16:20 +00:00
Merge pull request #16086 from iamandrewluca/upload-local-absolute-url
This commit is contained in:
commit
7ae8ad5915
10
packages/providers/upload-local/jest.config.js
Normal file
10
packages/providers/upload-local/jest.config.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const baseConfig = require('../../../jest.base-config');
|
||||
const pkg = require('./package.json');
|
||||
|
||||
module.exports = {
|
||||
...baseConfig,
|
||||
displayName: pkg.name,
|
||||
roots: [__dirname],
|
||||
};
|
||||
@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
jest.mock('fs', () => {
|
||||
return {
|
||||
writeFile: jest.fn((_path, _buffer, callback) => callback()),
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('fs-extra', () => {
|
||||
return {
|
||||
pathExistsSync: jest.fn(() => true),
|
||||
};
|
||||
});
|
||||
|
||||
const localProvider = require('../index');
|
||||
|
||||
describe('Local provider', () => {
|
||||
beforeAll(() => {
|
||||
globalThis.strapi = globalThis.strapi ?? {};
|
||||
globalThis.strapi.dirs = { static: { public: '' } };
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
globalThis.strapi.dirs = undefined;
|
||||
});
|
||||
|
||||
describe('upload', () => {
|
||||
test('Should have relative url to file object', async () => {
|
||||
const providerInstance = localProvider.init({});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -60,7 +60,7 @@ module.exports = {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
file.url = `/uploads/${file.hash}${file.ext}`;
|
||||
file.url = `/${UPLOADS_FOLDER_NAME}/${file.hash}${file.ext}`;
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user