2019-08-09 19:55:12 +05:30
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
|
|
|
const localUtils = require('./utils');
|
2022-02-06 16:18:41 +00:00
|
|
|
const testUtils = require('../../../utils');
|
|
|
|
const config = require('../../../../core/shared/config');
|
2019-08-09 19:55:12 +05:30
|
|
|
|
|
|
|
describe('Images API', function () {
|
|
|
|
const images = [];
|
|
|
|
let request;
|
|
|
|
|
2021-11-24 13:42:57 +04:00
|
|
|
before(async function () {
|
2021-11-24 17:29:45 +04:00
|
|
|
await localUtils.startGhost();
|
2021-11-24 13:42:57 +04:00
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
await localUtils.doAuth(request);
|
2019-08-09 19:55:12 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
images.forEach(function (image) {
|
|
|
|
fs.removeSync(config.get('paths').appRoot + image);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can\'t import fail without file', function () {
|
|
|
|
return request
|
|
|
|
.post(localUtils.API.getApiQuery('images/upload'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(422);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can\'t import with unsupported file', function (done) {
|
|
|
|
request.post(localUtils.API.getApiQuery('images/upload'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
2022-02-06 16:18:41 +00:00
|
|
|
.attach('file', path.join(__dirname, '/../../../utils/fixtures/csv/single-column-with-header.csv'))
|
2019-08-09 19:55:12 +05:30
|
|
|
.expect(415)
|
|
|
|
.end(function (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can\'t upload incorrect extension', function (done) {
|
|
|
|
request.post(localUtils.API.getApiQuery('images/upload'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.set('content-type', 'image/png')
|
|
|
|
.expect('Content-Type', /json/)
|
2022-02-06 16:18:41 +00:00
|
|
|
.attach('file', path.join(__dirname, '/../../../utils/fixtures/images/ghost-logo.pngx'))
|
2019-08-09 19:55:12 +05:30
|
|
|
.expect(415)
|
|
|
|
.end(function (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can\'t import if profile image is not square', function (done) {
|
|
|
|
request.post(localUtils.API.getApiQuery('images/upload'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.field('purpose', 'profile_image')
|
2022-02-06 16:18:41 +00:00
|
|
|
.attach('file', path.join(__dirname, '/../../../utils/fixtures/images/favicon_not_square.png'))
|
2019-08-09 19:55:12 +05:30
|
|
|
.expect(422)
|
|
|
|
.end(function (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|