@@ -3,7 +3,7 @@ import { createFakeBugSplatApiClient } from '@spec/fakes/common/bugsplat-api-cli
33import { createFakeFormData } from '@spec/fakes/common/form-data' ;
44import { createFakeResponseBody } from '@spec/fakes/common/response' ;
55import { createFakeCrashApiResponse } from '@spec/fakes/crash/crash-api-response' ;
6- import { createCrashDetails } from '../crash-details/crash-details' ;
6+ import { CrashStatus , createCrashDetails } from '../crash-details/crash-details' ;
77
88describe ( 'CrashApiClient' , ( ) => {
99 const database = 'fred' ;
@@ -170,4 +170,59 @@ describe('CrashApiClient', () => {
170170 }
171171 } ) ;
172172 } ) ;
173- } ) ;
173+
174+ describe ( 'postStatus' , ( ) => {
175+ let client : CrashApiClient ;
176+ let fakePostStatusApiResponse ;
177+ let fakeBugSplatApiClient ;
178+ let result ;
179+
180+ beforeEach ( async ( ) => {
181+ fakePostStatusApiResponse = { success : true } ;
182+ const fakeResponse = createFakeResponseBody ( 200 , fakePostStatusApiResponse ) ;
183+ fakeBugSplatApiClient = createFakeBugSplatApiClient ( fakeFormData , fakeResponse ) ;
184+ client = new CrashApiClient ( fakeBugSplatApiClient ) ;
185+
186+ result = await client . postStatus ( database , id , CrashStatus . Closed ) ;
187+ } ) ;
188+
189+ it ( 'should call fetch with correct route' , ( ) => {
190+ expect ( fakeBugSplatApiClient . fetch ) . toHaveBeenCalledWith ( '/api/crash/status' , jasmine . anything ( ) ) ;
191+ } ) ;
192+
193+ it ( 'should call fetch with formData containing database, id and status' , ( ) => {
194+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'database' , database ) ;
195+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'groupId' , id . toString ( ) ) ;
196+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'status' , CrashStatus . Closed . toString ( ) ) ;
197+ } ) ;
198+
199+ it ( 'should return response json' , ( ) => {
200+ expect ( result ) . toEqual ( fakePostStatusApiResponse ) ;
201+ } ) ;
202+
203+ it ( 'should throw if status is not 200' , async ( ) => {
204+ const message = 'Bad request' ;
205+
206+ try {
207+ const fakePostStatusErrorBody = { message } ;
208+ const fakeResponse = createFakeResponseBody ( 400 , fakePostStatusErrorBody , false ) ;
209+ const fakeBugSplatApiClient = createFakeBugSplatApiClient ( fakeFormData , fakeResponse ) ;
210+ const client = new CrashApiClient ( fakeBugSplatApiClient ) ;
211+
212+ await client . postStatus ( database , id , CrashStatus . Closed ) ;
213+ fail ( 'postStatus was supposed to throw!' ) ;
214+ } catch ( error : any ) {
215+ expect ( error . message ) . toEqual ( message ) ;
216+ }
217+ } ) ;
218+
219+ it ( 'should throw if database is falsy' , async ( ) => {
220+ try {
221+ await client . postStatus ( '' , id , CrashStatus . Closed ) ;
222+ fail ( 'postStatus was supposed to throw!' ) ;
223+ } catch ( error : any ) {
224+ expect ( error . message ) . toMatch ( / t o b e a n o n w h i t e s p a c e s t r i n g / ) ;
225+ }
226+ } ) ;
227+ } ) ;
228+ } ) ;
0 commit comments