|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var supertest = require('supertest'); |
| 4 | +var should = require('should'); |
| 5 | + |
| 6 | +var server = supertest.agent('http://localhost:5000'); |
| 7 | + |
| 8 | +describe('Python Flask Seed Tests', () => { |
| 9 | + |
| 10 | + describe('Route /', () => { |
| 11 | + |
| 12 | + it('should return a message from flask', (done) => { |
| 13 | + server |
| 14 | + .get('/') |
| 15 | + .expect(200) |
| 16 | + .end((err, res) => { |
| 17 | + if (err) return done(err); |
| 18 | + |
| 19 | + res.body.message.should.equal('Hello from flask!'); |
| 20 | + done(); |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + }); |
| 25 | + |
| 26 | + describe('Route /welcome', () => { |
| 27 | + |
| 28 | + it('should return "Hello ${name}!" when POST with name', (done) => { |
| 29 | + server |
| 30 | + .post('/welcome') |
| 31 | + .send({ 'name': 'Roberto' }) |
| 32 | + .expect(200) |
| 33 | + .end((err, res) => { |
| 34 | + if (err) return done(err); |
| 35 | + |
| 36 | + res.body.message.should.equal('Welcome Roberto!'); |
| 37 | + done(); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should return an error when POST without the name', (done) => { |
| 42 | + server |
| 43 | + .post('/welcome') |
| 44 | + .expect(400) |
| 45 | + .end((err, res) => { |
| 46 | + if (err) return done(err); |
| 47 | + |
| 48 | + res.body.error.should.equal('name is required'); |
| 49 | + done(); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + }); |
| 54 | + |
| 55 | + describe('Route /not_found', () => { |
| 56 | + |
| 57 | + it('should return a 404 when GET', (done) => { |
| 58 | + server |
| 59 | + .get('/not_found') |
| 60 | + .expect(404) |
| 61 | + .end((err, res) => { |
| 62 | + if (err) return done(err); |
| 63 | + |
| 64 | + res.body.error.should.equal('route not found'); |
| 65 | + done(); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should return a 404 when POST', (done) => { |
| 70 | + server |
| 71 | + .post('/not_found') |
| 72 | + .expect(404) |
| 73 | + .end((err, res) => { |
| 74 | + if (err) return done(err); |
| 75 | + |
| 76 | + res.body.error.should.equal('route not found'); |
| 77 | + done(); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + }); |
| 82 | + |
| 83 | +}); |
0 commit comments