feathers-adapter-vitest 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/methods.ts ADDED
@@ -0,0 +1,887 @@
1
+ import assert from 'node:assert'
2
+ import type { AdapterMethodsTest } from './declarations.js'
3
+ import { describe, beforeEach, afterEach, beforeAll } from 'vitest'
4
+ import type { Application } from '@feathersjs/feathers'
5
+
6
+ type MethodTestOptions = {
7
+ app: Application
8
+ test: AdapterMethodsTest
9
+ serviceName: string
10
+ idProp: string
11
+ }
12
+
13
+ export default (options: MethodTestOptions) => {
14
+ const { test, app, serviceName, idProp } = options
15
+
16
+ describe(' Methods', () => {
17
+ let doug: any
18
+ let service: any
19
+
20
+ beforeEach(async () => {
21
+ service = app.service(serviceName)
22
+ doug = await app.service(serviceName).create({
23
+ name: 'Doug',
24
+ age: 32,
25
+ })
26
+ })
27
+
28
+ afterEach(async () => {
29
+ try {
30
+ await app.service(serviceName).remove(doug[idProp])
31
+ } catch {
32
+ // Ignore errors
33
+ }
34
+ })
35
+
36
+ describe('get', () => {
37
+ test('.get', async () => {
38
+ const data = await service.get(doug[idProp])
39
+
40
+ assert.strictEqual(
41
+ data[idProp].toString(),
42
+ doug[idProp].toString(),
43
+ `${idProp} id matches`,
44
+ )
45
+ assert.strictEqual(data.name, 'Doug', 'data.name matches')
46
+ assert.strictEqual(data.age, 32, 'data.age matches')
47
+ })
48
+
49
+ test('.get + $select', async () => {
50
+ const data = await service.get(doug[idProp], {
51
+ query: { $select: ['name'] },
52
+ })
53
+
54
+ assert.strictEqual(
55
+ data[idProp].toString(),
56
+ doug[idProp].toString(),
57
+ `${idProp} id property matches`,
58
+ )
59
+ assert.strictEqual(data.name, 'Doug', 'data.name matches')
60
+ assert.ok(!data.age, 'data.age is falsy')
61
+ })
62
+
63
+ test('.get + id + query', async () => {
64
+ try {
65
+ await service.get(doug[idProp], {
66
+ query: { name: 'Tester' },
67
+ })
68
+ throw new Error('Should never get here')
69
+ } catch (error: any) {
70
+ assert.strictEqual(
71
+ error.name,
72
+ 'NotFound',
73
+ 'Got a NotFound Feathers error',
74
+ )
75
+ }
76
+ })
77
+
78
+ test('.get + NotFound', async () => {
79
+ try {
80
+ await service.get('568225fbfe21222432e836ff')
81
+ throw new Error('Should never get here')
82
+ } catch (error: any) {
83
+ assert.strictEqual(
84
+ error.name,
85
+ 'NotFound',
86
+ 'Error is a NotFound Feathers error',
87
+ )
88
+ }
89
+ })
90
+
91
+ test('.get + id + query id', async () => {
92
+ const alice = await service.create({
93
+ name: 'Alice',
94
+ age: 12,
95
+ })
96
+
97
+ try {
98
+ await service.get(doug[idProp], {
99
+ query: { [idProp]: alice[idProp] },
100
+ })
101
+ throw new Error('Should never get here')
102
+ } catch (error: any) {
103
+ assert.strictEqual(
104
+ error.name,
105
+ 'NotFound',
106
+ 'Got a NotFound Feathers error',
107
+ )
108
+ }
109
+
110
+ await service.remove(alice[idProp])
111
+ })
112
+ })
113
+
114
+ describe('find', () => {
115
+ test('.find', async () => {
116
+ const data = await service.find()
117
+
118
+ assert.ok(Array.isArray(data), 'Data is an array')
119
+ assert.strictEqual(data.length, 1, 'Got one entry')
120
+ })
121
+ })
122
+
123
+ describe('remove', () => {
124
+ test('.remove', async () => {
125
+ const data = await service.remove(doug[idProp])
126
+
127
+ assert.strictEqual(data.name, 'Doug', 'data.name matches')
128
+ })
129
+
130
+ test('.remove + $select', async () => {
131
+ const data = await service.remove(doug[idProp], {
132
+ query: { $select: ['name'] },
133
+ })
134
+
135
+ assert.strictEqual(
136
+ data[idProp].toString(),
137
+ doug[idProp].toString(),
138
+ `${idProp} id property matches`,
139
+ )
140
+ assert.strictEqual(data.name, 'Doug', 'data.name matches')
141
+ assert.ok(!data.age, 'data.age is falsy')
142
+ })
143
+
144
+ test('.remove + id + query', async () => {
145
+ try {
146
+ await service.remove(doug[idProp], {
147
+ query: { name: 'Tester' },
148
+ })
149
+ throw new Error('Should never get here')
150
+ } catch (error: any) {
151
+ assert.strictEqual(
152
+ error.name,
153
+ 'NotFound',
154
+ 'Got a NotFound Feathers error',
155
+ )
156
+ }
157
+ })
158
+
159
+ test('.remove + multi', async () => {
160
+ try {
161
+ await service.remove(null)
162
+ throw new Error('Should never get here')
163
+ } catch (error: any) {
164
+ assert.strictEqual(
165
+ error.name,
166
+ 'MethodNotAllowed',
167
+ 'Removing multiple without option set throws MethodNotAllowed',
168
+ )
169
+ }
170
+
171
+ service.options.multi = ['remove']
172
+
173
+ await service.create({ name: 'Dave', age: 29, created: true })
174
+ await service.create({
175
+ name: 'David',
176
+ age: 3,
177
+ created: true,
178
+ })
179
+
180
+ const data = await service.remove(null, {
181
+ query: { created: true },
182
+ })
183
+
184
+ assert.strictEqual(data.length, 2)
185
+
186
+ const names = data.map((person: any) => person.name)
187
+
188
+ assert.ok(names.includes('Dave'), 'Dave removed')
189
+ assert.ok(names.includes('David'), 'David removed')
190
+ })
191
+
192
+ test('.remove + multi no pagination', async () => {
193
+ try {
194
+ await service.remove(doug[idProp])
195
+ } catch {
196
+ // Ignore errors
197
+ }
198
+
199
+ const count = 14
200
+ const defaultPaginate = 10
201
+
202
+ assert.ok(
203
+ count > defaultPaginate,
204
+ 'count is bigger than default pagination',
205
+ )
206
+
207
+ const multiBefore = service.options.multi
208
+ const paginateBefore = service.options.paginate
209
+
210
+ try {
211
+ service.options.multi = true
212
+ service.options.paginate = {
213
+ default: defaultPaginate,
214
+ max: 100,
215
+ }
216
+
217
+ const emptyItems = await service.find({ paginate: false })
218
+ assert.strictEqual(emptyItems.length, 0, 'no items before')
219
+
220
+ const createdItems = await service.create(
221
+ Array.from(Array(count)).map((_, i) => ({
222
+ name: `name-${i}`,
223
+ age: 3,
224
+ created: true,
225
+ })),
226
+ )
227
+ assert.strictEqual(
228
+ createdItems.length,
229
+ count,
230
+ `created ${count} items`,
231
+ )
232
+
233
+ const foundItems = await service.find({ paginate: false })
234
+ assert.strictEqual(foundItems.length, count, `created ${count} items`)
235
+
236
+ const foundPaginatedItems = await service.find({})
237
+ assert.strictEqual(
238
+ foundPaginatedItems.data.length,
239
+ defaultPaginate,
240
+ 'found paginated items',
241
+ )
242
+
243
+ const allItems = await service.remove(null, {
244
+ query: { created: true },
245
+ })
246
+
247
+ assert.strictEqual(
248
+ allItems.length,
249
+ count,
250
+ `removed all ${count} items`,
251
+ )
252
+ } finally {
253
+ await service.remove(null, {
254
+ query: { created: true },
255
+ paginate: false,
256
+ })
257
+
258
+ service.options.multi = multiBefore
259
+ service.options.paginate = paginateBefore
260
+ }
261
+ })
262
+
263
+ test('.remove + id + query id', async () => {
264
+ const alice = await service.create({
265
+ name: 'Alice',
266
+ age: 12,
267
+ })
268
+
269
+ try {
270
+ await service.remove(doug[idProp], {
271
+ query: { [idProp]: alice[idProp] },
272
+ })
273
+ throw new Error('Should never get here')
274
+ } catch (error: any) {
275
+ assert.strictEqual(
276
+ error.name,
277
+ 'NotFound',
278
+ 'Got a NotFound Feathers error',
279
+ )
280
+ }
281
+
282
+ await service.remove(alice[idProp])
283
+ })
284
+ })
285
+
286
+ describe('update', () => {
287
+ test('.update', async () => {
288
+ const originalData = { [idProp]: doug[idProp], name: 'Dougler' }
289
+ const originalCopy = Object.assign({}, originalData)
290
+
291
+ const data = await service.update(doug[idProp], originalData)
292
+
293
+ assert.deepStrictEqual(
294
+ originalData,
295
+ originalCopy,
296
+ 'data was not modified',
297
+ )
298
+ assert.strictEqual(
299
+ data[idProp].toString(),
300
+ doug[idProp].toString(),
301
+ `${idProp} id matches`,
302
+ )
303
+ assert.strictEqual(data.name, 'Dougler', 'data.name matches')
304
+ assert.ok(!data.age, 'data.age is falsy')
305
+ })
306
+
307
+ test('.update + $select', async () => {
308
+ const originalData = {
309
+ [idProp]: doug[idProp],
310
+ name: 'Dougler',
311
+ age: 10,
312
+ }
313
+
314
+ const data = await service.update(doug[idProp], originalData, {
315
+ query: { $select: ['name'] },
316
+ })
317
+
318
+ assert.strictEqual(
319
+ data[idProp].toString(),
320
+ doug[idProp].toString(),
321
+ `${idProp} id property matches`,
322
+ )
323
+ assert.strictEqual(data.name, 'Dougler', 'data.name matches')
324
+ assert.ok(!data.age, 'data.age is falsy')
325
+ })
326
+
327
+ test('.update + id + query', async () => {
328
+ try {
329
+ await service.update(
330
+ doug[idProp],
331
+ {
332
+ name: 'Dougler',
333
+ },
334
+ {
335
+ query: { name: 'Tester' },
336
+ },
337
+ )
338
+ throw new Error('Should never get here')
339
+ } catch (error: any) {
340
+ assert.strictEqual(
341
+ error.name,
342
+ 'NotFound',
343
+ 'Got a NotFound Feathers error',
344
+ )
345
+ }
346
+ })
347
+
348
+ test('.update + NotFound', async () => {
349
+ try {
350
+ await service.update('568225fbfe21222432e836ff', {
351
+ name: 'NotFound',
352
+ })
353
+ throw new Error('Should never get here')
354
+ } catch (error: any) {
355
+ assert.strictEqual(
356
+ error.name,
357
+ 'NotFound',
358
+ 'Error is a NotFound Feathers error',
359
+ )
360
+ }
361
+ })
362
+
363
+ test('.update + query + NotFound', async () => {
364
+ const dave = await service.create({ name: 'Dave' })
365
+ try {
366
+ await service.update(
367
+ dave[idProp],
368
+ { name: 'UpdatedDave' },
369
+ { query: { name: 'NotDave' } },
370
+ )
371
+ throw new Error('Should never get here')
372
+ } catch (error: any) {
373
+ assert.strictEqual(
374
+ error.name,
375
+ 'NotFound',
376
+ 'Error is a NotFound Feathers error',
377
+ )
378
+ }
379
+ await service.remove(dave[idProp])
380
+ })
381
+
382
+ test('.update + id + query id', async () => {
383
+ const alice = await service.create({
384
+ name: 'Alice',
385
+ age: 12,
386
+ })
387
+
388
+ try {
389
+ await service.update(
390
+ doug[idProp],
391
+ {
392
+ name: 'Dougler',
393
+ age: 33,
394
+ },
395
+ {
396
+ query: { [idProp]: alice[idProp] },
397
+ },
398
+ )
399
+ throw new Error('Should never get here')
400
+ } catch (error: any) {
401
+ assert.strictEqual(
402
+ error.name,
403
+ 'NotFound',
404
+ 'Got a NotFound Feathers error',
405
+ )
406
+ }
407
+
408
+ await service.remove(alice[idProp])
409
+ })
410
+ })
411
+
412
+ describe('patch', () => {
413
+ test('.patch', async () => {
414
+ const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' }
415
+ const originalCopy = Object.assign({}, originalData)
416
+
417
+ const data = await service.patch(doug[idProp], originalData)
418
+
419
+ assert.deepStrictEqual(
420
+ originalData,
421
+ originalCopy,
422
+ 'original data was not modified',
423
+ )
424
+ assert.strictEqual(
425
+ data[idProp].toString(),
426
+ doug[idProp].toString(),
427
+ `${idProp} id matches`,
428
+ )
429
+ assert.strictEqual(data.name, 'PatchDoug', 'data.name matches')
430
+ assert.strictEqual(data.age, 32, 'data.age matches')
431
+ })
432
+
433
+ test('.patch + $select', async () => {
434
+ const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' }
435
+
436
+ const data = await service.patch(doug[idProp], originalData, {
437
+ query: { $select: ['name'] },
438
+ })
439
+
440
+ assert.strictEqual(
441
+ data[idProp].toString(),
442
+ doug[idProp].toString(),
443
+ `${idProp} id property matches`,
444
+ )
445
+ assert.strictEqual(data.name, 'PatchDoug', 'data.name matches')
446
+ assert.ok(!data.age, 'data.age is falsy')
447
+ })
448
+
449
+ test('.patch + id + query', async () => {
450
+ try {
451
+ await service.patch(
452
+ doug[idProp],
453
+ {
454
+ name: 'id patched doug',
455
+ },
456
+ {
457
+ query: { name: 'Tester' },
458
+ },
459
+ )
460
+ throw new Error('Should never get here')
461
+ } catch (error: any) {
462
+ assert.strictEqual(
463
+ error.name,
464
+ 'NotFound',
465
+ 'Got a NotFound Feathers error',
466
+ )
467
+ }
468
+ })
469
+
470
+ test('.patch multiple', async () => {
471
+ try {
472
+ await service.patch(null, {})
473
+ throw new Error('Should never get here')
474
+ } catch (error: any) {
475
+ assert.strictEqual(
476
+ error.name,
477
+ 'MethodNotAllowed',
478
+ 'Removing multiple without option set throws MethodNotAllowed',
479
+ )
480
+ }
481
+
482
+ const params = {
483
+ query: { created: true },
484
+ }
485
+ const dave = await service.create({
486
+ name: 'Dave',
487
+ age: 29,
488
+ created: true,
489
+ })
490
+ const david = await service.create({
491
+ name: 'David',
492
+ age: 3,
493
+ created: true,
494
+ })
495
+
496
+ service.options.multi = ['patch']
497
+
498
+ const data = await service.patch(
499
+ null,
500
+ {
501
+ age: 2,
502
+ },
503
+ params,
504
+ )
505
+
506
+ assert.strictEqual(data.length, 2, 'returned two entries')
507
+ assert.strictEqual(data[0].age, 2, 'First entry age was updated')
508
+ assert.strictEqual(data[1].age, 2, 'Second entry age was updated')
509
+
510
+ await service.remove(dave[idProp])
511
+ await service.remove(david[idProp])
512
+ })
513
+
514
+ test('.patch multiple no pagination', async () => {
515
+ try {
516
+ await service.remove(doug[idProp])
517
+ } catch {
518
+ // Ignore errors
519
+ }
520
+
521
+ const count = 14
522
+ const defaultPaginate = 10
523
+
524
+ assert.ok(
525
+ count > defaultPaginate,
526
+ 'count is bigger than default pagination',
527
+ )
528
+
529
+ const multiBefore = service.options.multi
530
+ const paginateBefore = service.options.paginate
531
+
532
+ let ids: any[] | undefined = undefined
533
+
534
+ try {
535
+ service.options.multi = true
536
+ service.options.paginate = {
537
+ default: defaultPaginate,
538
+ max: 100,
539
+ }
540
+
541
+ const emptyItems = await service.find({ paginate: false })
542
+ assert.strictEqual(emptyItems.length, 0, 'no items before')
543
+
544
+ const createdItems = await service.create(
545
+ Array.from(Array(count)).map((_, i) => ({
546
+ name: `name-${i}`,
547
+ age: 3,
548
+ created: true,
549
+ })),
550
+ )
551
+ assert.strictEqual(
552
+ createdItems.length,
553
+ count,
554
+ `created ${count} items`,
555
+ )
556
+ ids = createdItems.map((item: any) => item[idProp])
557
+
558
+ const foundItems = await service.find({ paginate: false })
559
+ assert.strictEqual(foundItems.length, count, `created ${count} items`)
560
+
561
+ const foundPaginatedItems = await service.find({})
562
+ assert.strictEqual(
563
+ foundPaginatedItems.data.length,
564
+ defaultPaginate,
565
+ 'found paginated data',
566
+ )
567
+
568
+ const allItems = await service.patch(
569
+ null,
570
+ { age: 4 },
571
+ { query: { created: true } },
572
+ )
573
+
574
+ assert.strictEqual(
575
+ allItems.length,
576
+ count,
577
+ `patched all ${count} items`,
578
+ )
579
+ } finally {
580
+ service.options.multi = multiBefore
581
+ service.options.paginate = paginateBefore
582
+ if (ids) {
583
+ await Promise.all(ids.map((id) => service.remove(id)))
584
+ }
585
+ }
586
+ })
587
+
588
+ test('.patch multi query same', async () => {
589
+ const service = app.service(serviceName)
590
+ // @ts-expect-error options may not exist
591
+ const multiBefore = service.options?.multi
592
+
593
+ // @ts-expect-error options may not exist
594
+ service.options ??= {}
595
+
596
+ // @ts-expect-error options may not exist
597
+ service.options.multi = true
598
+
599
+ const params = {
600
+ query: { age: { $lt: 10 } },
601
+ }
602
+ const dave = await service.create({
603
+ name: 'Dave',
604
+ age: 8,
605
+ created: true,
606
+ })
607
+ const david = await service.create({
608
+ name: 'David',
609
+ age: 4,
610
+ created: true,
611
+ })
612
+
613
+ const data = await service.patch(
614
+ null,
615
+ {
616
+ age: 2,
617
+ },
618
+ params,
619
+ )
620
+
621
+ assert.strictEqual(data.length, 2, 'returned two entries')
622
+ assert.strictEqual(data[0].age, 2, 'First entry age was updated')
623
+ assert.strictEqual(data[1].age, 2, 'Second entry age was updated')
624
+
625
+ await service.remove(dave[idProp])
626
+ await service.remove(david[idProp])
627
+
628
+ // @ts-expect-error options may not exist
629
+ service.options.multi = multiBefore
630
+ })
631
+
632
+ test('.patch multi query changed', async () => {
633
+ const service = app.service(serviceName)
634
+ // @ts-expect-error options may not exist
635
+ const multiBefore = service.options.multi
636
+
637
+ // @ts-expect-error options may not exist
638
+ service.options.multi = true
639
+
640
+ const params = {
641
+ query: { age: 10 },
642
+ }
643
+ const dave = await service.create({
644
+ name: 'Dave',
645
+ age: 10,
646
+ created: true,
647
+ })
648
+ const david = await service.create({
649
+ name: 'David',
650
+ age: 10,
651
+ created: true,
652
+ })
653
+
654
+ const data = await service.patch(
655
+ null,
656
+ {
657
+ age: 2,
658
+ },
659
+ params,
660
+ )
661
+
662
+ assert.strictEqual(data.length, 2, 'returned two entries')
663
+ assert.strictEqual(data[0].age, 2, 'First entry age was updated')
664
+ assert.strictEqual(data[1].age, 2, 'Second entry age was updated')
665
+
666
+ await service.remove(dave[idProp])
667
+ await service.remove(david[idProp])
668
+
669
+ // @ts-expect-error options may not exist
670
+ service.options.multi = multiBefore
671
+ })
672
+
673
+ test('.patch + NotFound', async () => {
674
+ try {
675
+ await service.patch('568225fbfe21222432e836ff', {
676
+ name: 'PatchDoug',
677
+ })
678
+ throw new Error('Should never get here')
679
+ } catch (error: any) {
680
+ assert.strictEqual(
681
+ error.name,
682
+ 'NotFound',
683
+ 'Error is a NotFound Feathers error',
684
+ )
685
+ }
686
+ })
687
+
688
+ test('.patch + query + NotFound', async () => {
689
+ const dave = await service.create({ name: 'Dave' })
690
+ try {
691
+ await service.patch(
692
+ dave[idProp],
693
+ { name: 'PatchedDave' },
694
+ { query: { name: 'NotDave' } },
695
+ )
696
+ throw new Error('Should never get here')
697
+ } catch (error: any) {
698
+ assert.strictEqual(
699
+ error.name,
700
+ 'NotFound',
701
+ 'Error is a NotFound Feathers error',
702
+ )
703
+ }
704
+ await service.remove(dave[idProp])
705
+ })
706
+
707
+ test('.patch + id + query id', async () => {
708
+ const alice = await service.create({
709
+ name: 'Alice',
710
+ age: 12,
711
+ })
712
+
713
+ try {
714
+ await service.patch(
715
+ doug[idProp],
716
+ {
717
+ age: 33,
718
+ },
719
+ {
720
+ query: { [idProp]: alice[idProp] },
721
+ },
722
+ )
723
+ throw new Error('Should never get here')
724
+ } catch (error: any) {
725
+ assert.strictEqual(
726
+ error.name,
727
+ 'NotFound',
728
+ 'Got a NotFound Feathers error',
729
+ )
730
+ }
731
+
732
+ await service.remove(alice[idProp])
733
+ })
734
+ })
735
+
736
+ describe('create', () => {
737
+ test('.create', async () => {
738
+ const originalData = {
739
+ name: 'Bill',
740
+ age: 40,
741
+ }
742
+ const originalCopy = Object.assign({}, originalData)
743
+
744
+ const data = await service.create(originalData)
745
+
746
+ assert.deepStrictEqual(
747
+ originalData,
748
+ originalCopy,
749
+ 'original data was not modified',
750
+ )
751
+ assert.ok(data instanceof Object, 'data is an object')
752
+ assert.strictEqual(data.name, 'Bill', 'data.name matches')
753
+
754
+ await service.remove(data[idProp])
755
+ })
756
+
757
+ test('.create ignores query', async () => {
758
+ const originalData = {
759
+ name: 'Billy',
760
+ age: 42,
761
+ }
762
+ const data = await service.create(originalData, {
763
+ query: {
764
+ name: 'Dave',
765
+ },
766
+ })
767
+
768
+ assert.strictEqual(data.name, 'Billy', 'data.name matches')
769
+
770
+ await service.remove(data[idProp])
771
+ })
772
+
773
+ test('.create + $select', async () => {
774
+ const originalData = {
775
+ name: 'William',
776
+ age: 23,
777
+ }
778
+
779
+ const data = await service.create(originalData, {
780
+ query: { $select: ['name'] },
781
+ })
782
+
783
+ assert.ok(idProp in data, 'data has id')
784
+ assert.strictEqual(data.name, 'William', 'data.name matches')
785
+ assert.ok(!data.age, 'data.age is falsy')
786
+
787
+ await service.remove(data[idProp])
788
+ })
789
+
790
+ test('.create multi', async () => {
791
+ try {
792
+ await service.create([], {})
793
+ throw new Error('Should never get here')
794
+ } catch (error: any) {
795
+ assert.strictEqual(
796
+ error.name,
797
+ 'MethodNotAllowed',
798
+ 'Removing multiple without option set throws MethodNotAllowed',
799
+ )
800
+ }
801
+
802
+ const items = [
803
+ {
804
+ name: 'Gerald',
805
+ age: 18,
806
+ },
807
+ {
808
+ name: 'Herald',
809
+ age: 18,
810
+ },
811
+ ]
812
+
813
+ service.options.multi = ['create', 'patch']
814
+
815
+ const data = await service.create(items)
816
+
817
+ assert.ok(Array.isArray(data), 'data is an array')
818
+ assert.ok(typeof data[0][idProp] !== 'undefined', 'id is set')
819
+ assert.strictEqual(data[0].name, 'Gerald', 'first name matches')
820
+ assert.ok(typeof data[1][idProp] !== 'undefined', 'id is set')
821
+ assert.strictEqual(data[1].name, 'Herald', 'second name macthes')
822
+
823
+ await service.remove(data[0][idProp])
824
+ await service.remove(data[1][idProp])
825
+ })
826
+ })
827
+
828
+ describe("doesn't call public methods internally", () => {
829
+ let throwing: any
830
+
831
+ beforeAll(() => {
832
+ throwing = Object.assign(Object.create(app.service(serviceName)), {
833
+ get store() {
834
+ // @ts-expect-error just ignore it for now
835
+ return app.service(serviceName).store
836
+ },
837
+
838
+ find() {
839
+ throw new Error('find method called')
840
+ },
841
+ get() {
842
+ throw new Error('get method called')
843
+ },
844
+ create() {
845
+ throw new Error('create method called')
846
+ },
847
+ update() {
848
+ throw new Error('update method called')
849
+ },
850
+ patch() {
851
+ throw new Error('patch method called')
852
+ },
853
+ remove() {
854
+ throw new Error('remove method called')
855
+ },
856
+ })
857
+ })
858
+
859
+ test('internal .find', () =>
860
+ (app as any).service(serviceName).find.call(throwing))
861
+
862
+ test('internal .get', () => service.get.call(throwing, doug[idProp]))
863
+
864
+ test('internal .create', async () => {
865
+ const bob = await service.create.call(throwing, {
866
+ name: 'Bob',
867
+ age: 25,
868
+ })
869
+
870
+ await service.remove(bob[idProp])
871
+ })
872
+
873
+ test('internal .update', () =>
874
+ service.update.call(throwing, doug[idProp], {
875
+ name: 'Dougler',
876
+ }))
877
+
878
+ test('internal .patch', () =>
879
+ service.patch.call(throwing, doug[idProp], {
880
+ name: 'PatchDoug',
881
+ }))
882
+
883
+ test('internal .remove', () =>
884
+ service.remove.call(throwing, doug[idProp]))
885
+ })
886
+ })
887
+ }