import { expect } from 'chai'; import { PersonalisedToken } from '../../../src/models/personalised-token'; describe('PersonalisedToken', () => { const tokenData = { id: 'tokenId', creationDateTime: '2019-05-30T11:10:55.132Z', emailAddress: 'example@ft.com', accessLicenceId: 'accessLicenceId', externalUserId: 'ext.user.id', }; const personalisedToken = new PersonalisedToken(tokenData); describe('on initialise', () => { it('sets this.id', () => { expect(personalisedToken.id).to.eql(tokenData.id); }); it('sets this.creationDateTime', () => { expect(personalisedToken.creationDateTime).to.eql(tokenData.creationDateTime); }); it('sets this.accessLicenceId', () => { expect(personalisedToken.accessLicenceId).to.equal(tokenData.accessLicenceId); }); it('sets this.emailAddress', () => { expect(personalisedToken.emailAddress).to.eql(tokenData.emailAddress); }); it('sets this.externalUserId', () => { expect(personalisedToken.externalUserId).to.eql(tokenData.externalUserId); }); }); describe('#isValidToken', () => { it('is true', () => { expect(personalisedToken.isValid()).to.be.true; }); }); describe('#matchesEmail', () => { it('should be true if the email matches the email provided ', () => { expect(personalisedToken.matchesEmail(tokenData.emailAddress)).to.be.true; }); it('should be false if the email doesn’t match the email provided ', () => { expect(personalisedToken.matchesEmail('invalidemail@ft.com')).to.be.false; }); it('should trim any whitespace around the email before matching', () => { const emailToMatch = ` ${tokenData.emailAddress} `; expect(personalisedToken.matchesEmail(emailToMatch)).to.be.true; }); it('should be case insensitive in matching the emails', () => { const emailToMatch = tokenData.emailAddress.toUpperCase(); expect(personalisedToken.matchesEmail(emailToMatch)).to.be.true; }); }); });