refactor(upload)

This commit is contained in:
Jamie Howard 2023-02-22 11:21:54 +00:00
parent 1b39486f24
commit 4212f2d33a

View File

@ -65,7 +65,13 @@ describe('Upload | extensions | entity-manager', () => {
})); }));
describe('signEntityMedia', () => { describe('signEntityMedia', () => {
beforeAll(() => { let spySignFileUrls;
beforeEach(() => {
spySignFileUrls = jest.fn();
getService.mockImplementation(() => ({
signFileUrls: spySignFileUrls,
}));
global.strapi = { global.strapi = {
plugins: { plugins: {
upload: {}, upload: {},
@ -79,11 +85,6 @@ describe('Upload | extensions | entity-manager', () => {
media: media[0], media: media[0],
}; };
const spySignFileUrls = jest.fn();
getService.mockImplementation(() => ({
signFileUrls: spySignFileUrls,
}));
await signEntityMedia(entity, modelUID); await signEntityMedia(entity, modelUID);
expect(getService).toBeCalledWith('file'); expect(getService).toBeCalledWith('file');
expect(spySignFileUrls).toBeCalledWith(entity.media); expect(spySignFileUrls).toBeCalledWith(entity.media);
@ -94,11 +95,6 @@ describe('Upload | extensions | entity-manager', () => {
media_repeatable: media, media_repeatable: media,
}; };
const spySignFileUrls = jest.fn();
getService.mockImplementation(() => ({
signFileUrls: spySignFileUrls,
}));
await signEntityMedia(entity, modelUID); await signEntityMedia(entity, modelUID);
expect(getService).toBeCalledWith('file'); expect(getService).toBeCalledWith('file');
expect(spySignFileUrls).toBeCalledTimes(2); expect(spySignFileUrls).toBeCalledTimes(2);
@ -116,11 +112,6 @@ describe('Upload | extensions | entity-manager', () => {
}, },
}; };
const spySignFileUrls = jest.fn();
getService.mockImplementation(() => ({
signFileUrls: spySignFileUrls,
}));
await signEntityMedia(entity, modelUID); await signEntityMedia(entity, modelUID);
expect(getService).toBeCalledWith('file'); expect(getService).toBeCalledWith('file');
expect(spySignFileUrls).toBeCalledTimes(3); expect(spySignFileUrls).toBeCalledTimes(3);
@ -141,11 +132,6 @@ describe('Upload | extensions | entity-manager', () => {
], ],
}; };
const spySignFileUrls = jest.fn();
getService.mockImplementation(() => ({
signFileUrls: spySignFileUrls,
}));
await signEntityMedia(entity, modelUID); await signEntityMedia(entity, modelUID);
expect(getService).toBeCalledWith('file'); expect(getService).toBeCalledWith('file');
expect(spySignFileUrls).toBeCalledTimes(6); expect(spySignFileUrls).toBeCalledTimes(6);