@@ -5,178 +5,208 @@ import { UsersApiClient } from './users-api-client';
55import { UsersApiRow } from './users-api-row' ;
66
77describe ( '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+ } ) ;
4136
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+ } ) ;
4643
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+ } ) ;
5050
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+ } ) ;
5656
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+ ) ;
6063 } ) ;
6164
62- describe ( 'addUserToDatabase' , ( ) => {
63- let result ;
64- let email ;
65+ it ( 'should return rows from response' , ( ) => {
66+ expect ( result . rows ) . toEqual ( rows ) ;
67+ } ) ;
68+ } ) ;
6569
66- beforeEach ( async ( ) => {
67- email = '☕️' ;
68- result = await sut . addUserToDatabase ( database , email ) ;
69- } ) ;
70+ describe ( 'addUserToDatabase' , ( ) => {
71+ let result ;
72+ let email ;
7073
71- it ( 'should call createFormData' , ( ) => {
72- expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
73- } ) ;
74+ beforeEach ( async ( ) => {
75+ email = '☕️' ;
76+ result = await sut . addUserToDatabase ( database , email ) ;
77+ } ) ;
7478
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+ } ) ;
7982
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+ } ) ;
8387
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+ ) ;
8793 } ) ;
8894
89- describe ( 'removeUserFromDatabase' , ( ) => {
90- let result ;
91- let uId ;
95+ it ( 'should return response' , ( ) => {
96+ expect ( result ) . toEqual ( apiClientResponse ) ;
97+ } ) ;
98+ } ) ;
9299
93- beforeEach ( async ( ) => {
94- uId = 1 ;
95- result = await sut . removeUserFromDatabase ( database , uId ) ;
96- } ) ;
100+ describe ( 'removeUserFromDatabase' , ( ) => {
101+ let result ;
102+ let email ;
97103
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+ email = 'test@bugsplat.com' ;
106+ result = await sut . removeUserFromDatabase ( database , email ) ;
107+ } ) ;
101108
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+ ) ;
105116 } ) ;
106117
107- describe ( 'updateUserForDatabase ', ( ) => {
108- let result ;
109- let email ;
110- let isRestricted ;
118+ it ( 'should return response ', ( ) => {
119+ expect ( result ) . toEqual ( apiClientResponse ) ;
120+ } ) ;
121+ } ) ;
111122
112- beforeEach ( async ( ) => {
113- email = 'fred@bugsplat.com' ;
114- isRestricted = true ;
115- result = await sut . updateUserForDatabase ( database , email , isRestricted ) ;
116- } ) ;
123+ describe ( 'updateUserForDatabase' , ( ) => {
124+ let result ;
125+ let email ;
126+ let isRestricted ;
117127
118- it ( 'should call createFormData' , ( ) => {
119- expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
120- } ) ;
128+ beforeEach ( async ( ) => {
129+ email = 'fred@bugsplat.com' ;
130+ isRestricted = true ;
131+ result = await sut . updateUserForDatabase ( database , email , isRestricted ) ;
132+ } ) ;
121133
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+ } ) ;
127137
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+ } ) ;
131146
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+ ) ;
135152 } ) ;
136153
137- describe ( 'addUserToCompany' , ( ) => {
138- let result ;
139- let email ;
154+ it ( 'should return response' , ( ) => {
155+ expect ( result ) . toEqual ( apiClientResponse ) ;
156+ } ) ;
157+ } ) ;
140158
141- beforeEach ( async ( ) => {
142- email = '☕️' ;
143- result = await sut . addUserToCompany ( companyId , email ) ;
144- } ) ;
159+ describe ( 'addUserToCompany' , ( ) => {
160+ let result ;
161+ let email ;
145162
163+ beforeEach ( async ( ) => {
164+ email = '☕️' ;
165+ result = await sut . addUserToCompany ( companyId , email ) ;
166+ } ) ;
146167
147- it ( 'should call createFormData' , ( ) => {
148- expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
149- } ) ;
168+ it ( 'should call createFormData' , ( ) => {
169+ expect ( apiClient . createFormData ) . toHaveBeenCalled ( ) ;
170+ } ) ;
150171
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+ } ) ;
155179
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+ } ) ;
159186
160- it ( 'should return response' , ( ) => {
161- expect ( result ) . toEqual ( apiClientResponse ) ;
162- } ) ;
187+ it ( 'should return response' , ( ) => {
188+ expect ( result ) . toEqual ( apiClientResponse ) ;
163189 } ) ;
190+ } ) ;
164191
165- describe ( 'removeUserFromCompany' , ( ) => {
166- let result ;
167- let uId ;
192+ describe ( 'removeUserFromCompany' , ( ) => {
193+ let result ;
194+ let uId ;
168195
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+ } ) ;
173200
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+ } ) ;
177207
178- it ( 'should return response' , ( ) => {
179- expect ( result ) . toEqual ( apiClientResponse ) ;
180- } ) ;
208+ it ( 'should return response' , ( ) => {
209+ expect ( result ) . toEqual ( apiClientResponse ) ;
181210 } ) ;
182- } ) ;
211+ } ) ;
212+ } ) ;
0 commit comments