diff --git a/package.json b/package.json index 3fed837..2386d1c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Makes Fox Faces", "main": "server.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "mocha" }, "repository": { "type": "git", @@ -21,9 +21,12 @@ "chance": "^1.0.4", "express": "^4.14.0", "express-cluster": "0.0.4", + "mocha": "^3.4.2", "newrelic": "^1.35.1", "node-gyp": "^3.4.0", "sanitize-filename": "^1.6.1", + "sharp": "^0.18.1", + "supertest": "^3.0.0", "uuid": "^3.0.1" } } diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..5523a7a --- /dev/null +++ b/test/test.js @@ -0,0 +1,47 @@ +const request = require('supertest') +const assert = require('assert') +const sharp = require('sharp') + +const app = require('../server') + +const testUID = 4125370 + +describe('Foxy-moxy', () => { + describe('fox generation', () => { + it('should respect widths < 400', (done) => { + const width = 158 + request(app) + .get(`/${width}/${testUID}`) + .expect('Content-Type', 'image/png') + .expect(200) + .end(function(err, res) { + assert(!err, String(err)) + sharp(res.body).metadata((err, metadata) => { + assert(!err, String(err)) + assert.equal(metadata.format, 'png') + assert.equal(metadata.height, width) + assert.equal(metadata.width, width) + done() + }) + }) + }) + + it('should allow max width of 400', (done) => { + const width = 510 + request(app) + .get(`/${width}/${testUID}`) + .expect('Content-Type', 'image/png') + .expect(200) + .end(function(err, res) { + assert(!err, String(err)) + sharp(res.body).metadata((err, metadata) => { + assert(!err, String(err)) + assert.equal(metadata.format, 'png') + assert.equal(metadata.height, 400) + assert.equal(metadata.width, 400) + done() + }) + }) + }) + }) +})