@@ -4,7 +4,9 @@ import { expect } from 'chai';
44import { UserModel } from '../../__mocks__/userModel.js' ;
55import findByIds from '../findByIds' ;
66import Resolver from '../../../../graphql-compose/src/resolver/resolver' ;
7- import { GraphQLNonNull , GraphQLID , GraphQLList , GraphQLObjectType } from 'graphql' ;
7+ import InputTypeComposer from '../../../../graphql-compose/src/typeInputComposer' ;
8+ import { GraphQLNonNull , GraphQLList , GraphQLObjectType } from 'graphql' ;
9+ import GraphQLMongoID from '../../types/mongoid' ;
810
911const UserType = new GraphQLObjectType ( {
1012 name : 'MockUserType' ,
@@ -36,23 +38,25 @@ describe('findByIds() ->', () => {
3638 expect ( resolver ) . to . be . instanceof ( Resolver ) ;
3739 } ) ;
3840
39- it ( 'should have non-null `ids` arg' , ( ) => {
40- const resolver = findByIds ( UserModel , UserType ) ;
41- expect ( resolver . hasArg ( 'ids' ) ) . to . be . true ;
42- const argConfig = resolver . getArg ( 'ids' ) ;
43- expect ( argConfig . type ) . to . be . instanceof ( GraphQLNonNull ) ;
44- expect ( argConfig . type . ofType ) . to . be . instanceof ( GraphQLList ) ;
45- expect ( argConfig . type . ofType . ofType ) . to . equal ( GraphQLID ) ;
46- } ) ;
41+ describe ( 'Resolver.args' , ( ) => {
42+ it ( 'should have non-null `_ids` arg' , ( ) => {
43+ const resolver = findByIds ( UserModel , UserType ) ;
44+ expect ( resolver . hasArg ( '_ids' ) ) . to . be . true ;
45+ const argConfig = resolver . getArg ( '_ids' ) ;
46+ expect ( argConfig ) . property ( 'type' ) . that . instanceof ( GraphQLNonNull ) ;
47+ expect ( argConfig ) . deep . property ( 'type.ofType' ) . that . instanceof ( GraphQLList ) ;
48+ expect ( argConfig ) . deep . property ( 'type.ofType.ofType' ) . that . equal ( GraphQLMongoID ) ;
49+ } ) ;
4750
48- it ( 'Resolver object should have `limit` arg' , ( ) => {
49- const resolver = findByIds ( UserModel , UserType ) ;
50- expect ( resolver . hasArg ( 'limit' ) ) . to . be . true ;
51- } ) ;
51+ it ( 'should have `limit` arg' , ( ) => {
52+ const resolver = findByIds ( UserModel , UserType ) ;
53+ expect ( resolver . hasArg ( 'limit' ) ) . to . be . true ;
54+ } ) ;
5255
53- it ( 'Resolver object should have `sort` arg' , ( ) => {
54- const resolver = findByIds ( UserModel , UserType ) ;
55- expect ( resolver . hasArg ( 'sort' ) ) . to . be . true ;
56+ it ( 'should have `sort` arg' , ( ) => {
57+ const resolver = findByIds ( UserModel , UserType ) ;
58+ expect ( resolver . hasArg ( 'sort' ) ) . to . be . true ;
59+ } ) ;
5660 } ) ;
5761
5862 describe ( 'Resolver.resolve():Promise' , ( ) => {
@@ -61,21 +65,21 @@ describe('findByIds() ->', () => {
6165 await expect ( result ) . be . fulfilled ;
6266 } ) ;
6367
64- it ( 'should return empty array if args.ids is empty' , async ( ) => {
68+ it ( 'should return empty array if args._ids is empty' , async ( ) => {
6569 const result = await findByIds ( UserModel , UserType ) . resolve ( { } ) ;
6670 expect ( result ) . to . be . instanceOf ( Array ) ;
6771 expect ( result ) . to . be . empty ;
6872 } ) ;
6973
70- it ( 'should return empty array if args.ids is not valid objectIds' , async ( ) => {
71- const result = await findByIds ( UserModel , UserType ) . resolve ( { args : { ids : [ 'd' , 'e' ] } } ) ;
74+ it ( 'should return empty array if args._ids is not valid objectIds' , async ( ) => {
75+ const result = await findByIds ( UserModel , UserType ) . resolve ( { args : { _ids : [ 'd' , 'e' ] } } ) ;
7276 expect ( result ) . to . be . instanceOf ( Array ) ;
7377 expect ( result ) . to . be . empty ;
7478 } ) ;
7579
7680 it ( 'should return array of documents' , async ( ) => {
7781 const result = await findByIds ( UserModel , UserType )
78- . resolve ( { args : { ids : [ user1 . _id , user2 . _id , user3 . _id ] } } ) ;
82+ . resolve ( { args : { _ids : [ user1 . _id , user2 . _id , user3 . _id ] } } ) ;
7983
8084 expect ( result ) . to . be . instanceOf ( Array ) ;
8185 expect ( result ) . to . have . lengthOf ( 3 ) ;
@@ -86,7 +90,7 @@ describe('findByIds() ->', () => {
8690 it ( 'should return array of documents if object id is string' , async ( ) => {
8791 const stringId = `${ user1 . _id } ` ;
8892 const result = await findByIds ( UserModel , UserType )
89- . resolve ( { args : { ids : [ stringId ] } } ) ;
93+ . resolve ( { args : { _ids : [ stringId ] } } ) ;
9094
9195 expect ( result ) . to . be . instanceOf ( Array ) ;
9296 expect ( result ) . to . have . lengthOf ( 1 ) ;
0 commit comments