spee.ch/test/unit/publishHelpers.test.js

64 lines
2.1 KiB
JavaScript
Raw Normal View History

const chai = require('chai');
const expect = chai.expect;
2017-12-15 16:24:29 +01:00
describe('publishHelpers.js', function () {
2018-03-16 18:34:26 +01:00
const publishHelpers = require('../../server/helpers/publishHelpers.js');
2017-12-15 16:24:29 +01:00
describe('#parsePublishApiRequestBody()', function () {
it('should throw an error if no body', function () {
expect(publishHelpers.parsePublishApiRequestBody.bind(this, null)).to.throw();
2017-12-15 16:24:29 +01:00
});
it('should throw an error if no body.name', function () {
const bodyNoName = {};
expect(publishHelpers.parsePublishApiRequestBody.bind(this, bodyNoName)).to.throw();
2017-12-15 16:24:29 +01:00
});
});
describe('#parsePublishApiRequestFiles()', function () {
it('should throw an error if no files', function () {
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, null)).to.throw();
2017-12-15 16:24:29 +01:00
});
it('should throw an error if no files.file', function () {
const filesNoFile = {};
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoFile)).to.throw();
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,
},
};
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, filesTooBig)).to.throw();
2017-12-15 16:24:29 +01:00
});
it('should throw error if not an accepted file type', function () {
const filesWrongType = {
2017-12-15 16:24:29 +01:00
file: {
name: 'file.jpg',
path: '/path/to/file.jpg',
type: 'someType/ext',
size: 10000000,
},
};
expect(publishHelpers.parsePublishApiRequestFiles.bind(this, filesWrongType)).to.throw();
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,
},
};
expect(publishHelpers.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');
});
});