18979: Filter user vm panel request to only fetch current user login permissions
[arvados.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
8 describe('link-account-panel-reducer', () => {
9     const initialState = undefined;
10
11     it('handles initial link account state', () => {
12         const targetUser = { } as any;
13         targetUser.username = "targetUser";
14
15         const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_INIT({targetUser}));
16         expect(state).toEqual({
17             targetUser,
18             isProcessing: false,
19             selectedCluster: undefined,
20             targetUserToken: undefined,
21             userToLink: undefined,
22             userToLinkToken: undefined,
23             originatingUser: OriginatingUser.NONE,
24             error: LinkAccountPanelError.NONE,
25             status: LinkAccountPanelStatus.INITIAL
26         });
27     });
28
29     it('handles loaded link account state', () => {
30         const targetUser = { } as any;
31         targetUser.username = "targetUser";
32         const targetUserToken = "targettoken";
33
34         const userToLink = { } as any;
35         userToLink.username = "userToLink";
36         const userToLinkToken = "usertoken";
37
38         const originatingUser = OriginatingUser.TARGET_USER;
39
40         const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_LOAD({
41             originatingUser, targetUser, targetUserToken, userToLink, userToLinkToken}));
42         expect(state).toEqual({
43             targetUser,
44             targetUserToken,
45             isProcessing: false,
46             selectedCluster: undefined,
47             userToLink,
48             userToLinkToken,
49             originatingUser: OriginatingUser.TARGET_USER,
50             error: LinkAccountPanelError.NONE,
51             status: LinkAccountPanelStatus.LINKING
52         });
53     });
54
55     it('handles loaded invalid account state', () => {
56         const targetUser = { } as any;
57         targetUser.username = "targetUser";
58
59         const userToLink = { } as any;
60         userToLink.username = "userToLink";
61
62         const originatingUser = OriginatingUser.TARGET_USER;
63         const error = LinkAccountPanelError.NON_ADMIN;
64
65         const state = linkAccountPanelReducer(initialState, linkAccountPanelActions.LINK_INVALID({targetUser, userToLink, originatingUser, error}));
66         expect(state).toEqual({
67             targetUser,
68             targetUserToken: undefined,
69             isProcessing: false,
70             selectedCluster: undefined,
71             userToLink,
72             userToLinkToken: undefined,
73             originatingUser: OriginatingUser.TARGET_USER,
74             error: LinkAccountPanelError.NON_ADMIN,
75             status: LinkAccountPanelStatus.ERROR
76         });
77     });
78 });