Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. /* eslint-disable import/no-extraneous-dependencies*/
  2. // Test cases for routing
  3.  
  4. import { expect } from 'chai';
  5. import request from 'supertest';
  6.  
  7. import { BaseModel } from '../API/models/BaseSchema';
  8. import Movie from '../API/models/MovieSchema';
  9. import server from '../server';
  10. import sampleData from './sampleData';
  11.  
  12. let movieId;
  13. let movieId2;
  14. const { sampleMovie } = sampleData;
  15.  
  16. before(() => {
  17. const movie = new Movie({ title: 'CasaBlanca' });
  18. const movie2 = new Movie({ title: 'X men' });
  19. movie.save();
  20. movie2.save();
  21. BaseModel.find().then(( response ) => {
  22. movieId = response.find( item => item.title === 'CasaBlanca' )._id;
  23. movieId2 = response.find( item => item.title === 'X men' )._id;
  24. });
  25. });
  26.  
  27. after(() => {
  28. BaseModel.remove({ _id: `${movieId}` }).exec();
  29. BaseModel.remove({ _id: `${movieId2}` }).exec();
  30. });
  31.  
  32. describe( 'Routing test cases', () => {
  33. describe( 'Movies route', () => {
  34. it( 'Movies route should return 200', () => {
  35. request( server )
  36. .get( '/movies' )
  37. .expect( 200 )
  38. .then( response => expect( response.text ).to.equal( 'Rambo' ));
  39. });
  40.  
  41. it( 'A page per movie should be displayed', () => {
  42. request( server )
  43. .get( '/movies/58faa4dfb131c3f8c49cb3b0' )
  44. .expect( 200 )
  45. .then( response => expect( response.text ).to.equal( 'Rambo' ));
  46. });
  47.  
  48. it( 'myRating property can be set', () => {
  49. request( server )
  50. .post( '/movies/58faa4dfb131c3f8c49cb3b0' )
  51. .send({ rating: '5.6' })
  52. .expect( 200 )
  53. .then( response => expect( response.text ).to.equal( 'myRating: 5.6' ));
  54. });
  55.  
  56. it( 'a movie can be deleted from it\'s page', () => {
  57. request( server )
  58. .delete( `/movies/${movieId}` )
  59. .expect( 200 )
  60. .then( response => expect( response.text ).to.equal( 'CasaBlanca has been deleted' ));
  61. });
  62.  
  63. it( 'a movie can be deleted from the main movies page', () => {
  64. request( server )
  65. .delete( '/movies' )
  66. .send({ id: movieId2 })
  67. .expect( 200 )
  68. .then( response => expect( response.text ).to.equal( 'X men has been deleted' ));
  69. });
  70. });
  71. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement