2022-03-30 16:26:09 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { createTestBuilder } = require('../../../../../test/helpers/builder');
|
|
|
|
const { createStrapiInstance } = require('../../../../../test/helpers/strapi');
|
|
|
|
const { createAuthRequest } = require('../../../../../test/helpers/request');
|
|
|
|
|
2022-04-06 11:36:13 +02:00
|
|
|
const builder = createTestBuilder();
|
2022-03-30 16:26:09 +02:00
|
|
|
let strapi;
|
|
|
|
let rq;
|
|
|
|
|
2022-04-06 11:36:13 +02:00
|
|
|
const dogModel = {
|
|
|
|
displayName: 'Dog',
|
|
|
|
singularName: 'dog',
|
|
|
|
pluralName: 'dogs',
|
|
|
|
kind: 'collectionType',
|
|
|
|
attributes: {
|
|
|
|
profilePicture: {
|
|
|
|
type: 'media',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-03-30 16:26:09 +02:00
|
|
|
|
2022-04-06 11:36:13 +02:00
|
|
|
describe('Upload', () => {
|
2022-03-30 16:26:09 +02:00
|
|
|
beforeAll(async () => {
|
2022-04-06 11:36:13 +02:00
|
|
|
await builder.addContentType(dogModel).build();
|
2022-03-30 16:26:09 +02:00
|
|
|
strapi = await createStrapiInstance();
|
|
|
|
rq = await createAuthRequest({ strapi });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await strapi.destroy();
|
|
|
|
await builder.cleanup();
|
|
|
|
});
|
|
|
|
|
2022-04-06 11:36:13 +02:00
|
|
|
describe('Create', () => {
|
|
|
|
test('Rejects when no files are provided', async () => {
|
|
|
|
const res = await rq({ method: 'POST', url: '/upload', formData: {} });
|
|
|
|
expect(res.statusCode).toBe(400);
|
2022-03-30 16:26:09 +02:00
|
|
|
});
|
2022-04-06 11:36:13 +02:00
|
|
|
});
|
2022-03-30 16:26:09 +02:00
|
|
|
|
2022-04-06 11:36:13 +02:00
|
|
|
describe('Read', () => {
|
|
|
|
test('GET /upload/files => Find files', async () => {
|
|
|
|
const getRes = await rq({ method: 'GET', url: '/upload/files' });
|
2022-04-04 14:32:08 +02:00
|
|
|
|
2022-04-06 11:36:13 +02:00
|
|
|
expect(getRes.statusCode).toBe(200);
|
|
|
|
expect(getRes.body).toEqual({
|
|
|
|
results: expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
id: expect.anything(),
|
|
|
|
url: expect.any(String),
|
2022-04-04 14:32:08 +02:00
|
|
|
}),
|
2022-04-06 11:36:13 +02:00
|
|
|
]),
|
|
|
|
pagination: {
|
|
|
|
page: expect.any(Number),
|
|
|
|
pageSize: expect.any(Number),
|
|
|
|
pageCount: expect.any(Number),
|
|
|
|
total: expect.any(Number),
|
2022-04-04 14:32:08 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2022-03-30 16:26:09 +02:00
|
|
|
});
|
|
|
|
});
|