express.post.cookies.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. let Express = require('express')
  2. let request = require('../index');
  3. let assert = require('assert');
  4. let bodyParser = require('body-parser')
  5. var cookieParser = require('cookie-parser')
  6. const app = Express();
  7. const port = 3006;
  8. let server;
  9. describe('/POST-Cookies', function() {
  10. before(function() {
  11. server = app.listen(port, () => {
  12. ''
  13. console.log("Test are running on port : " + port);
  14. app.use(cookieParser())
  15. app.post("/", function(req, res) {
  16. res.append('Content-Type', 'text/html');
  17. res.append('authorization', req.headers.authorization || "");
  18. res.send(req.query)
  19. })
  20. app.post('/cookies', function(req, res) {
  21. res.cookie('john', 'doe')
  22. res.cookie('human', 'true')
  23. res.send('')
  24. })
  25. app.post('/cookies-redirect', function(req, res) {
  26. res.redirect('/cookies')
  27. })
  28. });
  29. });
  30. describe('/cookies', function() {
  31. it("should send me back the cookies", function(done) {
  32. request.request({ url: "http://localhost:3006/cookies",
  33. method: 'POST',
  34. Cookies: { john: "doe", human: true },
  35. }
  36. , function(err, data, status, headers) {
  37. assert.deepEqual(headers['set-cookie'], [ 'john=doe; Path=/', 'human=true; Path=/' ]);
  38. assert.equal(200, status);
  39. done();
  40. });
  41. });
  42. });
  43. after(function() {
  44. server.close();
  45. });
  46. });