@@ -5,178 +5,208 @@ import { UsersApiClient } from './users-api-client';
5
5
import { UsersApiRow } from './users-api-row' ;
6
6
7
7
describe ( 'UsersApiClient' , ( ) => {
8
- let sut : UsersApiClient ;
9
-
10
- let apiClient ;
11
- let apiClientResponse ;
12
- let companyId ;
13
- let database ;
14
- let fakeFormData ;
15
- let rows ;
16
-
17
- beforeEach ( ( ) => {
18
- companyId = 123 ;
19
- database = 'zzz' ;
20
- rows = [ new UsersApiRow ( 1 , 'x' , 1 , 'y' , 'z' , 1 , 1 , 'a' , 'b' ) ] ;
21
- fakeFormData = createFakeFormData ( ) ;
22
- apiClientResponse = createFakeResponseBody ( 200 , rows ) ;
23
- apiClient = createFakeBugSplatApiClient ( fakeFormData , apiClientResponse ) ;
24
-
25
- sut = new UsersApiClient ( apiClient ) ;
26
- } ) ;
27
-
28
- describe ( 'getUsers' , ( ) => {
29
- let result ;
30
- let request ;
31
-
32
- beforeEach ( async ( ) => {
33
- request = { database } ;
34
- result = await sut . getUsers ( request ) ;
35
- } ) ;
36
-
37
- it ( 'should throw if both database and companyId are specified' , async ( ) => {
38
- request = { database, companyId : 1 } ;
39
- await expectAsync ( sut . getUsers ( request ) ) . toBeRejectedWithError ( 'Cannot specify both database and companyId' ) ;
40
- } ) ;
8
+ let sut : UsersApiClient ;
9
+
10
+ let apiClient ;
11
+ let apiClientResponse ;
12
+ let companyId ;
13
+ let database ;
14
+ let fakeFormData ;
15
+ let rows ;
16
+
17
+ beforeEach ( ( ) => {
18
+ companyId = 123 ;
19
+ database = 'zzz' ;
20
+ rows = [ new UsersApiRow ( 1 , 'x' , 1 , 'y' , 'z' , 1 , 1 , 'a' , 'b' ) ] ;
21
+ fakeFormData = createFakeFormData ( ) ;
22
+ apiClientResponse = createFakeResponseBody ( 200 , rows ) ;
23
+ apiClient = createFakeBugSplatApiClient ( fakeFormData , apiClientResponse ) ;
24
+
25
+ sut = new UsersApiClient ( apiClient ) ;
26
+ } ) ;
27
+
28
+ describe ( 'getUsers' , ( ) => {
29
+ let result ;
30
+ let request ;
31
+
32
+ beforeEach ( async ( ) => {
33
+ request = { database } ;
34
+ result = await sut . getUsers ( request ) ;
35
+ } ) ;
41
36
42
- it ( 'should throw if neither database nor companyId are specified' , async ( ) => {
43
- request = { } ;
44
- await expectAsync ( sut . getUsers ( request ) ) . toBeRejectedWithError ( 'Must specify either database or companyId' ) ;
45
- } ) ;
37
+ it ( 'should throw if both database and companyId are specified' , async ( ) => {
38
+ request = { database, companyId : 1 } ;
39
+ await expectAsync ( sut . getUsers ( request ) ) . toBeRejectedWithError (
40
+ 'Cannot specify both database and companyId'
41
+ ) ;
42
+ } ) ;
46
43
47
- it ( 'should call fetch with url containing database param' , ( ) => {
48
- expect ( apiClient . fetch ) . toHaveBeenCalledWith ( `/api/user/users.php?database=${ database } ` ) ;
49
- } ) ;
44
+ it ( 'should throw if neither database nor companyId are specified' , async ( ) => {
45
+ request = { } ;
46
+ await expectAsync ( sut . getUsers ( request ) ) . toBeRejectedWithError (
47
+ 'Must specify either database or companyId'
48
+ ) ;
49
+ } ) ;
50
50
51
- it ( 'should call fetch with url containing companyId param' , async ( ) => {
52
- request = { companyId : 1 } ;
53
- await sut . getUsers ( request ) ;
54
- expect ( apiClient . fetch ) . toHaveBeenCalledWith ( `/api/user/users.php?companyId= ${ request . companyId } ` ) ;
55
- } ) ;
51
+ it ( 'should call fetch with url containing database param' , ( ) => {
52
+ expect ( apiClient . fetch ) . toHaveBeenCalledWith (
53
+ `/api/user/users.php?database= ${ database } `
54
+ ) ;
55
+ } ) ;
56
56
57
- it ( 'should return rows from response' , ( ) => {
58
- expect ( result . rows ) . toEqual ( rows ) ;
59
- } ) ;
57
+ it ( 'should call fetch with url containing companyId param' , async ( ) => {
58
+ request = { companyId : 1 } ;
59
+ await sut . getUsers ( request ) ;
60
+ expect ( apiClient . fetch ) . toHaveBeenCalledWith (
61
+ `/api/user/users.php?companyId=${ request . companyId } `
62
+ ) ;
60
63
} ) ;
61
64
62
- describe ( 'addUserToDatabase' , ( ) => {
63
- let result ;
64
- let email ;
65
+ it ( 'should return rows from response' , ( ) => {
66
+ expect ( result . rows ) . toEqual ( rows ) ;
67
+ } ) ;
68
+ } ) ;
65
69
66
- beforeEach ( async ( ) => {
67
- email = '☕️' ;
68
- result = await sut . addUserToDatabase ( database , email ) ;
69
- } ) ;
70
+ describe ( 'addUserToDatabase' , ( ) => {
71
+ let result ;
72
+ let email ;
70
73
71
- it ( 'should call createFormData' , ( ) => {
72
- expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
73
- } ) ;
74
+ beforeEach ( async ( ) => {
75
+ email = '☕️' ;
76
+ result = await sut . addUserToDatabase ( database , email ) ;
77
+ } ) ;
74
78
75
- it ( 'should call append with database and email' , ( ) => {
76
- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'database' , database ) ;
77
- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'username' , email ) ;
78
- } ) ;
79
+ it ( 'should call createFormData' , ( ) => {
80
+ expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
81
+ } ) ;
79
82
80
- it ( 'should call fetch with url and request containing formData' , ( ) => {
81
- expect ( apiClient . fetch ) . toHaveBeenCalledWith ( '/api/user/users.php' , jasmine . objectContaining ( { method : 'POST' , body : fakeFormData } ) ) ;
82
- } ) ;
83
+ it ( 'should call append with database and email' , ( ) => {
84
+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'database' , database ) ;
85
+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'username' , email ) ;
86
+ } ) ;
83
87
84
- it ( 'should return response' , ( ) => {
85
- expect ( result ) . toEqual ( apiClientResponse ) ;
86
- } ) ;
88
+ it ( 'should call fetch with url and request containing formData' , ( ) => {
89
+ expect ( apiClient . fetch ) . toHaveBeenCalledWith (
90
+ '/api/user/users.php' ,
91
+ jasmine . objectContaining ( { method : 'POST' , body : fakeFormData } )
92
+ ) ;
87
93
} ) ;
88
94
89
- describe ( 'removeUserFromDatabase' , ( ) => {
90
- let result ;
91
- let uId ;
95
+ it ( 'should return response' , ( ) => {
96
+ expect ( result ) . toEqual ( apiClientResponse ) ;
97
+ } ) ;
98
+ } ) ;
92
99
93
- beforeEach ( async ( ) => {
94
- uId = 1 ;
95
- result = await sut . removeUserFromDatabase ( database , uId ) ;
96
- } ) ;
100
+ describe ( 'removeUserFromDatabase' , ( ) => {
101
+ let result ;
102
+ let email ;
97
103
98
- it ( 'should call fetch with url' , ( ) => {
99
- expect ( apiClient . fetch ) . toHaveBeenCalledWith ( `/api/user/users.php?database=${ database } &uId=${ uId } ` , jasmine . objectContaining ( { method : 'DELETE' } ) ) ;
100
- } ) ;
104
+ beforeEach ( async ( ) => {
105
+
106
+ result = await sut . removeUserFromDatabase ( database , email ) ;
107
+ } ) ;
101
108
102
- it ( 'should return response' , ( ) => {
103
- expect ( result ) . toEqual ( apiClientResponse ) ;
104
- } ) ;
109
+ it ( 'should call fetch with url' , ( ) => {
110
+ expect ( apiClient . fetch ) . toHaveBeenCalledWith (
111
+ `/api/user/users.php?database=${ database } &username=${ encodeURIComponent (
112
+ email
113
+ ) } `,
114
+ jasmine . objectContaining ( { method : 'DELETE' } )
115
+ ) ;
105
116
} ) ;
106
117
107
- describe ( 'updateUserForDatabase ', ( ) => {
108
- let result ;
109
- let email ;
110
- let isRestricted ;
118
+ it ( 'should return response ', ( ) => {
119
+ expect ( result ) . toEqual ( apiClientResponse ) ;
120
+ } ) ;
121
+ } ) ;
111
122
112
- beforeEach ( async ( ) => {
113
-
114
- isRestricted = true ;
115
- result = await sut . updateUserForDatabase ( database , email , isRestricted ) ;
116
- } ) ;
123
+ describe ( 'updateUserForDatabase' , ( ) => {
124
+ let result ;
125
+ let email ;
126
+ let isRestricted ;
117
127
118
- it ( 'should call createFormData' , ( ) => {
119
- expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
120
- } ) ;
128
+ beforeEach ( async ( ) => {
129
+
130
+ isRestricted = true ;
131
+ result = await sut . updateUserForDatabase ( database , email , isRestricted ) ;
132
+ } ) ;
121
133
122
- it ( 'should call append with database and email' , ( ) => {
123
- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'database' , database ) ;
124
- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'username' , email ) ;
125
- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'rights' , isRestricted ? '0' : '1' ) ;
126
- } ) ;
134
+ it ( 'should call createFormData' , ( ) => {
135
+ expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
136
+ } ) ;
127
137
128
- it ( 'should call fetch with url and request containing formData' , ( ) => {
129
- expect ( apiClient . fetch ) . toHaveBeenCalledWith ( '/api/user/users.php' , jasmine . objectContaining ( { method : 'POST' , body : fakeFormData } ) ) ;
130
- } ) ;
138
+ it ( 'should call append with database and email' , ( ) => {
139
+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'database' , database ) ;
140
+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'username' , email ) ;
141
+ expect ( fakeFormData . append ) . toHaveBeenCalledWith (
142
+ 'rights' ,
143
+ isRestricted ? '0' : '1'
144
+ ) ;
145
+ } ) ;
131
146
132
- it ( 'should return response' , ( ) => {
133
- expect ( result ) . toEqual ( apiClientResponse ) ;
134
- } ) ;
147
+ it ( 'should call fetch with url and request containing formData' , ( ) => {
148
+ expect ( apiClient . fetch ) . toHaveBeenCalledWith (
149
+ '/api/user/users.php' ,
150
+ jasmine . objectContaining ( { method : 'POST' , body : fakeFormData } )
151
+ ) ;
135
152
} ) ;
136
153
137
- describe ( 'addUserToCompany' , ( ) => {
138
- let result ;
139
- let email ;
154
+ it ( 'should return response' , ( ) => {
155
+ expect ( result ) . toEqual ( apiClientResponse ) ;
156
+ } ) ;
157
+ } ) ;
140
158
141
- beforeEach ( async ( ) => {
142
- email = '☕️' ;
143
- result = await sut . addUserToCompany ( companyId , email ) ;
144
- } ) ;
159
+ describe ( 'addUserToCompany' , ( ) => {
160
+ let result ;
161
+ let email ;
145
162
163
+ beforeEach ( async ( ) => {
164
+ email = '☕️' ;
165
+ result = await sut . addUserToCompany ( companyId , email ) ;
166
+ } ) ;
146
167
147
- it ( 'should call createFormData' , ( ) => {
148
- expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
149
- } ) ;
168
+ it ( 'should call createFormData' , ( ) => {
169
+ expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
170
+ } ) ;
150
171
151
- it ( 'should call append with companyId and email' , ( ) => {
152
- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'companyId' , `${ companyId } ` ) ;
153
- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'username' , email ) ;
154
- } ) ;
172
+ it ( 'should call append with companyId and email' , ( ) => {
173
+ expect ( fakeFormData . append ) . toHaveBeenCalledWith (
174
+ 'companyId' ,
175
+ `${ companyId } `
176
+ ) ;
177
+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'username' , email ) ;
178
+ } ) ;
155
179
156
- it ( 'should call fetch with url and request containing formData' , ( ) => {
157
- expect ( apiClient . fetch ) . toHaveBeenCalledWith ( '/api/user/users.php' , jasmine . objectContaining ( { method : 'POST' , body : fakeFormData } ) ) ;
158
- } ) ;
180
+ it ( 'should call fetch with url and request containing formData' , ( ) => {
181
+ expect ( apiClient . fetch ) . toHaveBeenCalledWith (
182
+ '/api/user/users.php' ,
183
+ jasmine . objectContaining ( { method : 'POST' , body : fakeFormData } )
184
+ ) ;
185
+ } ) ;
159
186
160
- it ( 'should return response' , ( ) => {
161
- expect ( result ) . toEqual ( apiClientResponse ) ;
162
- } ) ;
187
+ it ( 'should return response' , ( ) => {
188
+ expect ( result ) . toEqual ( apiClientResponse ) ;
163
189
} ) ;
190
+ } ) ;
164
191
165
- describe ( 'removeUserFromCompany' , ( ) => {
166
- let result ;
167
- let uId ;
192
+ describe ( 'removeUserFromCompany' , ( ) => {
193
+ let result ;
194
+ let uId ;
168
195
169
- beforeEach ( async ( ) => {
170
- uId = 1 ;
171
- result = await sut . removeUserFromCompany ( companyId , uId ) ;
172
- } ) ;
196
+ beforeEach ( async ( ) => {
197
+ uId = 1 ;
198
+ result = await sut . removeUserFromCompany ( companyId , uId ) ;
199
+ } ) ;
173
200
174
- it ( 'should call fetch with url' , ( ) => {
175
- expect ( apiClient . fetch ) . toHaveBeenCalledWith ( `/api/user/users.php?companyId=${ companyId } &uId=${ uId } ` , jasmine . objectContaining ( { method : 'DELETE' } ) ) ;
176
- } ) ;
201
+ it ( 'should call fetch with url' , ( ) => {
202
+ expect ( apiClient . fetch ) . toHaveBeenCalledWith (
203
+ `/api/user/users.php?companyId=${ companyId } &uId=${ uId } ` ,
204
+ jasmine . objectContaining ( { method : 'DELETE' } )
205
+ ) ;
206
+ } ) ;
177
207
178
- it ( 'should return response' , ( ) => {
179
- expect ( result ) . toEqual ( apiClientResponse ) ;
180
- } ) ;
208
+ it ( 'should return response' , ( ) => {
209
+ expect ( result ) . toEqual ( apiClientResponse ) ;
181
210
} ) ;
182
- } ) ;
211
+ } ) ;
212
+ } ) ;
0 commit comments