Skip to content

Commit 6298eed

Browse files
committed
Merge branch 'pr-74-fixes' into feature/random-endpoint
2 parents b952532 + 09eee3c commit 6298eed

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

src/routes/avatars.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import Router from 'express';
2-
import uuid from 'uuid'
2+
import uuid from 'uuid';
33

4-
import {
5-
allNames,
6-
pathFor,
7-
} from '../lib/imageFiles';
4+
import { allNames, pathFor } from '../lib/imageFiles';
85
import common from './common';
96
import { combine } from '../lib/imager';
107
import potato from '../lib/potato';
@@ -31,12 +28,6 @@ router.get('/list', function(req, res) {
3128
return res.set('Content-Type', 'application/json').send(response);
3229
});
3330

34-
router.get('/:size?/:id', function(req, res, next) {
35-
return combine(req.faceParts, req.params.size, function(err, stdout) {
36-
return common.sendImage(err, stdout, req, res, next);
37-
});
38-
});
39-
4031
router.get('/:size?/random', function(req, res) {
4132
var faceParts;
4233
faceParts = potato.parts(uuid.v4());
@@ -47,6 +38,12 @@ router.get('/:size?/random', function(req, res) {
4738
});
4839
});
4940

41+
router.get('/:size?/:id', function(req, res, next) {
42+
return combine(req.faceParts, req.params.size, function(err, stdout) {
43+
return common.sendImage(err, stdout, req, res, next);
44+
});
45+
});
46+
5047
router.get('/face/:eyes/:nose/:mouth/:color/:size?', function(req, res, next) {
5148
let faceParts = { color: '#' + req.params.color };
5249

test/integration.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,37 @@ describe('routing', function() {
7474
});
7575

7676
describe('v2 avatar random requests', function() {
77-
7877
it('can randomly generate a new avatar', function(done) {
79-
request.get('/avatars/random')
80-
.expect(200)
81-
.expect('Content-Type', /image/)
82-
.end(done);
83-
});
84-
85-
it('can randomly generate a new avatar with a custom size', function(done) {
86-
request.get('/avatars/50/random')
87-
.expect(200)
88-
.expect('Content-Type', /image/)
89-
.parse(parseImage).end(function(err, res) {
90-
im(res.body).size(function(_, size) {
91-
expect(size).to.eql({ height: 50, width: 50 });
92-
done();
78+
const getRandom = () => request
79+
.get('/avatars/random')
80+
.expect(200)
81+
.expect('Content-Type', /image/)
82+
.parse(parseImage);
83+
84+
getRandom().end((_, r1) => {
85+
getRandom().end((_, r2) => {
86+
im(r1.body).identify('%#', (_, id1) => {
87+
im(r2.body).identify('%#', (_, id2) => {
88+
expect(id1).not.to.equal(id2);
89+
done();
90+
});
91+
});
9392
});
9493
});
9594
});
9695

96+
it('supports a custom size parameter', function(done) {
97+
request
98+
.get('/avatars/50/random')
99+
.expect(200)
100+
.expect('Content-Type', /image/)
101+
.parse(parseImage)
102+
.end(function(err, res) {
103+
im(res.body).size(function(_, size) {
104+
expect(size).to.eql({ height: 50, width: 50 });
105+
done();
106+
});
107+
});
108+
});
97109
});
98-
99110
});

0 commit comments

Comments
 (0)