2017-05-11 15:12:17 +02:00
|
|
|
let mongoose = require("mongoose");
|
|
|
|
let AwardingModel = require('../models/awarding');
|
2017-05-11 18:36:32 +02:00
|
|
|
let urls = require('../config/api-url');
|
2017-05-11 15:12:17 +02:00
|
|
|
let codes = require('../routes/http-codes');
|
|
|
|
|
|
|
|
|
|
|
|
//Require the dev-dependencies
|
|
|
|
let chai = require('chai');
|
|
|
|
let chaiHttp = require('chai-http');
|
|
|
|
let server = require('../server');
|
|
|
|
let should = chai.should();
|
|
|
|
|
|
|
|
chai.use(chaiHttp);
|
|
|
|
//Our parent block
|
|
|
|
describe('Awardings', () => {
|
|
|
|
beforeEach((done) => { //Before each test we empty the database
|
|
|
|
AwardingModel.remove({}, (err) => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
/*
|
|
|
|
* Test the /GET awardings
|
|
|
|
*/
|
|
|
|
describe('/GET awardings', () => {
|
2017-07-09 18:45:07 +02:00
|
|
|
it('it should GET all awardings', (done) => {
|
2017-05-11 15:12:17 +02:00
|
|
|
chai.request(server)
|
|
|
|
.get(urls.awards)
|
|
|
|
.end((err, res) => {
|
2017-07-09 18:45:07 +02:00
|
|
|
res.should.have.status(codes.success);
|
|
|
|
res.body.should.be.a('array');
|
|
|
|
res.body.length.should.be.eql(0);
|
2017-05-11 15:12:17 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the /POST awardings
|
|
|
|
*/
|
|
|
|
describe('/POST awardings', () => {
|
|
|
|
|
|
|
|
it('it should not POST an awarding without auth-token provided', (done) => {
|
|
|
|
chai.request(server)
|
|
|
|
.post(urls.awards)
|
|
|
|
.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 awardings
|
|
|
|
*/
|
|
|
|
describe('/PATCH awardings', () => {
|
|
|
|
|
|
|
|
it('it should not PATCH an awarding without auth-token provided', (done) => {
|
|
|
|
chai.request(server)
|
|
|
|
.patch(urls.awards + '/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 awardings
|
|
|
|
*/
|
|
|
|
describe('/DELETE awardings', () => {
|
|
|
|
|
2017-07-09 18:45:07 +02:00
|
|
|
it('it should not accept DELETE method without id in url', (done) => {
|
2017-05-11 15:12:17 +02:00
|
|
|
chai.request(server)
|
|
|
|
.delete(urls.awards)
|
|
|
|
.send({})
|
|
|
|
.end((err, res) => {
|
2017-07-09 18:45:07 +02:00
|
|
|
res.should.have.status(codes.wrongmethod);
|
2017-05-11 15:12:17 +02:00
|
|
|
res.body.should.be.a('object');
|
2017-07-09 18:45:07 +02:00
|
|
|
res.body.should.have.property('error').property('message')
|
|
|
|
.eql('this method is not allowed at ' + urls.awards);
|
2017-05-11 15:12:17 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('it should not DELETE an awarding without auth-token provided', (done) => {
|
|
|
|
chai.request(server)
|
|
|
|
.delete(urls.awards + '/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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|