@@ -91,6 +91,92 @@ describe('CrashApiClient', () => {
9191 } ) ;
9292 } ) ;
9393
94+ describe ( 'getCrashByGroupId' , ( ) => {
95+ let client : CrashApiClient ;
96+ let fakeBugSplatApiClient ;
97+ let fakeCrashApiResponse ;
98+ let result ;
99+ const groupId = 12345 ;
100+
101+ beforeEach ( async ( ) => {
102+ fakeCrashApiResponse = createFakeCrashApiResponse ( ) ;
103+ const fakeResponse = createFakeResponseBody ( 200 , fakeCrashApiResponse ) ;
104+ fakeBugSplatApiClient = createFakeBugSplatApiClient ( fakeFormData , fakeResponse ) ;
105+ client = new CrashApiClient ( fakeBugSplatApiClient ) ;
106+
107+ result = await client . getCrashByGroupId ( database , groupId ) ;
108+ } ) ;
109+
110+ it ( 'should call fetch with correct route' , ( ) => {
111+ expect ( fakeBugSplatApiClient . fetch ) . toHaveBeenCalledWith (
112+ '/api/crash/details' ,
113+ jasmine . anything ( )
114+ ) ;
115+ } ) ;
116+
117+ it ( 'should call fetch with formData containing database and stackKeyId' , ( ) => {
118+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'database' , database ) ;
119+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'stackKeyId' , groupId . toString ( ) ) ;
120+ expect ( fakeBugSplatApiClient . fetch ) . toHaveBeenCalledWith (
121+ jasmine . any ( String ) ,
122+ jasmine . objectContaining ( {
123+ method : 'POST' ,
124+ body : fakeFormData ,
125+ cache : 'no-cache' ,
126+ credentials : 'include' ,
127+ redirect : 'follow' ,
128+ } )
129+ ) ;
130+ } ) ;
131+
132+ it ( 'should return response json' , ( ) => {
133+ expect ( result ) . toEqual ( jasmine . objectContaining ( createCrashDetails ( fakeCrashApiResponse ) ) ) ;
134+ } ) ;
135+
136+ it ( 'should throw if status is not 200' , async ( ) => {
137+ const message = 'Bad request' ;
138+
139+ try {
140+ const fakeErrorBody = { message } ;
141+ const fakeResponse = createFakeResponseBody ( 400 , fakeErrorBody , false ) ;
142+ const fakeBugSplatApiClient = createFakeBugSplatApiClient ( fakeFormData , fakeResponse ) ;
143+ const client = new CrashApiClient ( fakeBugSplatApiClient ) ;
144+
145+ await client . getCrashByGroupId ( database , groupId ) ;
146+ fail ( 'getCrashByGroupId was supposed to throw!' ) ;
147+ } catch ( error : any ) {
148+ expect ( error . message ) . toEqual ( message ) ;
149+ }
150+ } ) ;
151+
152+ it ( 'should throw if database is falsy' , async ( ) => {
153+ try {
154+ await client . getCrashByGroupId ( '' , groupId ) ;
155+ fail ( 'getCrashByGroupId was supposed to throw!' ) ;
156+ } catch ( error : any ) {
157+ 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 / ) ;
158+ }
159+ } ) ;
160+
161+ it ( 'should throw if groupId is less than or equal to 0' , async ( ) => {
162+ try {
163+ await client . getCrashByGroupId ( database , 0 ) ;
164+ fail ( 'getCrashByGroupId was supposed to throw!' ) ;
165+ } catch ( error : any ) {
166+ expect ( error . message ) . toMatch ( / t o b e a p o s i t i v e n o n - z e r o n u m b e r / ) ;
167+ }
168+ } ) ;
169+
170+ it ( 'should throw if groupId is negative' , async ( ) => {
171+ try {
172+ await client . getCrashByGroupId ( database , - 1 ) ;
173+ fail ( 'getCrashByGroupId was supposed to throw!' ) ;
174+ } catch ( error : any ) {
175+ expect ( error . message ) . toMatch ( / t o b e a p o s i t i v e n o n - z e r o n u m b e r / ) ;
176+ }
177+ } ) ;
178+ } ) ;
179+
94180 describe ( 'reprocessCrash' , ( ) => {
95181 let client : CrashApiClient ;
96182 let fakeReprocessApiResponse ;
0 commit comments