|
| 1 | +/* eslint-disable no-return-await */ |
| 2 | +/* eslint-disable no-undef */ |
| 3 | +/* eslint-disable no-underscore-dangle */ |
| 4 | +import supertest from 'supertest'; |
| 5 | +import chai from 'chai'; |
| 6 | +import setupApp from '../../../src/app'; |
| 7 | +import Movie from '../../../src/models/movie'; |
| 8 | + |
| 9 | +describe('Routes: Movies', () => { |
| 10 | + before(async () => { |
| 11 | + const app = await setupApp(); |
| 12 | + global.app = app; |
| 13 | + global.request = supertest(app); |
| 14 | + global.expect = chai.expect; |
| 15 | + }); |
| 16 | + |
| 17 | + after(async () => await app.database.connection.close()); |
| 18 | + |
| 19 | + const defaultId = '5e90f0600bf2272ecf8e82d2'; |
| 20 | + const defaultMovie = { |
| 21 | + title: 'Star Wars A New Hope', |
| 22 | + description: 'Loren ipsun dolor', |
| 23 | + year: '1977', |
| 24 | + director: 'George Lucas', |
| 25 | + }; |
| 26 | + const expectedMovie = { |
| 27 | + __v: 0, |
| 28 | + _id: '5e90f0600bf2272ecf8e82d2', |
| 29 | + title: 'Star Wars A New Hope', |
| 30 | + description: 'Loren ipsun dolor', |
| 31 | + year: '1977', |
| 32 | + director: 'George Lucas', |
| 33 | + }; |
| 34 | + |
| 35 | + beforeEach(async () => { |
| 36 | + await Movie.deleteMany(); |
| 37 | + |
| 38 | + const movie = new Movie(defaultMovie); |
| 39 | + movie._id = defaultId; |
| 40 | + return movie.save(); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('GET /', () => { |
| 44 | + it('should return a list of movies', (done) => { |
| 45 | + request.get('/movies').end((err, res) => { |
| 46 | + expect(res.statusCode).to.eql(200); |
| 47 | + expect(res.body).to.eql([expectedMovie]); |
| 48 | + done(err); |
| 49 | + }); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('GET /', () => { |
| 54 | + it('should return 200 with one movie', (done) => { |
| 55 | + request.get(`/movies/${defaultId}`).end((err, res) => { |
| 56 | + expect(res.statusCode).to.eql(200); |
| 57 | + expect(res.body).to.eql([expectedMovie]); |
| 58 | + done(err); |
| 59 | + }); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe('GET /', () => { |
| 64 | + it('should return a hello world', (done) => { |
| 65 | + request.get('/').end((err, res) => { |
| 66 | + expect(res.statusCode).to.eql(200); |
| 67 | + expect(res.body).to.eql({}); |
| 68 | + expect(res.text).to.eql('Hello World!'); |
| 69 | + done(err); |
| 70 | + }); |
| 71 | + }); |
| 72 | + }); |
| 73 | +}); |
0 commit comments