imageDimensionsTest.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var should = require('chai').should();
  2. var imageDimensions = require('../../lib/tools/redownload/imageDimensions');
  3. var fs = require('fs');
  4. var path = require('path');
  5. describe('imageDimensions', function() {
  6. it('should detect png image dimensions', function(done) {
  7. var fileContent = fs.readFileSync(path.resolve(__dirname, '../www/png-image.png'));
  8. var entry = {
  9. method: 'GET',
  10. url: 'http://localhost:8388/an-image.png',
  11. requestHeaders: {
  12. 'User-Agent': 'something',
  13. Referer: 'http://www.google.fr/',
  14. Accept: '*/*',
  15. 'Accept-Encoding': 'gzip, deflate'
  16. },
  17. status: 200,
  18. isImage: true,
  19. type: 'image',
  20. contentType: 'image/png',
  21. contentLength: 999,
  22. weightCheck: {
  23. bodyBuffer: fileContent,
  24. totalWeight: 999,
  25. headersSize: 200,
  26. bodySize: 999,
  27. isCompressed: false,
  28. uncompressedSize: 999
  29. }
  30. };
  31. imageDimensions.getDimensions(entry)
  32. .then(function(newEntry) {
  33. newEntry.should.have.a.property('imageDimensions');
  34. newEntry.imageDimensions.should.have.a.property('width').that.equals(664);
  35. newEntry.imageDimensions.should.have.a.property('height').that.equals(314);
  36. done();
  37. })
  38. .fail(function(err) {
  39. done(err);
  40. });
  41. });
  42. it('should detect a jpg image dimensions', function(done) {
  43. var fileContent = fs.readFileSync(path.resolve(__dirname, '../www/jpeg-image.jpg'));
  44. var entry = {
  45. method: 'GET',
  46. url: 'http://localhost:8388/an-image.jpg',
  47. requestHeaders: {
  48. 'User-Agent': 'something',
  49. Referer: 'http://www.google.fr/',
  50. Accept: '*/*',
  51. 'Accept-Encoding': 'gzip, deflate'
  52. },
  53. status: 200,
  54. isImage: true,
  55. type: 'image',
  56. contentType: 'image/jpeg',
  57. contentLength: 999,
  58. weightCheck: {
  59. bodyBuffer: fileContent,
  60. totalWeight: 999,
  61. headersSize: 200,
  62. bodySize: 999,
  63. isCompressed: false,
  64. uncompressedSize: 999
  65. }
  66. };
  67. imageDimensions.getDimensions(entry)
  68. .then(function(newEntry) {
  69. newEntry.should.have.a.property('imageDimensions');
  70. newEntry.imageDimensions.should.have.a.property('width').that.equals(285);
  71. newEntry.imageDimensions.should.have.a.property('height').that.equals(427);
  72. done();
  73. })
  74. .fail(function(err) {
  75. done(err);
  76. });
  77. });
  78. });