import { expect } from 'chai'; import { ChangePassword } from '../../../src/models/change-password'; describe('ChangePasswordBody', () => { describe('reason for change', () => { context('concurrency-detected', () => { let changePassword: any; const reasonForChange = 'concurrency-detected'; beforeEach(() => { changePassword = new ChangePassword(reasonForChange); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: concurrency-detected', () => { expect(changePassword.body).to.eql({ reasonForChange: 'concurrency-detected' }); }); it('does not return a body containing a password property', () => { expect(changePassword.body).not.to.have.property('password'); }); }); context('b2b-account-created', () => { let changePassword: any; const reasonForChange = 'b2b-account-created'; beforeEach(() => { changePassword = new ChangePassword(reasonForChange); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: b2b-account-created', () => { expect(changePassword.body).to.eql({ reasonForChange: 'b2b-account-created' }); }); it('does not return a body containing a password property', () => { expect(changePassword.body).not.to.have.property('password'); }); }); context('passwordless-signup', () => { let changePassword: any; const reasonForChange = 'passwordless-signup'; beforeEach(() => { changePassword = new ChangePassword(reasonForChange); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: passwordless-signup', () => { expect(changePassword.body).to.eql({ reasonForChange: 'passwordless-signup' }); }); it('does not return a body containing a password property', () => { expect(changePassword.body).not.to.have.property('password'); }); }); context('sso-auto-link', () => { let changePassword: any; const reasonForChange = 'sso-auto-link'; beforeEach(() => { changePassword = new ChangePassword(reasonForChange); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: sso-auto-link', () => { expect(changePassword.body).to.eql({ reasonForChange: 'sso-auto-link' }); }); it('does not return a body containing a password property', () => { expect(changePassword.body).not.to.have.property('password'); }); }); context('reset-password', () => { let changePassword: any; const reasonForChange = 'reset-password'; context('using old password', () => { beforeEach(() => { changePassword = new ChangePassword(reasonForChange, 'password', 'oldPassword', undefined); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: reset-password', () => { expect(changePassword.body.reasonForChange).to.equal('reset-password'); }); it('returns a change user password body with password', () => { expect(changePassword.body.password).to.equal('password'); }); it('returns a change user password body with old password', () => { expect(changePassword.body.oldPassword).to.equal('oldPassword'); }); it('returns a change user password body with token', () => { expect(changePassword.body.token).to.equal(undefined); }); }); context('using token', () => { beforeEach(() => { changePassword = new ChangePassword(reasonForChange, 'password', undefined, 'token'); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: reset-password', () => { expect(changePassword.body.reasonForChange).to.equal('reset-password'); }); it('returns a change user password body with password', () => { expect(changePassword.body.password).to.equal('password'); }); it('returns a change user password body with old password', () => { expect(changePassword.body.oldPassword).to.equal(undefined); }); it('returns a change user password body with token', () => { expect(changePassword.body.token).to.equal('token'); }); }); it('throws an error when all the correct parameters are not given', () => { expect(() => new ChangePassword(reasonForChange)).to.throw(); }); }); context('owner-requested', () => { let changePassword: any; const reasonForChange = 'owner-requested'; context('using old password', () => { beforeEach(() => { changePassword = new ChangePassword(reasonForChange, 'password', 'oldPassword', undefined); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: owner-requested', () => { expect(changePassword.body.reasonForChange).to.equal('owner-requested'); }); it('returns a change user password body with password', () => { expect(changePassword.body.password).to.equal('password'); }); it('returns a change user password body with old password', () => { expect(changePassword.body.oldPassword).to.equal('oldPassword'); }); it('returns a change user password body with token', () => { expect(changePassword.body.token).to.equal(undefined); }); }); context('using token', () => { beforeEach(() => { changePassword = new ChangePassword(reasonForChange, 'password', undefined, 'token'); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: owner-requested', () => { expect(changePassword.body.reasonForChange).to.equal('owner-requested'); }); it('returns a change user password body with password', () => { expect(changePassword.body.password).to.equal('password'); }); it('returns a change user password body with old password', () => { expect(changePassword.body.oldPassword).to.equal(undefined); }); it('returns a change user password body with token', () => { expect(changePassword.body.token).to.equal('token'); }); }); it('throws an error when all the correct parameters are not given', () => { expect(() => new ChangePassword(reasonForChange)).to.throw(); }); }); context('masquerader-requested', () => { let changePassword: any; const reasonForChange = 'masquerader-requested'; context('using old password', () => { beforeEach(() => { changePassword = new ChangePassword(reasonForChange, 'password', 'oldPassword', undefined); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: masquerader-requested', () => { expect(changePassword.body.reasonForChange).to.equal('masquerader-requested'); }); it('returns a change user password body with password', () => { expect(changePassword.body.password).to.equal('password'); }); it('returns a change user password body with old password', () => { expect(changePassword.body.oldPassword).to.equal('oldPassword'); }); it('returns a change user password body with token', () => { expect(changePassword.body.token).to.equal(undefined); }); }); context('using token', () => { beforeEach(() => { changePassword = new ChangePassword(reasonForChange, 'password', undefined, 'token'); }); it('returns an instance of ChangePasswordBody', () => { expect(changePassword).to.be.instanceOf(ChangePassword); }); it('returns a change user password body of reasonForChange: masquerader-requested', () => { expect(changePassword.body.reasonForChange).to.equal('masquerader-requested'); }); it('returns a change user password body with password', () => { expect(changePassword.body.password).to.equal('password'); }); it('returns a change user password body with old password', () => { expect(changePassword.body.oldPassword).to.equal(undefined); }); it('returns a change user password body with token', () => { expect(changePassword.body.token).to.equal('token'); }); }); it('throws an error when all the correct parameters are not given', () => { expect(() => new ChangePassword(reasonForChange)).to.throw(); }); }); context('unknown reasonForChange', () => { it('throws an error when the reasonForChange is unknown', () => { expect(() => new ChangePassword('thisReasonDoesNotExist')).to.throw(); }); }); }); });