opt-cc/api/test/squads.spec.js

110 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

let mongoose = require("mongoose");
let SquadModel = require('../models/squad');
let urls = require('../config/api-url');
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('Squads', () => {
beforeEach((done) => { //Before each test we empty the database
SquadModel.remove({}, (err) => {
done();
});
});
/*
* Test the /GET route
*/
describe('/GET squads', () => {
it('it should GET all the squads', (done) => {
chai.request(server)
.get(urls.squads)
.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 squad
*/
describe('/POST squads', () => {
it('it should not POST a squad without auth-token provided', (done) => {
chai.request(server)
.post(urls.squads)
.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 squad
*/
describe('/PATCH squads', () => {
it('it should not PATCH a squad without auth-token provided', (done) => {
chai.request(server)
.patch(urls.squads + '/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 squad
*/
describe('/DELETE squads', () => {
it('it should not accept DELETE method without id in url', (done) => {
chai.request(server)
.delete(urls.squads)
.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.squads);
done();
});
});
it('it should not DELETE a squad without auth-token provided', (done) => {
chai.request(server)
.delete(urls.squads + '/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();
});
});
});
});