mirror of
https://github.com/strapi/strapi.git
synced 2025-10-11 16:13:12 +00:00
fix(upload): add populate query to findOne method
This commit is contained in:
parent
ea3f7fa37e
commit
2f1b44db8a
@ -26,9 +26,10 @@ module.exports = {
|
||||
async findOne(ctx) {
|
||||
const {
|
||||
params: { id },
|
||||
query: { populate },
|
||||
} = ctx;
|
||||
|
||||
const file = await getService('upload').findOne(id);
|
||||
const file = await getService('upload').findOne(id, populate);
|
||||
|
||||
if (!file) {
|
||||
return ctx.notFound('file.notFound');
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const get = require('lodash/get');
|
||||
|
||||
// Helpers.
|
||||
const { createTestBuilder } = require('../../../../../test/helpers/builder');
|
||||
@ -163,6 +164,17 @@ describe('Upload plugin', () => {
|
||||
])
|
||||
);
|
||||
});
|
||||
test('Get one file', async () => {
|
||||
const getRes = await rq({ method: 'GET', url: '/upload/files/1' });
|
||||
|
||||
expect(getRes.statusCode).toBe(200);
|
||||
expect(getRes.body).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.anything(),
|
||||
url: expect.any(String),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Create an entity with a file', () => {
|
||||
@ -224,6 +236,25 @@ describe('Upload plugin', () => {
|
||||
});
|
||||
data.dogs.push(res.body);
|
||||
});
|
||||
test('File should have related field', async () => {
|
||||
const fileId = get(data, 'dogs[0].data.attributes.profilePicture.data.id');
|
||||
|
||||
expect(fileId).toBeDefined();
|
||||
|
||||
const getRes = await rq({
|
||||
method: 'GET',
|
||||
url: `/upload/files/${fileId}`,
|
||||
qs: { populate: '*' },
|
||||
});
|
||||
|
||||
expect(getRes.statusCode).toBe(200);
|
||||
expect(getRes.body).toEqual(
|
||||
expect.objectContaining({
|
||||
id: fileId,
|
||||
related: [expect.any(Object)],
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Create an entity with a component with a file', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user