mimetype.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var should = require('should'),
  2. needle = require('./../'),
  3. helpers = require('./helpers');
  4. describe('receiving json and xml content as string', function() {
  5. this.timeout(5000);
  6. ["text/plain", "application/json", "application/ld+json", "application/xml", "image/svg+xml"].forEach(function(mimetype, offset){
  7. describe('Given content-type: "'+mimetype+'"', function () {
  8. var server, port = 54330+offset;
  9. before(function(done) {
  10. server = helpers.server({
  11. port: port,
  12. response: 'content',
  13. headers: { 'Content-Type': mimetype }
  14. }, done);
  15. })
  16. after(function(done) {
  17. server.close(done)
  18. })
  19. describe('with parse = false', function () {
  20. it('delivers by default as string', function (done) {
  21. needle.get('http://localhost:' + port, { parse: false }, function (err, resp) {
  22. resp.body.should.be.a.String;
  23. (typeof resp.body).should.eql('string')
  24. done();
  25. })
  26. })
  27. })
  28. })
  29. });
  30. ["application/octet-stream", "image/png"].forEach(function(mimetype, offset){
  31. describe('Given content-type: "'+mimetype+'"', function () {
  32. var server, port = 54340+offset;
  33. before(function(done) {
  34. server = helpers.server({
  35. port: port,
  36. response: 'content',
  37. headers: { 'Content-Type': mimetype }
  38. }, done);
  39. })
  40. after(function(done) {
  41. server.close(done)
  42. })
  43. describe('with parse = false', function () {
  44. it('delivers by default as Buffer', function (done) {
  45. needle.get('http://localhost:' + port, { parse: false }, function (err, resp) {
  46. resp.body.should.be.a.Buffer;
  47. (resp.body instanceof Buffer).should.eql(true)
  48. done();
  49. })
  50. })
  51. })
  52. })
  53. })
  54. })