@@ -6,6 +6,9 @@ import findById from '../findById';
66import Resolver from '../../../../graphql-compose/src/resolver/resolver' ;
77import { GraphQLNonNull } from 'graphql' ;
88import GraphQLMongoID from '../../types/mongoid' ;
9+ import { convertModelToGraphQL } from '../../fieldsConverter' ;
10+
11+ const UserType = convertModelToGraphQL ( UserModel , 'User' ) ;
912
1013describe ( 'findById() ->' , ( ) => {
1114 let user ;
@@ -22,13 +25,13 @@ describe('findById() ->', () => {
2225 } ) ;
2326
2427 it ( 'should return Resolver object' , ( ) => {
25- const resolver = findById ( UserModel ) ;
28+ const resolver = findById ( UserModel , UserType ) ;
2629 expect ( resolver ) . to . be . instanceof ( Resolver ) ;
2730 } ) ;
2831
2932 describe ( 'Resolver.args' , ( ) => {
3033 it ( 'should have non-null `_id` arg' , ( ) => {
31- const resolver = findById ( UserModel ) ;
34+ const resolver = findById ( UserModel , UserType ) ;
3235 expect ( resolver . hasArg ( '_id' ) ) . to . be . true ;
3336 const argConfig = resolver . getArg ( '_id' ) ;
3437 expect ( argConfig ) . property ( 'type' ) . that . instanceof ( GraphQLNonNull ) ;
@@ -38,22 +41,22 @@ describe('findById() ->', () => {
3841
3942 describe ( 'Resolver.resolve():Promise' , ( ) => {
4043 it ( 'should be fulfilled promise' , async ( ) => {
41- const result = findById ( UserModel ) . resolve ( { } ) ;
44+ const result = findById ( UserModel , UserType ) . resolve ( { } ) ;
4245 await expect ( result ) . be . fulfilled ;
4346 } ) ;
4447
4548 it ( 'should be rejected if args.id is not objectId' , async ( ) => {
46- const result = findById ( UserModel ) . resolve ( { args : { _id : 1 } } ) ;
49+ const result = findById ( UserModel , UserType ) . resolve ( { args : { _id : 1 } } ) ;
4750 await expect ( result ) . be . rejected ;
4851 } ) ;
4952
5053 it ( 'should return null if args.id is empty' , async ( ) => {
51- const result = await findById ( UserModel ) . resolve ( { } ) ;
54+ const result = await findById ( UserModel , UserType ) . resolve ( { } ) ;
5255 expect ( result ) . equal ( null ) ;
5356 } ) ;
5457
5558 it ( 'should return document if provided existed id' , async ( ) => {
56- const result = await findById ( UserModel ) . resolve ( { args : { _id : user . _id } } ) ;
59+ const result = await findById ( UserModel , UserType ) . resolve ( { args : { _id : user . _id } } ) ;
5760 expect ( result ) . have . property ( 'name' ) . that . equal ( user . name ) ;
5861 } ) ;
5962 } ) ;
0 commit comments