diff --git a/packages/core/upload/server/controllers/content-api.js b/packages/core/upload/server/controllers/content-api.js index 7d4565d316..7cb013a5ab 100644 --- a/packages/core/upload/server/controllers/content-api.js +++ b/packages/core/upload/server/controllers/content-api.js @@ -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'); diff --git a/packages/core/upload/tests/content-api/upload.test.api.js b/packages/core/upload/tests/content-api/upload.test.api.js index 6919c8db92..1d4fde0452 100644 --- a/packages/core/upload/tests/content-api/upload.test.api.js +++ b/packages/core/upload/tests/content-api/upload.test.api.js @@ -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', () => {