diff --git a/client/lib/security-checkup/test/account-recovery-store.js b/client/lib/security-checkup/test/account-recovery-store.js index e6de365575a15..f8050b1ea107c 100644 --- a/client/lib/security-checkup/test/account-recovery-store.js +++ b/client/lib/security-checkup/test/account-recovery-store.js @@ -1,104 +1,92 @@ -require( 'lib/react-test-env-setup' )(); -require( 'lib/mixins/i18n' ).initialize(); - /** * External dependencies */ -const chai = require( 'chai' ), - expect = chai.expect, - sinon = require( 'sinon' ), - sinonChai = require( 'sinon-chai' ); - -chai.use( sinonChai ); +import { expect } from 'chai'; /** * Internal dependencies */ -const Dispatcher = require( 'dispatcher' ), - testConstants = require( './fixtures/constants' ), - undocumentedMe = require( 'lib/wpcom-undocumented/lib/me' ); +import { useSandbox } from 'test/helpers/use-sinon'; +import useI18n from 'test/helpers/use-i18n'; -describe( 'AccountRecoveryStore', function() { - var AccountRecoveryStore, sandbox, dispatchHandler; +import Dispatcher from 'dispatcher'; +import undocumentedMe from 'lib/wpcom-undocumented/lib/me'; - function dispatch( action ) { - dispatchHandler( { - action: action - } ); - } +describe( 'AccountRecoveryStore', () => { + let AccountRecoveryStore, sandbox, dispatchHandler, testConstants; - beforeEach( function() { - sandbox = sinon.sandbox.create(); + useI18n(); + + useSandbox( sandy => sandbox = sandy ); + + beforeEach( () => { + testConstants = require( './fixtures/constants' ); sandbox.spy( Dispatcher, 'register' ); sandbox.stub( undocumentedMe.prototype, 'getAccountRecovery' ) .callsArgWithAsync( 0, null, testConstants.DUMMY_ACCOUNT_RECOVERY_RESPONSE ); - delete require.cache[ require.resolve( '../account-recovery-store' ) ]; AccountRecoveryStore = require( '../account-recovery-store' ); dispatchHandler = Dispatcher.register.lastCall.args[ 0 ]; } ); - afterEach( function() { + afterEach( () => { sandbox.restore(); } ); - describe( 'getEmail()', function() { - it( 'should call the WP.com REST API on first request', function() { - var data = AccountRecoveryStore.getEmail(); + describe( 'getEmail()', () => { + it( 'should call the WP.com REST API on first request', () => { + const data = AccountRecoveryStore.getEmail(); expect( undocumentedMe.prototype.getAccountRecovery ).to.have.been.calledOnce; - expect( data ).to.eql( testConstants.DUMMY_STORE_EMAIL_OBJECT_LOADING ); } ); - it( 'should only call the WP.com REST API only once', function( done ) { + it( 'should only call the WP.com REST API only once', done => { AccountRecoveryStore.getEmail(); - process.nextTick( function() { + process.nextTick( () => { AccountRecoveryStore.getEmail(); - process.nextTick( function() { + process.nextTick( () => { expect( undocumentedMe.prototype.getAccountRecovery ).to.have.been.calledOnce; - done(); } ); } ); } ); - it( 'should return remote data', function( done ) { + it( 'should return remote data', done => { AccountRecoveryStore.getEmail(); - process.nextTick( function() { - var data = AccountRecoveryStore.getEmail(); + process.nextTick( () => { + const data = AccountRecoveryStore.getEmail(); expect( data ).to.eql( testConstants.DUMMY_STORE_EMAIL_OBJECT ); done(); } ); } ); } ); - describe( 'getPhone()', function() { - it( 'should call the WP.com REST API on first request', function() { - var data = AccountRecoveryStore.getPhone(); + describe( 'getPhone()', () => { + it( 'should call the WP.com REST API on first request', () => { + const data = AccountRecoveryStore.getPhone(); expect( undocumentedMe.prototype.getAccountRecovery ).to.have.been.calledOnce; - expect( data ).to.eql( testConstants.DUMMY_STORE_PHONE_OBJECT_LOADING ); } ); - it( 'should only call the WP.com REST API only once', function( done ) { + it( 'should only call the WP.com REST API only once', done => { AccountRecoveryStore.getPhone(); - process.nextTick( function() { + process.nextTick( () => { AccountRecoveryStore.getPhone(); - process.nextTick( function() { + process.nextTick( () => { expect( undocumentedMe.prototype.getAccountRecovery ).to.have.been.calledOnce; done(); } ); } ); } ); - it( 'should return remote data', function( done ) { + it( 'should return remote data', done => { AccountRecoveryStore.getPhone(); - process.nextTick( function() { + process.nextTick( () => { var data = AccountRecoveryStore.getPhone(); expect( data ).to.eql( testConstants.DUMMY_STORE_PHONE_OBJECT ); done(); @@ -106,34 +94,39 @@ describe( 'AccountRecoveryStore', function() { } ); } ); - describe( '.dispatchToken', function() { - it( 'should expose dispatch ID', function() { + describe( '.dispatchToken', () => { + let dispatch; + before( () => { + dispatch = action => dispatchHandler( { action } ); + } ); + + it( 'should expose dispatch ID', () => { expect( AccountRecoveryStore.dispatchToken ).to.be.a( 'string' ); } ); - it( 'should update email on UPDATE_ACCOUNT_RECOVERY_EMAIL', function() { + it( 'should update email on UPDATE_ACCOUNT_RECOVERY_EMAIL', () => { dispatch( testConstants.DISPATCH_UPDATE_ACCOUNT_RECOVERY_EMAIL ); expect( AccountRecoveryStore.getEmail() ).to.have.deep.property( 'data.email', testConstants.DUMMY_EMAIL ); } ); - it( 'should update and set notice on RECEIVE_UPDATED_ACCOUNT_RECOVERY_EMAIL', function() { + it( 'should update and set notice on RECEIVE_UPDATED_ACCOUNT_RECOVERY_EMAIL', () => { dispatch( testConstants.DISPATCH_RECEIVE_UPDATED_ACCOUNT_RECOVERY_EMAIL ); expect( AccountRecoveryStore.getEmail() ).to.have.deep.property( 'data.email', testConstants.DUMMY_EMAIL ); expect( AccountRecoveryStore.getEmail() ).to.have.property( 'lastNotice' ).that.is.an( 'object' ); } ); - it( 'should delete on DELETE_ACCOUNT_RECOVERY_EMAIL', function() { + it( 'should delete on DELETE_ACCOUNT_RECOVERY_EMAIL', () => { dispatch( testConstants.DISPATCH_DELETE_ACCOUNT_RECOVERY_EMAIL ); expect( AccountRecoveryStore.getEmail() ).to.have.deep.property( 'data.email', null ); } ); - it( 'should delete and update notice on RECEIVE_DELETED_ACCOUNT_RECOVERY_EMAIL', function() { + it( 'should delete and update notice on RECEIVE_DELETED_ACCOUNT_RECOVERY_EMAIL', () => { dispatch( testConstants.DISPATCH_RECEIVE_DELETED_ACCOUNT_RECOVERY_EMAIL ); expect( AccountRecoveryStore.getEmail() ).to.have.deep.property( 'data.email', null ); expect( AccountRecoveryStore.getEmail() ).to.have.property( 'lastNotice' ).that.is.an( 'object' ); } ); - it( 'should dismiss notice on DISMISS_ACCOUNT_RECOVERY_EMAIL_NOTICE', function() { + it( 'should dismiss notice on DISMISS_ACCOUNT_RECOVERY_EMAIL_NOTICE', () => { dispatch( testConstants.DISPATCH_RECEIVE_UPDATED_ACCOUNT_RECOVERY_EMAIL ); dispatch( testConstants.DISPATCH_DISMISS_ACCOUNT_RECOVERY_EMAIL_NOTICE ); expect( AccountRecoveryStore.getEmail() ).to.have.property( 'lastNotice' ).that.is.false;