d1bd8dfd62ddd03b7c6d099e9c3d33b50e07b75b
[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             isProcessing: false,
20             selectedCluster: undefined,
21             targetUserToken: undefined,
22             userToLink: undefined,
23             userToLinkToken: undefined,
24             originatingUser: OriginatingUser.NONE,
25             error: LinkAccountPanelError.NONE,
26             status: LinkAccountPanelStatus.INITIAL
27         });
28     });
29
30     it('handles loaded link account state', () => {
31         const targetUser = { } as any;
32         targetUser.username = "targetUser";
33         const targetUserToken = "targettoken";
34
35         const userToLink = { } as any;
36         userToLink.username = "userToLink";
37         const userToLinkToken = "usertoken";
38
39         const originatingUser = OriginatingUser.TARGET_USER;
40
41         const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_LOAD({
42             originatingUser, targetUser, targetUserToken, userToLink, userToLinkToken}));
43         expect(state).toEqual({
44             targetUser,
45             targetUserToken,
46             isProcessing: false,
47             selectedCluster: undefined,
48             userToLink,
49             userToLinkToken,
50             originatingUser: OriginatingUser.TARGET_USER,
51             error: LinkAccountPanelError.NONE,
52             status: LinkAccountPanelStatus.LINKING
53         });
54     });
55
56     it('handles loaded invalid account state', () => {
57         const targetUser = { } as any;
58         targetUser.username = "targetUser";
59
60         const userToLink = { } as any;
61         userToLink.username = "userToLink";
62
63         const originatingUser = OriginatingUser.TARGET_USER;
64         const error = LinkAccountPanelError.NON_ADMIN;
65
66         const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_INVALID({targetUser, userToLink, originatingUser, error}));
67         expect(state).toEqual({
68             targetUser,
69             targetUserToken: undefined,
70             isProcessing: false,
71             selectedCluster: undefined,
72             userToLink,
73             userToLinkToken: undefined,
74             originatingUser: OriginatingUser.TARGET_USER,
75             error: LinkAccountPanelError.NON_ADMIN,
76             status: LinkAccountPanelStatus.ERROR
77         });
78     });
79 });