two tests

This commit is contained in:
Jeffrey Sun 2017-06-13 15:27:24 -07:00
parent f2975db70f
commit 37590f21fb
2 changed files with 51 additions and 1 deletions

View file

@ -4,7 +4,7 @@
"description": "Makes Fox Faces", "description": "Makes Fox Faces",
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "mocha"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -21,9 +21,12 @@
"chance": "^1.0.4", "chance": "^1.0.4",
"express": "^4.14.0", "express": "^4.14.0",
"express-cluster": "0.0.4", "express-cluster": "0.0.4",
"mocha": "^3.4.2",
"newrelic": "^1.35.1", "newrelic": "^1.35.1",
"node-gyp": "^3.4.0", "node-gyp": "^3.4.0",
"sanitize-filename": "^1.6.1", "sanitize-filename": "^1.6.1",
"sharp": "^0.18.1",
"supertest": "^3.0.0",
"uuid": "^3.0.1" "uuid": "^3.0.1"
} }
} }

47
test/test.js Normal file
View file

@ -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()
})
})
})
})
})