Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const request = require('supertest');
  2. const app = require('../server/server.js');
  3.  
  4. /**
  5.  * Make sure that the list is empty in the beginning of the application
  6.  */
  7. describe('GET /api/todo', function() {
  8.   it('returns an empty array', function(done) {
  9.     request(app)
  10.         .get('/api/todo')
  11.         .set('Accept', 'application/json')
  12.         .expect(200, [], done);
  13.   });
  14. });
  15.  
  16. /**
  17.  * Scenario:
  18.  * 1). Add a new item
  19.  * 2). Check if it is in the list
  20.  * 3). Add the same item again (should give an error)
  21.  * 4). Check if the item has not been added!
  22.  */
  23. describe('POST /api/todo/:message', function() {
  24.   it('adds the item "TodoItem" to the list', function(done) {
  25.     request(app)
  26.         .post('/api/todo/TodoItem')
  27.         .set('Accept', 'application/json')
  28.         .expect(201, done);
  29.   });
  30.  
  31.   it('should contain the item "TodoItem" in the list', function(done) {
  32.     request(app)
  33.         .get('/api/todo')
  34.         .set('Accept', 'application/json')
  35.         .expect(200, ['TodoItem'], done);
  36.   });
  37.  
  38.   it('adds duplicate item "TodoItem" to the list', function(done) {
  39.     request(app)
  40.         .post('/api/todo/TodoItem')
  41.         .set('Accept', 'application/json')
  42.         .expect(400, done);
  43.   });
  44.  
  45.   it('should just contain one "TodoItem" in the list', function(done) {
  46.     request(app)
  47.         .get('/api/todo')
  48.         .set('Accept', 'application/json')
  49.         .expect(200, ['TodoItem'], done);
  50.   });
  51. });
  52.  
  53. /**
  54.  * Scenario:
  55.  * 1). the list (should give 404)
  56.  * 2). Delete an existing itDelete an unexisting item from em from the list
  57.  * 3). Check if the item has been deleted
  58.  */
  59. describe('DELETE /api/todo/:message', function() {
  60.  
  61.   it('remove the item "TodoTest"', function(done) {
  62.     request(app)
  63.         .delete('/api/todo/TodoTest')
  64.         .set('Accept', 'application/json')
  65.         .expect(404, done);
  66.   });
  67.  
  68.   it('remove the item "TodoItem"', function(done) {
  69.     request(app)
  70.         .delete('/api/todo/TodoItem')
  71.         .set('Accept', 'application/json')
  72.         .expect(204, done);
  73.   });
  74.  
  75.   it('returns an empty array (since the previous element has been deleted)',
  76.       function(done) {
  77.         request(app)
  78.             .get('/api/todo')
  79.             .set('Accept', 'application/json')
  80.             .expect(200, [], done);
  81.       });
  82. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement