From: Eric Biagiotti Date: Thu, 9 May 2019 21:39:18 +0000 (-0400) Subject: 15088: Adds link account panel reducer tests X-Git-Tag: 1.4.0~1^2~17 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/d2da940fb4be60affe0a350c7f82cf91180f1e3a 15088: Adds link account panel reducer tests Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti --- diff --git a/src/store/link-account-panel/link-account-panel-reducer.test.ts b/src/store/link-account-panel/link-account-panel-reducer.test.ts new file mode 100644 index 00000000..4cb88a85 --- /dev/null +++ b/src/store/link-account-panel/link-account-panel-reducer.test.ts @@ -0,0 +1,73 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { linkAccountPanelReducer, LinkAccountPanelError, LinkAccountPanelStatus, OriginatingUser } from "~/store/link-account-panel/link-account-panel-reducer"; +import { linkAccountPanelActions } from "~/store/link-account-panel/link-account-panel-actions"; +import { UserResource } from "~/models/user"; + +describe('link-account-panel-reducer', () => { + const initialState = undefined; + + it('handles initial link account state', () => { + const targetUser = { } as any; + targetUser.username = "targetUser"; + + const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_INIT({targetUser})); + expect(state).toEqual({ + targetUser, + targetUserToken: undefined, + userToLink: undefined, + userToLinkToken: undefined, + originatingUser: OriginatingUser.NONE, + error: LinkAccountPanelError.NONE, + status: LinkAccountPanelStatus.INITIAL + }); + }); + + it('handles loaded link account state', () => { + const targetUser = { } as any; + targetUser.username = "targetUser"; + const targetUserToken = "targettoken"; + + const userToLink = { } as any; + userToLink.username = "userToLink"; + const userToLinkToken = "usertoken"; + + const originatingUser = OriginatingUser.TARGET_USER; + + const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_LOAD({ + originatingUser, targetUser, targetUserToken, userToLink, userToLinkToken})); + expect(state).toEqual({ + targetUser, + targetUserToken, + userToLink, + userToLinkToken, + originatingUser: OriginatingUser.TARGET_USER, + error: LinkAccountPanelError.NONE, + status: LinkAccountPanelStatus.LINKING + }); + }); + + it('handles loaded invalid account state', () => { + const targetUser = { } as any; + targetUser.username = "targetUser"; + + const userToLink = { } as any; + userToLink.username = "userToLink"; + + const originatingUser = OriginatingUser.TARGET_USER; + const error = LinkAccountPanelError.NON_ADMIN; + + const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_INVALID({targetUser, userToLink, originatingUser, error})); + expect(state).toEqual({ + targetUser, + targetUserToken: undefined, + userToLink, + userToLinkToken: undefined, + originatingUser: OriginatingUser.TARGET_USER, + error: LinkAccountPanelError.NON_ADMIN, + status: LinkAccountPanelStatus.ERROR + }); + }); +}); diff --git a/src/store/link-account-panel/link-account-panel-reducer.ts b/src/store/link-account-panel/link-account-panel-reducer.ts index a8533185..80878c34 100644 --- a/src/store/link-account-panel/link-account-panel-reducer.ts +++ b/src/store/link-account-panel/link-account-panel-reducer.ts @@ -36,7 +36,7 @@ export interface LinkAccountPanelState { } const initialState = { - originatingUser: undefined, + originatingUser: OriginatingUser.NONE, targetUser: undefined, targetUserToken: undefined, userToLink: undefined, @@ -49,13 +49,21 @@ export const linkAccountPanelReducer = (state: LinkAccountPanelState = initialSt linkAccountPanelActions.match(action, { default: () => state, LINK_INIT: ({ targetUser }) => ({ - ...state, targetUser, status: LinkAccountPanelStatus.INITIAL, error: LinkAccountPanelError.NONE, originatingUser: OriginatingUser.NONE + targetUser, targetUserToken: undefined, + userToLink: undefined, userToLinkToken: undefined, + status: LinkAccountPanelStatus.INITIAL, error: LinkAccountPanelError.NONE, originatingUser: OriginatingUser.NONE }), LINK_LOAD: ({ originatingUser, userToLink, targetUser, targetUserToken, userToLinkToken}) => ({ - ...state, originatingUser, targetUser, targetUserToken, userToLink, userToLinkToken, status: LinkAccountPanelStatus.LINKING, error: LinkAccountPanelError.NONE + originatingUser, + targetUser, targetUserToken, + userToLink, userToLinkToken, + status: LinkAccountPanelStatus.LINKING, error: LinkAccountPanelError.NONE }), LINK_INVALID: ({originatingUser, targetUser, userToLink, error}) => ({ - ...state, originatingUser, targetUser, userToLink, error, status: LinkAccountPanelStatus.ERROR + originatingUser, + targetUser, targetUserToken: undefined, + userToLink, userToLinkToken: undefined, + error, status: LinkAccountPanelStatus.ERROR }), HAS_SESSION_DATA: () => ({ ...state, status: LinkAccountPanelStatus.HAS_SESSION_DATA