2017-05-11 15:12:17 +02:00
|
|
|
let RankModel = require('../models/rank');
|
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');
|
|
|
|
|
|
|
|
|
2018-03-12 09:26:44 +01:00
|
|
|
// Require the dev-dependencies
|
2017-05-11 15:12:17 +02:00
|
|
|
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();
|
|
|
|
|
2017-05-11 15:12:17 +02:00
|
|
|
chai.use(chaiHttp);
|
2018-03-12 09:26:44 +01:00
|
|
|
// Our parent block
|
2017-05-11 15:12:17 +02:00
|
|
|
describe('Ranks', () => {
|
2018-03-12 09:26:44 +01:00
|
|
|
beforeEach((done) => { // Before each test we empty the database
|
2017-05-11 15:12:17 +02:00
|
|
|
RankModel.remove({}, (err) => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
/*
|
|
|
|
* Test the /GET ranks
|
|
|
|
*/
|
|
|
|
describe('/GET ranks', () => {
|
|
|
|
it('it should GET all the ranks', (done) => {
|
|
|
|
chai.request(server)
|
2018-02-26 09:04:27 +01:00
|
|
|
.get(urls.ranks)
|
|
|
|
.end((err, res) => {
|
|
|
|
res.should.have.status(codes.success);
|
|
|
|
res.body.should.be.a('array');
|
|
|
|
res.body.length.should.be.eql(0);
|
|
|
|
done();
|
|
|
|
});
|
2017-05-11 15:12:17 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the /POST ranks
|
|
|
|
*/
|
|
|
|
describe('/POST ranks', () => {
|
|
|
|
it('it should not POST a rank without auth-token provided', (done) => {
|
|
|
|
chai.request(server)
|
2018-02-26 09:04:27 +01:00
|
|
|
.post(urls.ranks)
|
|
|
|
.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();
|
|
|
|
});
|
2017-05-11 15:12:17 +02:00
|
|
|
});
|
2018-03-12 09:26:44 +01:00
|
|
|
});
|
2017-05-11 15:12:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the /PATCH rank
|
|
|
|
*/
|
|
|
|
describe('/PATCH ranks', () => {
|
|
|
|
it('it should not PATCH a rank without auth-token provided', (done) => {
|
|
|
|
chai.request(server)
|
2018-02-26 09:04:27 +01:00
|
|
|
.patch(urls.ranks + '/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();
|
|
|
|
});
|
2017-05-11 15:12:17 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the /DELETE rank
|
|
|
|
*/
|
|
|
|
describe('/DELETE ranks', () => {
|
|
|
|
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.ranks)
|
|
|
|
.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.ranks);
|
|
|
|
done();
|
|
|
|
});
|
2017-05-11 15:12:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('it should not DELETE a rank without auth-token provided', (done) => {
|
|
|
|
chai.request(server)
|
2018-02-26 09:04:27 +01:00
|
|
|
.delete(urls.ranks + '/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();
|
|
|
|
});
|
2017-05-11 15:12:17 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|