Skip to content
Snippets Groups Projects
Commit 35e17fd7 authored by Rudolf Copi Eckelberg's avatar Rudolf Copi Eckelberg
Browse files

Simulation test coverage increase

parent 006998b2
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!25Auth
Pipeline #
......@@ -64,7 +64,7 @@ simulationApp.get('/:id', (req, res) => {
});
simulationApp.post('/:id', (req, res, next) => {
if (!req.body) {
if (!Object.keys(req.body).length) {
res.send({ success: false, msg: 'No field informed to update' });
} else {
next();
......
......@@ -492,6 +492,7 @@ describe('Requires a simulation', () => {
Simulation.findById(res.body.id, (err, simulation) => {
simulation.should.have.property('name');
simulation.name.should.be.a('string');
simulation.name.should.equal('test');
simulation.should.have.property('location');
simulation.location.should.be.a('number');
simulation.location.should.equal(5);
......@@ -500,6 +501,63 @@ describe('Requires a simulation', () => {
});
});
});
it('should update multiple fields on a single request', (done) => {
newSimulation = new Simulation();
newSimulation.name = 'test';
newSimulation.save((err, sim) => {
let id = sim._id;
chai.request(server)
.post(`/api/v1/simulation/${id}`)
.send({
location: 5,
time: 3,
failure_rate: [0.1, 0.2, 0.3],
goals_care: [0.3, 0.2, 0.1],
goals_inclusion: [0.8, 0.9, 1]
})
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('id');
res.body.id.should.be.a('string');
Simulation.findById(res.body.id, (err, simulation) => {
simulation.should.have.property('name');
simulation.name.should.be.a('string');
simulation.name.should.equal('test');
simulation.should.have.property('location');
simulation.location.should.be.a('number');
simulation.location.should.equal(5);
simulation.should.have.property('time');
simulation.time.should.be.a('number');
simulation.time.should.equal(3);
simulation.should.have.property('failure_rate');
simulation.failure_rate.should.be.a('array');
simulation.failure_rate.length.should.equal(3);
simulation.should.have.property('goals_care');
simulation.goals_care.should.be.a('array');
simulation.goals_care.length.should.equal(3);
simulation.should.have.property('goals_inclusion');
simulation.goals_inclusion.should.be.a('array');
simulation.goals_inclusion.length.should.equal(3);
});
done();
});
});
});
it('should not update an unexisting simulation', (done) => {
newSimulation = new Simulation();
let id = newSimulation._id;
chai.request(server)
.post(`/api/v1/simulation/${id}`)
.send({ location: 5 })
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('success');
res.body.success.should.equal(false);
done();
});
});
it('should update an existing simulation\'s time', (done) => {
newSimulation = new Simulation();
newSimulation.name = 'test';
......@@ -524,4 +582,22 @@ describe('Requires a simulation', () => {
});
});
});
it('should not change results for empty post requests', (done) => {
newSimulation = new Simulation();
newSimulation.name = 'test';
newSimulation.save((err, sim) => {
let id = sim._id;
chai.request(server)
.post(`/api/v1/simulation/${id}`)
.end((err, res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('success');
res.body.success.should.equal(false);
done();
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment