@@ -18,30 +18,32 @@ type MethodTests = {
1818 | '.get'
1919 | '.get + $select'
2020 | '.get + id + query'
21+ | '.get + id + query id'
2122 | '.get + NotFound (string)'
2223 | '.get + NotFound (integer)'
23- | '.get + id + query id'
2424 remove :
2525 | '.remove'
2626 | '.remove + $select'
2727 | '.remove + id + query'
28+ | '.remove + id + query id'
2829 | '.remove + NotFound (string)'
2930 | '.remove + NotFound (integer)'
3031 | '.remove + multi'
3132 | '.remove + multi no pagination'
32- | '.remove + id + query id'
3333 update :
3434 | '.update'
3535 | '.update + $select'
3636 | '.update + id + query'
37+ | '.update + id + query id'
3738 | '.update + NotFound (string)'
3839 | '.update + NotFound (integer)'
3940 | '.update + query + NotFound'
40- | '.update + id + query id'
4141 patch :
4242 | '.patch'
4343 | '.patch + $select'
44+ | '.patch + $select unchanged'
4445 | '.patch + id + query'
46+ | '.patch + id + query id'
4547 | '.patch multiple'
4648 | '.patch multiple no pagination'
4749 | '.patch multi query same'
@@ -51,8 +53,6 @@ type MethodTests = {
5153 // | '.patch multi + $limit'
5254 | '.patch + NotFound (string)'
5355 | '.patch + NotFound (integer)'
54- | '.patch + query + NotFound'
55- | '.patch + id + query id'
5656 create :
5757 | '.create'
5858 | '.create + $select'
@@ -141,15 +141,6 @@ export default (options: MethodTestOptions) => {
141141 NotFound ,
142142 )
143143 } ,
144- '.get + NotFound (string)' : async ( ) => {
145- await assert . rejects (
146- ( ) => service . get ( '568225fbfe21222432e836ff' ) ,
147- NotFound ,
148- )
149- } ,
150- '.get + NotFound (integer)' : async ( ) => {
151- await assert . rejects ( ( ) => service . get ( 123141231231 ) , NotFound )
152- } ,
153144 '.get + id + query id' : async ( ) => {
154145 const alice = await service . create ( {
155146 name : 'Alice' ,
@@ -164,6 +155,15 @@ export default (options: MethodTestOptions) => {
164155 NotFound ,
165156 )
166157 } ,
158+ '.get + NotFound (string)' : async ( ) => {
159+ await assert . rejects (
160+ ( ) => service . get ( '568225fbfe21222432e836ff' ) ,
161+ NotFound ,
162+ )
163+ } ,
164+ '.get + NotFound (integer)' : async ( ) => {
165+ await assert . rejects ( ( ) => service . get ( 123141231231 ) , NotFound )
166+ } ,
167167 } ,
168168 remove : {
169169 '.remove' : async ( ) => {
@@ -199,6 +199,23 @@ export default (options: MethodTestOptions) => {
199199 const stillExists = await service . get ( doug [ idProp ] )
200200 assert . ok ( stillExists , 'Doug still exists' )
201201 } ,
202+ '.remove + id + query id' : async ( ) => {
203+ const alice = await service . create ( {
204+ name : 'Alice' ,
205+ age : 12 ,
206+ } )
207+
208+ await assert . rejects (
209+ ( ) =>
210+ service . remove ( doug [ idProp ] , {
211+ query : { [ idProp ] : alice [ idProp ] } ,
212+ } ) ,
213+ NotFound ,
214+ )
215+
216+ const stillExists = await service . get ( doug [ idProp ] )
217+ assert . ok ( stillExists , 'Doug still exists' )
218+ } ,
202219 '.remove + NotFound (string)' : async ( ) => {
203220 await assert . rejects (
204221 ( ) => service . remove ( '568225fbfe21222432e836ff' ) ,
@@ -305,28 +322,11 @@ export default (options: MethodTestOptions) => {
305322 } ,
306323 )
307324 } ,
308- '.remove + id + query id' : async ( ) => {
309- const alice = await service . create ( {
310- name : 'Alice' ,
311- age : 12 ,
312- } )
313-
314- await assert . rejects (
315- ( ) =>
316- service . remove ( doug [ idProp ] , {
317- query : { [ idProp ] : alice [ idProp ] } ,
318- } ) ,
319- NotFound ,
320- )
321-
322- const stillExists = await service . get ( doug [ idProp ] )
323- assert . ok ( stillExists , 'Doug still exists' )
324- } ,
325325 } satisfies TestConfig < 'remove' > ,
326326 update : {
327327 '.update' : async ( ) => {
328328 const originalData = { [ idProp ] : doug [ idProp ] , name : 'Dougler' }
329- const originalCopy = Object . assign ( { } , originalData )
329+ const originalCopy = { ... originalData }
330330
331331 const data = await service . update ( doug [ idProp ] , originalData )
332332
@@ -364,6 +364,11 @@ export default (options: MethodTestOptions) => {
364364
365365 const changed = await service . get ( doug [ idProp ] )
366366
367+ assert . strictEqual (
368+ changed . name ,
369+ originalData . name ,
370+ 'data.name changed' ,
371+ )
367372 assert . strictEqual ( changed . age , originalData . age , 'data.age changed' )
368373 } ,
369374 '.update + id + query' : async ( ) => {
@@ -380,6 +385,34 @@ export default (options: MethodTestOptions) => {
380385 ) ,
381386 NotFound ,
382387 )
388+
389+ const unchanged = await service . get ( doug [ idProp ] )
390+ assert . strictEqual ( unchanged . name , doug . name , 'name is still Doug' )
391+ } ,
392+ '.update + id + query id' : async ( ) => {
393+ const alice = await service . create ( {
394+ name : 'Alice' ,
395+ age : 12 ,
396+ } )
397+
398+ await assert . rejects (
399+ ( ) =>
400+ service . update (
401+ doug [ idProp ] ,
402+ {
403+ name : 'Dougler' ,
404+ age : 33 ,
405+ } ,
406+ {
407+ query : { [ idProp ] : alice [ idProp ] } ,
408+ } ,
409+ ) ,
410+ NotFound ,
411+ )
412+
413+ const unchanged = await service . get ( doug [ idProp ] )
414+ assert . equal ( unchanged . name , doug . name , 'name stayed the same' )
415+ assert . equal ( unchanged . age , doug . age , 'age stayed the same' )
383416 } ,
384417 '.update + NotFound (string)' : async ( ) => {
385418 await assert . rejects (
@@ -412,27 +445,6 @@ export default (options: MethodTestOptions) => {
412445 NotFound ,
413446 )
414447 } ,
415- '.update + id + query id' : async ( ) => {
416- const alice = await service . create ( {
417- name : 'Alice' ,
418- age : 12 ,
419- } )
420-
421- await assert . rejects (
422- ( ) =>
423- service . update (
424- doug [ idProp ] ,
425- {
426- name : 'Dougler' ,
427- age : 33 ,
428- } ,
429- {
430- query : { [ idProp ] : alice [ idProp ] } ,
431- } ,
432- ) ,
433- NotFound ,
434- )
435- } ,
436448 } satisfies TestConfig < 'update' > ,
437449 patch : {
438450 '.patch' : async ( ) => {
@@ -476,6 +488,28 @@ export default (options: MethodTestOptions) => {
476488 const changed = await service . get ( doug [ idProp ] )
477489 assert . strictEqual ( changed . age , originalData . age , 'data.age changed' )
478490 } ,
491+
492+ '.patch + $select unchanged' : async ( ) => {
493+ const originalData = {
494+ [ idProp ] : doug [ idProp ] ,
495+ name : 'PatchDoug' ,
496+ }
497+
498+ const data = await service . patch ( doug [ idProp ] , originalData , {
499+ query : { $select : [ 'name' ] } ,
500+ } )
501+
502+ assert . strictEqual (
503+ data [ idProp ] . toString ( ) ,
504+ doug [ idProp ] . toString ( ) ,
505+ `${ idProp } id property matches` ,
506+ )
507+ assert . strictEqual ( data . name , 'PatchDoug' , 'data.name matches' )
508+ assert . ok ( ! ( 'age' in data ) , 'data.age is not present' )
509+
510+ const changed = await service . get ( doug [ idProp ] )
511+ assert . strictEqual ( changed . age , doug . age , 'data.age unchanged' )
512+ } ,
479513 '.patch + id + query' : async ( ) => {
480514 await assert . rejects (
481515 ( ) =>
@@ -490,6 +524,33 @@ export default (options: MethodTestOptions) => {
490524 ) ,
491525 NotFound ,
492526 )
527+
528+ const unchanged = await service . get ( doug [ idProp ] )
529+ assert . strictEqual ( unchanged . name , doug . name , 'name is still Doug' )
530+ } ,
531+ '.patch + id + query id' : async ( ) => {
532+ const alice = await service . create ( {
533+ name : 'Alice' ,
534+ age : 12 ,
535+ } )
536+
537+ await assert . rejects (
538+ ( ) =>
539+ service . patch (
540+ doug [ idProp ] ,
541+ {
542+ age : 33 ,
543+ } ,
544+ {
545+ query : { [ idProp ] : alice [ idProp ] } ,
546+ } ,
547+ ) ,
548+ NotFound ,
549+ )
550+
551+ const dougAfter = await service . get ( doug [ idProp ] )
552+
553+ assert . equal ( dougAfter . age , doug . age , 'age stayed the same' )
493554 } ,
494555 '.patch multiple' : async ( ) => {
495556 await withOptions ( service , { multi : false } , ( ) =>
@@ -742,43 +803,6 @@ export default (options: MethodTestOptions) => {
742803 NotFound ,
743804 )
744805 } ,
745- '.patch + query + NotFound' : async ( ) => {
746- const dave = await service . create ( { name : 'Dave' } )
747-
748- await assert . rejects (
749- ( ) =>
750- service . patch (
751- dave [ idProp ] ,
752- { name : 'PatchedDave' } ,
753- { query : { name : 'NotDave' } } ,
754- ) ,
755- NotFound ,
756- )
757- } ,
758- '.patch + id + query id' : async ( ) => {
759- const alice = await service . create ( {
760- name : 'Alice' ,
761- age : 12 ,
762- } )
763-
764- await assert . rejects (
765- ( ) =>
766- service . patch (
767- doug [ idProp ] ,
768- {
769- age : 33 ,
770- } ,
771- {
772- query : { [ idProp ] : alice [ idProp ] } ,
773- } ,
774- ) ,
775- NotFound ,
776- )
777-
778- const dougAfter = await service . get ( doug [ idProp ] )
779-
780- assert . equal ( doug . age , dougAfter . age , 'age stayed the same' )
781- } ,
782806 } satisfies TestConfig < 'patch' > ,
783807 create : {
784808 '.create' : async ( ) => {
0 commit comments