Skip to content

Commit 891cbf1

Browse files
rylndJackymancs4
authored andcommitted
Update test to assert randomness
If we're not asserting that we get a different image on subsequent calls to the random endpoint, we're not really testing the random endpoint; the previous tests would pass without the random endpoint existing. Uses imagemagick's identify function to get a consistent hash of the image from the inconsistent binary buffer.
1 parent b952532 commit 891cbf1

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

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)