From 52cd433582bc759f7c08e96a9c0fbd82718cfff7 Mon Sep 17 00:00:00 2001 From: Aniko Litvanyi Date: Fri, 22 Sep 2017 13:08:38 +0200 Subject: [PATCH] [KFI]test(Login): Add tests for testing the new login buffer action and epic --- test/ActionsTests.ts | 14 ++++++++++++-- test/EpicsTests.ts | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/test/ActionsTests.ts b/test/ActionsTests.ts index e20a738..8cdd533 100644 --- a/test/ActionsTests.ts +++ b/test/ActionsTests.ts @@ -475,11 +475,12 @@ describe('Actions', () => { expect(Actions.UserLogin('alba', 'alba')).to.deep.equal(expectedAction) }); it('should create an action to a user login success', () => { + const user = Content.Create({ Name: 'alba' }, ContentTypes.User, repo) const expectedAction = { type: 'USER_LOGIN_SUCCESS', - response: true + response: user } - expect(Actions.UserLoginSuccess(true)).to.deep.equal(expectedAction) + expect(Actions.UserLoginSuccess(user)).to.deep.equal(expectedAction) }); it('should create an action to a user login failure', () => { const expectedAction = { @@ -496,6 +497,15 @@ describe('Actions', () => { expect(Actions.UserLoginFailure({ message: 'The username or the password is not valid!', status: 403 })).to.deep.equal(expectedAction) }); }); + describe('UserLoginBuffer', () => { + it('should create an action to a user login buffering', () => { + const expectedAction = { + type: 'USER_LOGIN_BUFFER', + response: true + } + expect(Actions.UserLoginBuffer(true)).to.deep.equal(expectedAction) + }); + }); describe('UserLogout', () => { it('should create an action to a user logout request', () => { const expectedAction = { diff --git a/test/EpicsTests.ts b/test/EpicsTests.ts index 666060d..9b352d8 100644 --- a/test/EpicsTests.ts +++ b/test/EpicsTests.ts @@ -631,7 +631,7 @@ describe('Epics', () => { response: user }, { type: 'CHECK_LOGIN_STATE_REQUEST' }, - { type: 'USER_LOGIN_SUCCESS', response: 2 }]); + { type: 'USER_LOGIN_BUFFER', response: true }]); }) it('handles an error', () => { (repo.Authentication as Mocks.MockAuthService).stateSubject.next(Authentication.LoginState.Unauthenticated); @@ -724,4 +724,23 @@ describe('Epics', () => { { type: 'LOAD_CONTENT_ACTIONS_FAILURE', error: 'error' }]); }) }); + describe('userLoginBufferEpic Epic', () => { + let store; + const epicMiddleware = createEpicMiddleware(Epics.userLoginBufferEpic, { dependencies: { repository: repo } }); + const mockStore = configureMockStore([epicMiddleware]); + + before(() => { + store = mockStore(); + }); + + after(() => { + epicMiddleware.replaceEpic(Epics.userLoginBufferEpic); + }); + it('handles the success', () => { + store.dispatch({ type: 'USER_LOGIN_BUFFER', response: true }); + console.log(store.getActions()) + expect(store.getActions()).to.be.deep.eq( + [ { type: 'USER_LOGIN_BUFFER', response: true } ]); + }) + }) }); \ No newline at end of file