File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
packages/firebase_data_connect/firebase_data_connect/test/src/network Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -376,5 +376,58 @@ void main() {
376376 throwsA (isA <DataConnectError >()),
377377 );
378378 });
379+ test ('invokeOperation should decode a partial error if available' ,
380+ () async {
381+ final mockResponse = http.Response (
382+ '''
383+ {
384+ "data": {"abc": "def"},
385+ "errors": [
386+ {
387+ "message": "SQL query error: pq: duplicate key value violates unique constraint movie_pkey",
388+ "locations": [],
389+ "path": [
390+ "the_matrix"
391+ ],
392+ "extensions": null
393+ }
394+ ]
395+ }''' ,
396+ 200 ,
397+ );
398+ when (
399+ mockHttpClient.post (
400+ any,
401+ headers: anyNamed ('headers' ),
402+ body: anyNamed ('body' ),
403+ ),
404+ ).thenAnswer ((_) async => mockResponse);
405+
406+ final deserializer = (String data) {
407+ Map <String , dynamic > decoded = jsonDecode (data) as Map <String , dynamic >;
408+ return AbcHolder (decoded['abc' ]! );
409+ };
410+
411+ expect (
412+ () => transport.invokeOperation (
413+ 'testQuery' ,
414+ 'executeQuery' ,
415+ deserializer,
416+ null ,
417+ null ,
418+ null ,
419+ ),
420+ throwsA (predicate ((e) =>
421+ e is DataConnectError &&
422+ e.data! ['abc' ] == 'def' &&
423+ e.decodedData is AbcHolder &&
424+ (e.decodedData as AbcHolder ).abc == 'def' )),
425+ );
426+ });
379427 });
380428}
429+
430+ class AbcHolder {
431+ String abc;
432+ AbcHolder (this .abc);
433+ }
You can’t perform that action at this time.
0 commit comments