From 17bb36270d92522105cb50ccae03d55625170dc3 Mon Sep 17 00:00:00 2001 From: Rudolf Copi Eckelberg <rce16@inf.ufpr.br> Date: Mon, 10 Oct 2016 11:12:49 -0300 Subject: [PATCH] More simulation testing --- src/test/test.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/test/test.js b/src/test/test.js index d0763cbe..bcda16e0 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -509,6 +509,7 @@ describe('Requires a simulation', () => { chai.request(server) .post(`/api/v1/simulation/${id}`) .send({ + name: 'new_name', location: 5, time: 3, failure_rate: [0.1, 0.2, 0.3], @@ -523,7 +524,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.name.should.equal('new_name'); simulation.should.have.property('location'); simulation.location.should.be.a('number'); simulation.location.should.equal(5); @@ -598,6 +599,29 @@ describe('Requires a simulation', () => { }); }); }); + it('should not update in case of invalid field', (done) => { + newSimulation = new Simulation(); + newSimulation.name = 'test'; + newSimulation.save((err, sim) => { + let id = sim._id; + chai.request(server) + .post(`/api/v1/simulation/${id}`) + .send({ + name: 'other_name', + totally_not_valid_value_for_an_entry: 'not hacking this api', + }) + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('success'); + res.body.success.should.equal(false); + Simulation.findById(id, (err, simulation) => { + simulation.name.should.equal('test'); + done(); + }); + }); + }); + }); it('should include consistent enrollment tables', (done) => { newSimulation = new Simulation(); newSimulation.name = 'test'; @@ -625,4 +649,43 @@ describe('Requires a simulation', () => { }); }); }); + it('should not accept an invalid time', (done) => { + newSimulation = new Simulation(); + newSimulation.name = 'test'; + newSimulation.save((err, sim) => { + let id = sim._id; + chai.request(server) + .post(`/api/v1/simulation/${id}`) + .send({ + time: "I'm an inocent time entry, don't mind me", + }) + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('success'); + res.body.id.should.equal(false); + }); + done(); + }); + }); + it('should not accept enrollments table different than provided time', (done) => { + newSimulation = new Simulation(); + newSimulation.name = 'test'; + newSimulation.save((err, sim) => { + let id = sim._id; + chai.request(server) + .post(`/api/v1/simulation/${id}`) + .send({ + time: 5, + enrollments: "[[1,2,3]]", + }) + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('success'); + res.body.id.should.equal(false); + }); + done(); + }); + }); }); -- GitLab