opt-cc/server/test/decorations.spec.js

106 lines
3.1 KiB
JavaScript
Raw Normal View History

let DecorationModel = require('../models/decoration');
let urls = require('../config/api-url');
let codes = require('../routes/http-codes');
2018-03-12 09:26:44 +01:00
// Require the dev-dependencies
let chai = require('chai');
let chaiHttp = require('chai-http');
let server = require('../server');
2018-03-12 12:35:19 +01:00
// chai methods
require('chai').should();
chai.use(chaiHttp);
2018-03-12 09:26:44 +01:00
// Our parent block
describe('Decorations', () => {
2018-03-12 09:26:44 +01:00
beforeEach((done) => { // Before each test we empty the database
DecorationModel.remove({}, (err) => {
done();
});
});
/*
* Test the /GET decorations
*/
describe('/GET decorations', () => {
it('it should GET all the decorations', (done) => {
chai.request(server)
2018-02-26 09:04:27 +01:00
.get(urls.decorations)
.end((err, res) => {
res.should.have.status(codes.success);
res.body.should.be.a('array');
res.body.length.should.be.eql(0);
done();
});
});
});
/*
* Test the /POST decorations
*/
describe('/POST decorations', () => {
it('it should not POST a decoration without auth-token provided', (done) => {
chai.request(server)
2018-02-26 09:04:27 +01:00
.post(urls.decorations)
.send({})
.end((err, res) => {
res.should.have.status(codes.forbidden);
res.body.should.be.a('object');
res.body.should.have.property('success').eql(false);
res.body.should.have.property('message').eql('No token provided.');
done();
});
});
});
/*
* Test the /PATCH decoration
*/
describe('/PATCH decorations', () => {
it('it should not PATCH a decoration without auth-token provided', (done) => {
chai.request(server)
2018-02-26 09:04:27 +01:00
.patch(urls.decorations + '/someId')
.send({})
.end((err, res) => {
res.should.have.status(codes.forbidden);
res.body.should.be.a('object');
res.body.should.have.property('success').eql(false);
res.body.should.have.property('message').eql('No token provided.');
done();
});
});
});
/*
* Test the /DELETE decorations
*/
describe('/DELETE decorations', () => {
it('it should not accept DELETE method without id in url', (done) => {
chai.request(server)
2018-02-26 09:04:27 +01:00
.delete(urls.decorations)
.send({})
.end((err, res) => {
res.should.have.status(codes.wrongmethod);
res.body.should.be.a('object');
res.body.should.have.property('error').property('message')
.eql('this method is not allowed at ' + urls.decorations);
done();
});
});
it('it should not DELETE a decoration without auth-token provided', (done) => {
chai.request(server)
2018-02-26 09:04:27 +01:00
.delete(urls.decorations + '/someId')
.send({})
.end((err, res) => {
res.should.have.status(codes.forbidden);
res.body.should.be.a('object');
res.body.should.have.property('success').eql(false);
res.body.should.have.property('message').eql('No token provided.');
done();
});
});
});
});