Merge pull request #16086 from iamandrewluca/upload-local-absolute-url

This commit is contained in:
Marc 2023-03-21 09:45:41 +01:00 committed by GitHub
commit 7ae8ad5915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 1 deletions

View 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],
};

View File

@ -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');
});
});
});

View File

@ -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();
}