Skip to content
This repository was archived by the owner on Aug 29, 2018. It is now read-only.

Commit 3997654

Browse files
committed
Update the sinon stub to handle more cases.
1 parent 7260a66 commit 3997654

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

test/verifier.test.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ describe('Verifier', () => {
2525
};
2626

2727
service = {
28-
find: sinon.stub().returns(Promise.resolve([user]))
28+
find () {}
2929
};
3030

31+
sinon.stub(service, "find", function (params) {
32+
return new Promise((resolve, reject) => {
33+
const { email } = params && params.query
34+
if (email === 'nonexistinguser@gmail.com') {
35+
return resolve([])
36+
}
37+
return resolve([user])
38+
})
39+
});
40+
3141
app.use('users', service)
3242
.configure(authentication({ secret: 'supersecret' }));
3343

@@ -185,7 +195,7 @@ describe('Verifier', () => {
185195
});
186196
});
187197

188-
it('handles false rejections in promise chain', () => {
198+
it('handles false rejections in promise chain', (done) => {
189199
verifier._normalizeResult = () => Promise.reject(false);
190200
verifier.verify({}, user.email, 'admin', (error, entity) => {
191201
expect(error).to.equal(null);
@@ -194,7 +204,7 @@ describe('Verifier', () => {
194204
});
195205
});
196206

197-
it('returns errors', () => {
207+
it('returns errors', (done) => {
198208
const authError = new Error('An error');
199209
verifier._normalizeResult = () => Promise.reject(authError);
200210
verifier.verify({}, user.email, 'admin', (error, entity) => {

0 commit comments

Comments
 (0)