-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to accounts that are identified by email instead of username
- Loading branch information
Showing
4 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import sinon from 'sinon'; | |
import { | ||
addValidationStep, | ||
findUserByUsername, | ||
findUserByEmail, | ||
findUser, | ||
getConnectionLastLoginToken, | ||
hashLoginToken | ||
} from '../../../server/integration/accounts'; | ||
|
@@ -58,6 +60,88 @@ describe('Given findUserByUsername method', () => { | |
}); | ||
}); | ||
|
||
describe('Given findUserByEmail method', () => { | ||
const sandbox = sinon.createSandbox(); | ||
let findUserByEmailStub; | ||
|
||
beforeEach(() => { | ||
findUserByEmailStub = sandbox.stub(Accounts, 'findUserByEmail'); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('When a param is passed', () => { | ||
const sampleEmail = '[email protected]'; | ||
|
||
beforeEach(() => { | ||
findUserByEmail(sampleEmail); | ||
}); | ||
|
||
it('should pass the param to the Accounts findUserByEmail method', () => { | ||
expect(findUserByEmailStub).to.be.calledWith(sampleEmail); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Given findUser method', () => { | ||
const sandbox = sinon.createSandbox(); | ||
const sampleUsername = 'test'; | ||
const sampleEmail = '[email protected]'; | ||
let findUserByUsernameStub, findUserByEmailStub; | ||
|
||
beforeEach(() => { | ||
findUserByUsernameStub = sandbox.stub(Accounts, 'findUserByUsername'); | ||
findUserByEmailStub = sandbox.stub(Accounts, 'findUserByEmail'); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('When the record contains username and email', () => { | ||
beforeEach(() => { | ||
findUser({ username: sampleUsername, emails: [ { address: sampleEmail } ] }); | ||
}); | ||
|
||
it('should pass the username to the Accounts findUserByUsernameStub method', () => { | ||
expect(findUserByUsernameStub).to.be.calledWith(sampleUsername); | ||
}); | ||
}); | ||
|
||
describe('When the record contains only username', () => { | ||
beforeEach(() => { | ||
findUser({ username: sampleUsername }); | ||
}); | ||
|
||
it('should pass the username to the Accounts findUserByUsernameStub method', () => { | ||
expect(findUserByUsernameStub).to.be.calledWith(sampleUsername); | ||
}); | ||
}); | ||
|
||
describe('When the record contains only email', () => { | ||
beforeEach(() => { | ||
findUser({ emails: [ { address: sampleEmail } ] }); | ||
}); | ||
|
||
it('should pass the email to the Accounts findUserByEmail method', () => { | ||
expect(findUserByEmailStub).to.be.calledWith(sampleEmail); | ||
}); | ||
}); | ||
|
||
describe('When the record does not contain username or email', () => { | ||
beforeEach(() => { | ||
findUser(); | ||
}); | ||
|
||
it('should not call the Accounts methods', () => { | ||
expect(findUserByUsernameStub).to.not.be.called(); | ||
expect(findUserByEmailStub).to.not.be.called(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Given getConnectionLastLoginToken method', () => { | ||
const sandbox = sinon.createSandbox(); | ||
let _getLoginTokenStub; | ||
|
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