@@ -51,119 +51,78 @@ describe('integration', () => {
5151 expect ( post . content ) . toMatch ( cloakedStringRegex )
5252 expect ( post . title ) . toEqual ( "I'm back" ) // clear text in the database
5353 } )
54- // test('Available APIs with write operations', async () => {
55- // // params.args.data.name
56- // // params.args.posts.create.content
57- // // params.args.posts.create.$.content
58- // // params.args.posts.connectOrCreate.create.content
59- // client.user.create({
60- // data: {
61- // name: '',
62- // email,
63- // posts: {
64- // create: [{ title: '', content: '' }],
65- // // create: {
66- // // title: '',
67- // // content: ''
68- // // },
69- // connectOrCreate: {
70- // create: {
71- // // cannot be an array
72- // title: '',
73- // content: ''
74- // },
75- // where: {
76- // id: 2
77- // }
78- // }
79- // }
80- // }
81- // })
8254
83- // // Update
84- // client.user.update({
85- // data: {
86- // name: 'foo'
87- // },
88- // where: {
89- // email
90- // }
91- // })
92-
93- // // Update with all possible nested queries:
94- // // params.args.data.name
95- // // params.args.data.name.set
96- // // params.args.data.name
97- // // params.args.data.posts.create.content
98- // // params.args.data.posts.connectOrCreate.create.content
99- // // params.args.data.posts.update.data.content
100- // // params.args.data.posts.update.data.content.set
101- // // params.args.data.posts.updateMany.data.content
102- // // params.args.data.posts.updateMany.data.content.set
103- // // params.args.data.posts.upsert.create.content
104- // // params.args.data.posts.upsert.update.content
105- // // params.args.data.posts.upsert.update.content.set
55+ test ( 'update user (with set)' , async ( ) => {
56+ const received = await client . user . update ( {
57+ data : {
58+ name : {
59+ set : 'Bond, James Bond.'
60+ }
61+ } ,
62+ where : {
63+ email
64+ }
65+ } )
66+ const user = await sqlite . get ( { table : 'User' , where : { email } } )
67+ expect ( received . name ) . toEqual ( 'Bond, James Bond.' )
68+ expect ( user . name ) . toMatch ( cloakedStringRegex )
69+ } )
10670
107- // client.user.update({
108- // data: {
109- // name: {
110- // set: 'foo' // alternative way to set things: update.data.field.set
111- // },
112- // posts: {
113- // create: {
114- // title: '',
115- // content: ''
116- // },
117- // connectOrCreate: {
118- // create: {
119- // title: '',
120- // content: ''
121- // },
122- // where: {
123- // id: 2
124- // }
125- // },
126- // update: {
127- // data: {
128- // content: {
129- // set: ''
130- // }
131- // },
132- // where: {
133- // id: 2
134- // }
135- // },
136- // updateMany: {
137- // data: {
138- // content: {
139- // set: ''
140- // }
141- // },
142- // where: {
143- // published: true
144- // }
145- // },
146- // upsert: {
147- // create: {
148- // title: '',
149- // content: ''
150- // },
151- // update: {
152- // content: {
153- // set: ''
154- // }
155- // },
156- // where: {
157- // id: 1
158- // }
159- // }
160- // }
161- // },
162- // where: {
163- // email
164- // }
165- // })
166- // client.user.updateMany()
167- // client.user.upsert()
168- // })
71+ test ( 'complex query nesting' , async ( ) => {
72+ const received = await client . user . create ( {
73+ data : {
74+ 75+ name : 'Alec Trevelyan' ,
76+ posts : {
77+ create : [
78+ {
79+ title : '006 - First report' ,
80+ content : 'For England, James?'
81+ } ,
82+ {
83+ title : 'Janus Quotes' ,
84+ content : "I've set the timers for six minutes" ,
85+ categories : {
86+ create : {
87+ name : 'Quotes'
88+ }
89+ }
90+ }
91+ ]
92+ }
93+ } ,
94+ include : {
95+ posts : {
96+ include : {
97+ categories : true
98+ }
99+ }
100+ }
101+ } )
102+ expect ( received . name ) . toEqual ( 'Alec Trevelyan' )
103+ expect ( received . posts [ 0 ] . content ) . toEqual ( 'For England, James?' )
104+ expect ( received . posts [ 1 ] . content ) . toEqual (
105+ "I've set the timers for six minutes"
106+ )
107+ const user = await sqlite . get ( {
108+ table : 'User' ,
109+ where :
{ email :
'[email protected] ' } 110+ } )
111+ const post1 = await sqlite . get ( {
112+ table : 'Post' ,
113+ where : { id : received . posts [ 0 ] . id . toString ( ) }
114+ } )
115+ const post2 = await sqlite . get ( {
116+ table : 'Post' ,
117+ where : { id : received . posts [ 1 ] . id . toString ( ) }
118+ } )
119+ const category = await sqlite . get ( {
120+ table : 'Category' ,
121+ where : { name : 'Quotes' }
122+ } )
123+ expect ( user . name ) . toMatch ( cloakedStringRegex )
124+ expect ( post1 . content ) . toMatch ( cloakedStringRegex )
125+ expect ( post2 . content ) . toMatch ( cloakedStringRegex )
126+ expect ( category . name ) . toEqual ( 'Quotes' )
127+ } )
169128} )
0 commit comments