mirror of
https://github.com/strapi/strapi.git
synced 2025-07-19 07:02:26 +00:00
78 lines
1.9 KiB
JavaScript
78 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const { createTestBuilder } = require('api-tests/builder');
|
|
const { createStrapiInstance } = require('api-tests/strapi');
|
|
const { createAuthRequest } = require('api-tests/request');
|
|
|
|
const builder = createTestBuilder();
|
|
let strapi;
|
|
let rq;
|
|
|
|
const dogModel = {
|
|
displayName: 'Dog',
|
|
singularName: 'dog',
|
|
pluralName: 'dogs',
|
|
kind: 'collectionType',
|
|
attributes: {
|
|
profilePicture: {
|
|
type: 'media',
|
|
},
|
|
},
|
|
};
|
|
|
|
describe('Upload', () => {
|
|
beforeAll(async () => {
|
|
await builder.addContentType(dogModel).build();
|
|
strapi = await createStrapiInstance();
|
|
rq = await createAuthRequest({ strapi });
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await strapi.destroy();
|
|
await builder.cleanup();
|
|
});
|
|
|
|
describe('Create', () => {
|
|
test('Rejects when no files are provided', async () => {
|
|
const res = await rq({ method: 'POST', url: '/upload', formData: {} });
|
|
expect(res.statusCode).toBe(400);
|
|
});
|
|
|
|
test('Can upload a file', async () => {
|
|
const res = await rq({
|
|
method: 'POST',
|
|
url: '/upload',
|
|
formData: { files: fs.createReadStream(path.join(__dirname, '../utils/rec.jpg')) },
|
|
});
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
});
|
|
});
|
|
|
|
describe('Read', () => {
|
|
test('GET /upload/files => Find files', async () => {
|
|
const res = await rq({ method: 'GET', url: '/upload/files' });
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
expect(res.body).toEqual({
|
|
results: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: expect.anything(),
|
|
url: expect.any(String),
|
|
}),
|
|
]),
|
|
pagination: {
|
|
page: expect.any(Number),
|
|
pageSize: expect.any(Number),
|
|
pageCount: expect.any(Number),
|
|
total: expect.any(Number),
|
|
},
|
|
});
|
|
res.body.results.forEach((file) => expect(file.folder).toBeDefined());
|
|
});
|
|
});
|
|
});
|