15814: Now handles secret inputs properly.
[arvados.git] / services / workbench2 / src / models / user.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { User, getUserDisplayName } from './user';
6
7 describe('User', () => {
8     it('gets the user display name', () => {
9         type UserCase = {
10             caseName: string;
11             withEmail?: boolean;
12             user: User;
13             expect: string;
14         };
15         const testCases: UserCase[] = [
16             {
17                 caseName: 'Full data available',
18                 user: {
19                     email: 'someuser@example.com', username: 'someuser',
20                     firstName: 'Some', lastName: 'User',
21                     uuid: 'zzzzz-tpzed-someusersuuid',
22                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
23                     prefs: {}, isAdmin: false, isActive: true,
24                     canWrite: false, canManage: false,
25                 },
26                 expect: 'Some User'
27             },
28             {
29                 caseName: 'Full data available (with email)',
30                 withEmail: true,
31                 user: {
32                     email: 'someuser@example.com', username: 'someuser',
33                     firstName: 'Some', lastName: 'User',
34                     uuid: 'zzzzz-tpzed-someusersuuid',
35                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
36                     prefs: {}, isAdmin: false, isActive: true,
37                     canWrite: false, canManage: false
38                 },
39                 expect: 'Some User <someuser@example.com>'
40             },
41             {
42                 caseName: 'Missing first name',
43                 user: {
44                     email: 'someuser@example.com', username: 'someuser',
45                     firstName: '', lastName: 'User',
46                     uuid: 'zzzzz-tpzed-someusersuuid',
47                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
48                     prefs: {}, isAdmin: false, isActive: true,
49                     canWrite: false, canManage: false,
50
51                 },
52                 expect: 'someuser@example.com'
53             },
54             {
55                 caseName: 'Missing last name',
56                 user: {
57                     email: 'someuser@example.com', username: 'someuser',
58                     firstName: 'Some', lastName: '',
59                     uuid: 'zzzzz-tpzed-someusersuuid',
60                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
61                     prefs: {}, isAdmin: false, isActive: true,
62                     canWrite: false, canManage: false,
63                 },
64                 expect: 'someuser@example.com'
65             },
66             {
67                 caseName: 'Missing first & last names',
68                 user: {
69                     email: 'someuser@example.com', username: 'someuser',
70                     firstName: '', lastName: '',
71                     uuid: 'zzzzz-tpzed-someusersuuid',
72                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
73                     prefs: {}, isAdmin: false, isActive: true,
74                     canWrite: false, canManage: false,
75                 },
76                 expect: 'someuser@example.com'
77             },
78             {
79                 caseName: 'Missing first & last names (with email)',
80                 withEmail: true,
81                 user: {
82                     email: 'someuser@example.com', username: 'someuser',
83                     firstName: '', lastName: '',
84                     uuid: 'zzzzz-tpzed-someusersuuid',
85                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
86                     prefs: {}, isAdmin: false, isActive: true,
87                     canWrite: false, canManage: false,
88                 },
89                 expect: 'someuser@example.com'
90             },
91             {
92                 caseName: 'Missing first & last names, and email address',
93                 user: {
94                     email: '', username: 'someuser',
95                     firstName: '', lastName: '',
96                     uuid: 'zzzzz-tpzed-someusersuuid',
97                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
98                     prefs: {}, isAdmin: false, isActive: true,
99                     canWrite: false, canManage: false,
100                 },
101                 expect: 'someuser'
102             },
103             {
104                 caseName: 'Missing first & last names, and email address (with email)',
105                 withEmail: true,
106                 user: {
107                     email: '', username: 'someuser',
108                     firstName: '', lastName: '',
109                     uuid: 'zzzzz-tpzed-someusersuuid',
110                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
111                     prefs: {}, isAdmin: false, isActive: true,
112                     canWrite: false, canManage: false,
113                 },
114                 expect: 'someuser'
115             },
116             {
117                 caseName: 'Missing all data (should not happen)',
118                 user: {
119                     email: '', username: '',
120                     firstName: '', lastName: '',
121                     uuid: 'zzzzz-tpzed-someusersuuid',
122                     ownerUuid: 'zzzzz-tpzed-someusersowneruuid',
123                     prefs: {}, isAdmin: false, isActive: true,
124                     canWrite: false, canManage: false,
125                 },
126                 expect: 'zzzzz-tpzed-someusersuuid'
127             },
128         ];
129         testCases.forEach(c => {
130             const dispName = getUserDisplayName(c.user, c.withEmail);
131             expect(dispName).toEqual(c.expect);
132         })
133     });
134 });