15088: Adds link account panel reducer tests
[arvados-workbench2.git] / src / store / link-account-panel / link-account-panel-reducer.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { linkAccountPanelReducer, LinkAccountPanelError, LinkAccountPanelStatus, OriginatingUser } from "~/store/link-account-panel/link-account-panel-reducer";
6 import { linkAccountPanelActions } from "~/store/link-account-panel/link-account-panel-actions";
7 import { UserResource } from "~/models/user";
8
9 describe('link-account-panel-reducer', () => {
10     const initialState = undefined;
11
12     it('handles initial link account state', () => {
13         const targetUser = { } as any;
14         targetUser.username = "targetUser";
15
16         const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_INIT({targetUser}));
17         expect(state).toEqual({
18             targetUser,
19             targetUserToken: undefined,
20             userToLink: undefined,
21             userToLinkToken: undefined,
22             originatingUser: OriginatingUser.NONE,
23             error: LinkAccountPanelError.NONE,
24             status: LinkAccountPanelStatus.INITIAL
25         });
26     });
27
28     it('handles loaded link account state', () => {
29         const targetUser = { } as any;
30         targetUser.username = "targetUser";
31         const targetUserToken = "targettoken";
32
33         const userToLink = { } as any;
34         userToLink.username = "userToLink";
35         const userToLinkToken = "usertoken";
36
37         const originatingUser = OriginatingUser.TARGET_USER;
38
39         const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_LOAD({
40             originatingUser, targetUser, targetUserToken, userToLink, userToLinkToken}));
41         expect(state).toEqual({
42             targetUser,
43             targetUserToken,
44             userToLink,
45             userToLinkToken,
46             originatingUser: OriginatingUser.TARGET_USER,
47             error: LinkAccountPanelError.NONE,
48             status: LinkAccountPanelStatus.LINKING
49         });
50     });
51
52     it('handles loaded invalid account state', () => {
53         const targetUser = { } as any;
54         targetUser.username = "targetUser";
55
56         const userToLink = { } as any;
57         userToLink.username = "userToLink";
58
59         const originatingUser = OriginatingUser.TARGET_USER;
60         const error = LinkAccountPanelError.NON_ADMIN;
61
62         const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_INVALID({targetUser, userToLink, originatingUser, error}));
63         expect(state).toEqual({
64             targetUser,
65             targetUserToken: undefined,
66             userToLink,
67             userToLinkToken: undefined,
68             originatingUser: OriginatingUser.TARGET_USER,
69             error: LinkAccountPanelError.NON_ADMIN,
70             status: LinkAccountPanelStatus.ERROR
71         });
72     });
73 });