2019-08-05 09:10:00 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
// Helpers.
|
|
|
|
const { registerAndLogin } = require('../../../test/helpers/auth');
|
|
|
|
const { createAuthRequest } = require('../../../test/helpers/request');
|
|
|
|
|
|
|
|
let rq;
|
|
|
|
|
|
|
|
describe('Upload plugin end to end tests', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
const token = await registerAndLogin();
|
|
|
|
rq = createAuthRequest(token);
|
|
|
|
}, 60000);
|
|
|
|
|
2020-02-26 18:34:45 +01:00
|
|
|
describe('GET /upload/settings => Get settings for an environment', () => {
|
|
|
|
test('Returns the settings', async () => {
|
|
|
|
const res = await rq.get('/upload/settings');
|
2019-08-05 09:10:00 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toEqual({
|
2020-02-26 18:34:45 +01:00
|
|
|
data: {
|
|
|
|
sizeOptimization: true,
|
|
|
|
responsiveDimensions: true,
|
2019-08-05 09:10:00 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('PUT /upload/settings/:environment', () => {
|
2020-04-21 18:24:15 +02:00
|
|
|
test('Updates an environment config correctly', async () => {
|
2020-02-26 18:34:45 +01:00
|
|
|
const updateRes = await rq.put('/upload/settings', {
|
2019-08-05 09:10:00 +02:00
|
|
|
body: {
|
2020-02-26 18:34:45 +01:00
|
|
|
sizeOptimization: true,
|
|
|
|
responsiveDimensions: true,
|
2019-08-05 09:10:00 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(updateRes.statusCode).toBe(200);
|
2020-02-26 18:34:45 +01:00
|
|
|
expect(updateRes.body).toEqual({
|
|
|
|
data: {
|
|
|
|
sizeOptimization: true,
|
|
|
|
responsiveDimensions: true,
|
|
|
|
},
|
|
|
|
});
|
2019-08-05 09:10:00 +02:00
|
|
|
|
2020-02-26 18:34:45 +01:00
|
|
|
const getRes = await rq.get('/upload/settings');
|
2019-08-05 09:10:00 +02:00
|
|
|
|
|
|
|
expect(getRes.statusCode).toBe(200);
|
2020-02-26 18:34:45 +01:00
|
|
|
expect(getRes.body).toEqual({
|
|
|
|
data: {
|
|
|
|
sizeOptimization: true,
|
|
|
|
responsiveDimensions: true,
|
|
|
|
},
|
2019-08-05 09:10:00 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('POST /upload => Upload a file', () => {
|
|
|
|
test('Simple image upload', async () => {
|
|
|
|
const res = await rq.post('/upload', {
|
|
|
|
formData: {
|
|
|
|
files: fs.createReadStream(__dirname + '/rec.jpg'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(Array.isArray(res.body)).toBe(true);
|
|
|
|
expect(res.body.length).toBe(1);
|
|
|
|
expect(res.body[0]).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
id: expect.anything(),
|
2020-03-06 17:00:25 +01:00
|
|
|
name: 'rec',
|
2020-04-03 15:07:12 +02:00
|
|
|
ext: '.jpeg',
|
2020-03-06 17:00:25 +01:00
|
|
|
mime: 'image/jpeg',
|
2019-08-05 09:10:00 +02:00
|
|
|
hash: expect.any(String),
|
2019-10-24 15:07:02 +01:00
|
|
|
size: expect.any(Number),
|
2020-03-06 17:00:25 +01:00
|
|
|
width: expect.any(Number),
|
|
|
|
height: expect.any(Number),
|
2019-08-05 09:10:00 +02:00
|
|
|
url: expect.any(String),
|
|
|
|
provider: 'local',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Rejects when no files are provided', async () => {
|
|
|
|
const res = await rq.post('/upload', {
|
|
|
|
formData: {},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
2020-03-06 17:00:25 +01:00
|
|
|
|
|
|
|
test('Generates a thumbnail on large enough files', async () => {
|
|
|
|
const res = await rq.post('/upload', {
|
|
|
|
formData: {
|
|
|
|
files: fs.createReadStream(__dirname + '/thumbnail_target.png'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(Array.isArray(res.body)).toBe(true);
|
|
|
|
expect(res.body.length).toBe(1);
|
|
|
|
expect(res.body[0]).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
id: expect.anything(),
|
|
|
|
name: 'thumbnail_target',
|
|
|
|
ext: '.png',
|
|
|
|
mime: 'image/png',
|
|
|
|
hash: expect.any(String),
|
|
|
|
size: expect.any(Number),
|
|
|
|
width: expect.any(Number),
|
|
|
|
height: expect.any(Number),
|
|
|
|
url: expect.any(String),
|
|
|
|
provider: 'local',
|
2020-03-09 09:04:32 +01:00
|
|
|
formats: {
|
|
|
|
thumbnail: {
|
|
|
|
hash: expect.any(String),
|
|
|
|
ext: '.png',
|
|
|
|
mime: 'image/png',
|
|
|
|
size: expect.any(Number),
|
|
|
|
width: expect.any(Number),
|
|
|
|
height: expect.any(Number),
|
|
|
|
url: expect.any(String),
|
2020-05-07 09:28:26 +02:00
|
|
|
path: null,
|
2020-03-09 09:04:32 +01:00
|
|
|
},
|
2020-03-06 17:00:25 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2019-08-05 09:10:00 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('GET /upload/files => Find files', () => {});
|
|
|
|
describe('GET /upload/files/count => Count available files', () => {});
|
|
|
|
describe('GET /upload/files/:id => Find one file', () => {});
|
|
|
|
describe('GET /upload/search/:id => Search files', () => {});
|
|
|
|
describe('DELETE /upload/files/:id => Delete a file ', () => {});
|
|
|
|
});
|