@@ -93,19 +93,36 @@ describe('createOne() ->', () => {
9393 expect ( result . record . id ) . toBe ( result . recordId ) ;
9494 } ) ;
9595
96- it ( 'should return payload.errors' , async ( ) => {
96+ it ( 'should return resolver runtime error in payload.error' , async ( ) => {
97+ const resolver = createOne ( UserModel , UserTC ) ;
98+ await expect ( resolver . resolve ( { projection : { error : true } } ) ) . resolves . toEqual ( {
99+ error : expect . objectContaining ( {
100+ message : expect . stringContaining ( 'requires at least one value in args' ) ,
101+ } ) ,
102+ } ) ;
103+
104+ // should throw error if error not requested in graphql query
105+ await expect ( resolver . resolve ( { } ) ) . rejects . toThrowError (
106+ 'requires at least one value in args'
107+ ) ;
108+ } ) ;
109+
110+ it ( 'should return validation error in payload.error' , async ( ) => {
97111 const result = await createOne ( UserModel , UserTC ) . resolve ( {
98112 args : {
99113 record : { valid : 'AlwaysFails' , contacts : { email : 'mail' } } ,
100114 } ,
101115 projection : {
102- errors : true ,
116+ error : true ,
103117 } ,
104118 } ) ;
105- expect ( result . errors ) . toEqual ( [
106- { message : 'Path `n` is required.' , path : 'n' , value : undefined } ,
107- { message : 'this is a validate message' , path : 'valid' , value : 'AlwaysFails' } ,
108- ] ) ;
119+ // TODO: FIX error
120+ expect ( result . error ) . toEqual (
121+ [
122+ { message : 'Path `n` is required.' , path : 'n' , value : undefined } ,
123+ { message : 'this is a validate message' , path : 'valid' , value : 'AlwaysFails' } ,
124+ ] [ 0 ] // <---- [0] remove after preparation correct ValidationErrorsType
125+ ) ;
109126 } ) ;
110127
111128 it ( 'should throw GraphQLError if client does not request errors field in payload' , async ( ) => {
@@ -120,13 +137,13 @@ describe('createOne() ->', () => {
120137 ) ;
121138 } ) ;
122139
123- it ( 'should return empty payload.errors ' , async ( ) => {
140+ it ( 'should return empty payload.error ' , async ( ) => {
124141 const result = await createOne ( UserModel , UserTC ) . resolve ( {
125142 args : {
126143 record : { n : 'foo' , contacts : { email : 'mail' } } ,
127144 } ,
128145 } ) ;
129- expect ( result . errors ) . toEqual ( null ) ;
146+ expect ( result . error ) . toEqual ( undefined ) ;
130147 } ) ;
131148
132149 it ( 'should return mongoose document' , async ( ) => {
0 commit comments