Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var test = require('tape');
  4. var request = require('supertest');
  5. var app = require('../server');
  6.  
  7. test('First test!', function (t) {
  8.   t.end();
  9. });
  10.  
  11. var movies = [
  12.     {
  13.         id: 1,
  14.         title: "szia",
  15.         releaseDate: 2003,
  16.         actors: ["asd", "asd2"]
  17.     },
  18.     {
  19.         id: 2,
  20.         title: "cso",
  21.         releaseDate: 2005,
  22.         actors: ["asd3", "asd4", "asd"]
  23.     },
  24.     {
  25.         id: 3,
  26.         title: "hali",
  27.         releaseDate: 2010,
  28.         actors: ["asd3", "asd2"]
  29.     },
  30.     {
  31.         id: 4,
  32.         title: "mizu",
  33.         releaseDate: 2001,
  34.         actors: ["asd"]
  35.     },
  36. ]
  37.  
  38. test('asd1', function (t) {
  39.     request(app)
  40.       .get('/api/movies')
  41.       .expect('Content-Type', /json/)
  42.       .expect(200)
  43.       .end(function (err, res) {
  44.  
  45.  
  46.         t.error(err, 'No error');
  47.         t.same(res.body, movies, 'All movies as expected');
  48.         t.end();
  49.       });
  50. });
  51.  
  52. test('asd2', function (t) {
  53.     var movie = {
  54.         id: 1,
  55.         title: "szia",
  56.         releaseDate: 2003,
  57.         actors: ["asd", "asd2"]
  58.     }
  59.  
  60.     request(app)
  61.       .get('/api/movies/1')
  62.       .expect('Content-Type', /json/)
  63.       .expect(200)
  64.       .end(function (err, res) {
  65.         t.error(err, 'No error');
  66.         t.same(res.body, movie, 'Movie 1 as expected');
  67.         t.end();
  68.       });
  69. });
  70.  
  71. test('asd3', function (t) {
  72.     request(app)
  73.       .get('/api/movies/5')
  74.       .expect('Content-Type', /json/)
  75.       .expect(403)
  76.       .end(function (err, res) {
  77.         t.error(err, 'No error');
  78.         t.same(res.body, {error: "No movie with this ID"}, 'Movie 5 as expected');
  79.         t.end();
  80.       });
  81. });
  82.  
  83. test('asd4', function (t) {
  84.     var movie = [{
  85.         id: 3,
  86.         title: "hali",
  87.         releaseDate: 2010,
  88.         actors: ["asd3", "asd2"]
  89.     }]
  90.  
  91.     request(app)
  92.       .get('/api/movies')
  93.       .query({ release: 2010})
  94.       .expect('Content-Type', /json/)
  95.       .expect(200)
  96.       .end(function (err, res) {
  97.         t.error(err, 'No error');
  98.         t.same(res.body, movie, 'Movie 2010 as expected');
  99.         t.end();
  100.       });
  101. });
  102.  
  103. test('asd5', function (t) {
  104.     request(app)
  105.       .get('/api/movies')
  106.       .query({ release: 2009})
  107.       .expect('Content-Type', /json/)
  108.       .expect(200)
  109.       .end(function (err, res) {
  110.         t.error(err, 'No error');
  111.         t.same(res.body, [], 'Movie 2009 as expected');
  112.         t.end();
  113.       });
  114. });
  115.  
  116. test('asd6', function (t) {
  117.     request(app)
  118.       .post('/api/movies')
  119.       .send({
  120.         title: "szervusz",
  121.         releaseDate: 2019,
  122.         actors: []
  123.       })
  124.       .expect('Content-Type', /json/)
  125.       .expect(200)
  126.       .end(function (err, res) {
  127.         t.error(err, 'No error');
  128.         t.same(res.body, {id: 5}, 'Movie szervusz as expected');
  129.         t.end();
  130.       });
  131. });
  132.  
  133. test('asd6', function (t) {
  134.     request(app)
  135.       .post('/api/movies')
  136.       .send({
  137.         asdsada: "szervusz",
  138.         asdasdas: []
  139.       })
  140.       .expect('Content-Type', /json/)
  141.       .expect(403)
  142.       .end(function (err, res) {
  143.         t.error(err, 'No error');
  144.         t.same(res.body, {error: "Body sucks!"}, 'Movie szervusz as expected');
  145.         t.end();
  146.       });
  147. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement