From 1b98d17608f4c53a1d4d7c6a4c939167769d82b2 Mon Sep 17 00:00:00 2001 From: "denys.oblohin" Date: Tue, 14 Sep 2021 22:30:30 +0300 Subject: [PATCH] add test --- test/unit/callback.spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/unit/callback.spec.js b/test/unit/callback.spec.js index b180db6..5d7f2c6 100644 --- a/test/unit/callback.spec.js +++ b/test/unit/callback.spec.js @@ -165,6 +165,34 @@ describe('callback', () => { }); }); + it('handles a callback with custom handler', async () => { + await bootstrap({ + routes: { + loginCallback: { + afterCallback: '/profile', + handler: (_req, _res, next) => { + next(); + } + } + } + }); + mockToken(); + return new Promise((resolve, reject) => { + agent + .get('/authorization-code/callback') + .query({ state, code: 'foo' }) + .set('Accept', 'application/json') + .expect(302) + .end(function(err, res){ + if (err) return reject(err); + expect(res.headers.location).toBe('/profile'); + expect(mocks.authenticate).toHaveBeenCalledWith(expect.any(Object), expect.any(Object)); + expect(mocks.validateIdToken).toHaveBeenCalledWith({ id_token: idToken }, nonce, 'token', undefined); + resolve() + }); + }); + }); + it('respects the "timeout" option when making a call to /token', async () => { jest.useFakeTimers(); const timeout = 30000; // should be greater than test timeout