@@ -4,7 +4,6 @@ import { expect } from 'chai';
44import { UserModel } from '../../__mocks__/userModel.js' ;
55import updateOne from '../updateOne' ;
66import Resolver from '../../../../graphql-compose/src/resolver/resolver' ;
7- import { GraphQLObjectType } from 'graphql' ;
87import { convertModelToGraphQL } from '../../fieldsConverter' ;
98
109const UserType = convertModelToGraphQL ( UserModel , 'User' ) ;
@@ -29,7 +28,7 @@ describe('updateOne() ->', () => {
2928 name : 'userName2' ,
3029 skills : [ 'go' , 'erlang' ] ,
3130 gender : 'female' ,
32- relocation : false ,
31+ relocation : true ,
3332 } ) ;
3433
3534 return Promise . all ( [
@@ -70,7 +69,7 @@ describe('updateOne() ->', () => {
7069 await expect ( result ) . be . rejectedWith ( Error , 'at least one value in args.filter' ) ;
7170 } ) ;
7271
73- it ( 'should return recordId' , async ( ) => {
72+ it ( 'should return payload. recordId' , async ( ) => {
7473 const result = await updateOne ( UserModel , UserType ) . resolve ( {
7574 args : { filter : { _id : user1 . id } } ,
7675 } ) ;
@@ -87,34 +86,58 @@ describe('updateOne() ->', () => {
8786 expect ( result ) . have . deep . property ( 'record.name' , 'newName' ) ;
8887 } ) ;
8988
90- it ( 'should change data via args.input in database' , async ( ) => {
91- const result = await updateOne ( UserModel , UserType ) . resolve ( {
89+ it ( 'should change data via args.input in database' , ( done ) => {
90+ const checkedName = 'nameForMongoDB' ;
91+ updateOne ( UserModel , UserType ) . resolve ( {
9292 args : {
9393 filter : { _id : user1 . id } ,
94- input : { name : 'newName' } ,
94+ input : { name : checkedName } ,
9595 } ,
96+ } ) . then ( ( ) => {
97+ UserModel . collection . findOne ( { _id : user1 . _id } , ( err , doc ) => {
98+ expect ( doc . name ) . to . be . equal ( checkedName ) ;
99+ done ( ) ;
100+ } ) ;
96101 } ) ;
97- throw new Error ( 'TODO' ) ;
98102 } ) ;
99103
100- xit ( 'should return document if provided existed id' , async ( ) => {
101- const result = await updateOne ( UserModel , UserType ) . resolve ( { args : { id : user1 . _id } } ) ;
102- expect ( result ) . have . property ( 'name' ) . that . equal ( user1 . name ) ;
104+ it ( 'should return payload.record' , async ( ) => {
105+ const result = await updateOne ( UserModel , UserType ) . resolve ( {
106+ args : { filter : { _id : user1 . id } } ,
107+ } ) ;
108+ expect ( result ) . have . deep . property ( 'record.id' , user1 . id ) ;
103109 } ) ;
104110
105- xit ( 'should skip records' , async ( ) => {
106- const result = await updateOne ( UserModel , UserType ) . resolve ( { args : { skip : 2000 } } ) ;
107- expect ( result ) . to . be . null ;
111+ it ( 'should skip records' , async ( ) => {
112+ const result1 = await updateOne ( UserModel , UserType ) . resolve ( {
113+ args : {
114+ filter : { relocation : true } ,
115+ skip : 0 ,
116+ } ,
117+ } ) ;
118+ const result2 = await updateOne ( UserModel , UserType ) . resolve ( {
119+ args : {
120+ filter : { relocation : true } ,
121+ skip : 1 ,
122+ } ,
123+ } ) ;
124+ expect ( result1 . record . id ) . to . not . equal ( result2 . record . id ) ;
108125 } ) ;
109126
110- xit ( 'should sort records' , async ( ) => {
111- const result1 = await updateOne ( UserModel , UserType )
112- . resolve ( { args : { sort : { _id : 1 } } } ) ;
113-
114- const result2 = await updateOne ( UserModel , UserType )
115- . resolve ( { args : { sort : { _id : - 1 } } } ) ;
116-
117- expect ( `${ result1 . _id } ` ) . not . equal ( `${ result2 . _id } ` ) ;
127+ it ( 'should sort records' , async ( ) => {
128+ const result1 = await updateOne ( UserModel , UserType ) . resolve ( {
129+ args : {
130+ filter : { relocation : true } ,
131+ sort : { _id : 1 } ,
132+ } ,
133+ } ) ;
134+ const result2 = await updateOne ( UserModel , UserType ) . resolve ( {
135+ args : {
136+ filter : { relocation : true } ,
137+ sort : { _id : - 1 } ,
138+ } ,
139+ } ) ;
140+ expect ( result1 . record . id ) . to . not . equal ( result2 . record . id ) ;
118141 } ) ;
119142 } ) ;
120143} ) ;
0 commit comments