Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. // Is there something like this?
  2. const RequestTest = require('should-request-test');
  3.  
  4. describe('Starting controller testing', () => {
  5. // calling the express app
  6. const server = require('src/index');
  7. // controller endpoint
  8. const endpoint = '/api/v1/myResource';
  9.  
  10. const requestTest;
  11.  
  12. before((done) => {
  13. const token = getToken();
  14. // send the same header on all petitions
  15. requestTest = new RequestTest({
  16. server,
  17. endpoint,
  18. headers: {
  19. Authorization: `Bearer ${token}`,
  20. 'Content-Type': 'application/json',
  21. },
  22. });
  23. });
  24.  
  25. // all set up and now I just need to send body and test for the response
  26. // done() could be called after the it callback, like a wrapper
  27. it('POST a record', () => {
  28. requestTest.post(
  29. // body of the request
  30. {
  31. number: 123,
  32. name: 'my sample name',
  33. },
  34. // response callback
  35. (res) => {
  36. should(res.status).be.eql(201);
  37. should(res.body).have.property('name', 'my sample name');
  38. should(res.body).have.property('number', 123);
  39. },
  40. );
  41. });
  42.  
  43. it('PUT a record with query and body', () => {
  44. requestTest.put(
  45. '1',
  46. // body of the request
  47. {
  48. number: 123,
  49. name: 'my sample name',
  50. },
  51. // response callback
  52. (res) => {
  53. should(res.status).be.eql(200);
  54. should(res.body).have.property('name', 'my sample name');
  55. should(res.body).have.property('number', 123);
  56. },
  57. );
  58. });
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement