2017-12-15 21:21:33 +01:00
|
|
|
const chai = require('chai');
|
|
|
|
const expect = chai.expect;
|
2017-12-15 16:24:29 +01:00
|
|
|
|
2018-04-27 18:54:36 +02:00
|
|
|
describe('publish utils', function () {
|
2017-12-15 16:24:29 +01:00
|
|
|
|
|
|
|
describe('#parsePublishApiRequestBody()', function () {
|
2018-04-27 18:54:36 +02:00
|
|
|
const parsePublishApiRequestBody = require('../../../server/controllers/api/claim/publish/parsePublishApiRequestBody.js');
|
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
it('should throw an error if no body', function () {
|
2018-04-27 18:54:36 +02:00
|
|
|
expect(parsePublishApiRequestBody.bind(this, null)).to.throw();
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
2018-04-27 18:54:36 +02:00
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
it('should throw an error if no body.name', function () {
|
|
|
|
const bodyNoName = {};
|
2018-04-27 18:54:36 +02:00
|
|
|
expect(parsePublishApiRequestBody.bind(this, bodyNoName)).to.throw();
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
2018-04-27 18:54:36 +02:00
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#parsePublishApiRequestFiles()', function () {
|
2018-04-27 18:54:36 +02:00
|
|
|
const parsePublishApiRequestFiles = require('../../../server/controllers/api/claim/publish/parsePublishApiRequestFiles.js');
|
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
it('should throw an error if no files', function () {
|
2018-04-27 18:54:36 +02:00
|
|
|
expect(parsePublishApiRequestFiles.bind(this, null)).to.throw();
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
2018-04-27 18:54:36 +02:00
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
it('should throw an error if no files.file', function () {
|
|
|
|
const filesNoFile = {};
|
2018-04-27 18:54:36 +02:00
|
|
|
expect(parsePublishApiRequestFiles.bind(this, filesNoFile)).to.throw();
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
2018-04-27 18:54:36 +02:00
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
it('should throw an error if file.size is too large', function () {
|
|
|
|
const filesTooBig = {
|
|
|
|
file: {
|
|
|
|
name: 'file.jpg',
|
|
|
|
path: '/path/to/file.jpg',
|
|
|
|
type: 'image/jpg',
|
|
|
|
size: 10000001,
|
|
|
|
},
|
|
|
|
};
|
2018-04-27 18:54:36 +02:00
|
|
|
expect(parsePublishApiRequestFiles.bind(this, filesTooBig)).to.throw();
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
2018-04-27 18:54:36 +02:00
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
it('should throw error if not an accepted file type', function () {
|
2017-12-15 21:21:33 +01:00
|
|
|
const filesWrongType = {
|
2017-12-15 16:24:29 +01:00
|
|
|
file: {
|
|
|
|
name: 'file.jpg',
|
|
|
|
path: '/path/to/file.jpg',
|
|
|
|
type: 'someType/ext',
|
|
|
|
size: 10000000,
|
|
|
|
},
|
|
|
|
};
|
2018-04-27 18:54:36 +02:00
|
|
|
expect(parsePublishApiRequestFiles.bind(this, filesWrongType)).to.throw();
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
2018-04-27 18:54:36 +02:00
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
it('should throw NO error if no problems', function () {
|
|
|
|
const filesNoProblems = {
|
|
|
|
file: {
|
|
|
|
name: 'file.jpg',
|
|
|
|
path: '/path/to/file.jpg',
|
|
|
|
type: 'image/jpg',
|
|
|
|
size: 10000000,
|
|
|
|
},
|
|
|
|
};
|
2018-04-27 18:54:36 +02:00
|
|
|
expect(parsePublishApiRequestFiles.bind(this, filesNoProblems)).to.not.throw();
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#parsePublishApiChannel()', function () {
|
|
|
|
it('should pass the tests I write here');
|
|
|
|
});
|
|
|
|
});
|