From e6dcde60804e7fdd6b09fd363341ecec8b11e1f1 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Thu, 1 Apr 2021 14:38:50 -0400 Subject: [PATCH] refactor(passport): Refactored passport lib and tests --- test/unit/biz-logic/a05-passport.lib-unit.js | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/unit/biz-logic/a05-passport.lib-unit.js diff --git a/test/unit/biz-logic/a05-passport.lib-unit.js b/test/unit/biz-logic/a05-passport.lib-unit.js new file mode 100644 index 0000000..a7d3e51 --- /dev/null +++ b/test/unit/biz-logic/a05-passport.lib-unit.js @@ -0,0 +1,46 @@ +const assert = require('chai').assert +const PassportLib = require('../../../src/lib/passport') + +const sinon = require('sinon') + +let uut +let sandbox + +describe('#passport.js', () => { + beforeEach(() => { + uut = new PassportLib() + + sandbox = sinon.createSandbox() + }) + + afterEach(() => sandbox.restore()) + + describe('authUser()', () => { + it('should throw error if ctx is not provided', async () => { + try { + await uut.authUser() + assert(false, 'Unexpected result') + } catch (err) { + assert.include(err.message, 'ctx is required') + } + }) + + it('Should throw error if the passport library fails', async () => { + try { + const error = new Error('cant auth user') + const user = null + + // Mock calls + // https://sinonjs.org/releases/latest/stubs/ + // About yields + sandbox.stub(uut.passport, 'authenticate').yields(error, user) + + const ctx = {} + await uut.authUser(ctx) + assert(false, 'Unexpected result') + } catch (err) { + assert.include(err.message, 'cant auth user') + } + }) + }) +})