Created
February 22, 2020 05:42
-
-
Save sj82516/4181f3c41a70f95b9ea42c0573ce9dcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const expect = require('chai').expect; | |
const sinon = require('sinon'); | |
const UserManager = require('../../user/user.manager'); | |
describe('userManger', () => { | |
let userManager = null; | |
let sandbox = sinon.createSandbox(); | |
const findUserStub = sandbox.stub(); | |
const fakeDB = { | |
collection: sinon.fake.returns({ | |
findOne: findUserStub | |
}) | |
} | |
before(() => { | |
userManager = new UserManager(fakeDB); | |
expect(fakeDB.collection.args[0][0]).to.be.equal('user'); | |
expect(fakeDB.collection.calledOnce).to.be.equal(true); | |
}) | |
afterEach(()=>{ | |
sandbox.restore(); | |
}) | |
describe('findUser', () => { | |
it('find existed user', async () => { | |
const account = "test"; | |
const password = "test"; | |
const otherProp = "test"; | |
findUserStub.returns({ | |
account, | |
password, | |
otherProp | |
}) | |
const user = await userManager.findUser({ | |
account, | |
password | |
}) | |
expect(user).to.deep.equal({ | |
account, | |
password, | |
otherProp | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment