@@ -7,6 +7,7 @@ import { ComplexError } from '../../model/errors/complex-error';
77import { SimpleError } from '../../model/errors/simple-error' ;
88import { UnknownError } from '../../model/errors/unknown-error' ;
99import { Qminder } from '../../qminder' ;
10+ import { ResponseValidationError } from '../../model/errors/response-validation-error' ;
1011
1112/**
1213 * A function that generates an object with the following keys:
@@ -476,30 +477,31 @@ describe('ApiBase', () => {
476477 } ) ;
477478 } ) ;
478479
479- it ( 'throws an error when getting errors as response' , ( done ) => {
480+ it ( 'throws an error when getting errors as response' , async ( ) => {
480481 Qminder . ApiBase . setKey ( 'testing' ) ;
481482 fetchSpy . mockImplementation ( ( ) =>
482483 Promise . resolve ( new MockResponse ( ERROR_UNDEFINED_FIELD ) ) ,
483484 ) ;
484485
485- Qminder . ApiBase . queryGraph ( ME_ID . request ) . then (
486- ( ) => done ( new Error ( 'QueryGraph should have thrown an error' ) ) ,
487- ( ) => done ( ) ,
486+ expect ( async ( ) => {
487+ await Qminder . ApiBase . queryGraph ( ME_ID . request ) ;
488+ } ) . rejects . toThrow (
489+ new SimpleError (
490+ "Validation error of type FieldUndefined: Field 'x' in type 'Account' is undefined @ 'account/x'" ,
491+ ) ,
488492 ) ;
489493 } ) ;
490494
491- it ( 'should resolve with response, even if response has errors ' , async ( ) => {
495+ it ( 'should throw an error when response does not contain any data ' , async ( ) => {
492496 Qminder . ApiBase . setKey ( 'testing' ) ;
493- fetchSpy . mockImplementation ( ( ) =>
494- Promise . resolve ( new MockResponse ( ERROR_UNDEFINED_FIELD ) ) ,
495- ) ;
497+ fetchSpy . mockImplementation ( ( ) => Promise . resolve ( new MockResponse ( { } ) ) ) ;
496498
497499 expect ( async ( ) => {
498500 await Qminder . ApiBase . queryGraph ( ME_ID . request ) ;
499501 } ) . rejects . toThrow (
500- `Server response is not valid GraphQL response. Response: ${ JSON . stringify (
501- ERROR_UNDEFINED_FIELD ,
502- ) } ` ,
502+ new ResponseValidationError (
503+ `Server response is not valid GraphQL response. Response: {}` ,
504+ ) ,
503505 ) ;
504506 } ) ;
505507 } ) ;
0 commit comments