You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.0 KiB

  1. 'use strict';
  2. const request = require('supertest');
  3. const server = require('./server');
  4. const app = server.setup();
  5. let mockUser = {
  6. firstName: 'Joe',
  7. lastName: 'Schmo',
  8. email: 'joe@mailinator.com'
  9. };
  10. let mockCars = [
  11. 'rsx',
  12. 'tsx',
  13. 'civic',
  14. 'integra'
  15. ];
  16. describe('Test Multipart Form Single Field Submissions', function() {
  17. it('submit multipart user data with POST', function(done) {
  18. request(app)
  19. .post('/fields/user')
  20. .field('firstName', mockUser.firstName)
  21. .field('lastName', mockUser.lastName)
  22. .field('email', mockUser.email)
  23. .expect('Content-Type', /json/)
  24. .expect(200, {
  25. firstName: mockUser.firstName,
  26. lastName: mockUser.lastName,
  27. email: mockUser.email
  28. }, done);
  29. });
  30. it('submit multipart user data with PUT', function(done) {
  31. request(app)
  32. .post('/fields/user')
  33. .field('firstName', mockUser.firstName)
  34. .field('lastName', mockUser.lastName)
  35. .field('email', mockUser.email)
  36. .expect('Content-Type', /json/)
  37. .expect(200, {
  38. firstName: mockUser.firstName,
  39. lastName: mockUser.lastName,
  40. email: mockUser.email
  41. }, done);
  42. });
  43. it('fail when user data submitted without multipart', function(done) {
  44. request(app)
  45. .post('/fields/user')
  46. .send(mockUser)
  47. .expect(400)
  48. .end(done);
  49. });
  50. it('fail when user data not submitted', function(done) {
  51. request(app)
  52. .post('/fields/user')
  53. .expect(400)
  54. .end(done);
  55. });
  56. });
  57. describe('Test Multipart Form Array Field Submissions', function() {
  58. it('submit array of data with POST', function(done) {
  59. let req = request(app).post('/fields/array');
  60. for (let i = 0; i < mockCars.length; i++) {
  61. req.field('testField', mockCars[i]);
  62. }
  63. req
  64. .expect(200)
  65. .end(function(err, res) {
  66. if (err) {
  67. return done(err);
  68. }
  69. let responseMatchesRequest = res.body.join(',') === mockCars.join(',');
  70. done(responseMatchesRequest ? null : 'Data was returned as expected.');
  71. });
  72. });
  73. });