ts-patch-mongoose 3.0.0 → 3.1.0
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/biome.json +2 -5
- package/dist/index.cjs +103 -109
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +103 -109
- package/package.json +6 -6
- package/src/helpers.ts +16 -3
- package/src/hooks/delete-hooks.ts +5 -4
- package/src/hooks/update-hooks.ts +42 -19
- package/src/omit-deep.ts +24 -63
- package/src/patch.ts +28 -31
- package/src/types.ts +1 -0
- package/tests/em.test.ts +24 -8
- package/tests/helpers.test.ts +62 -0
- package/tests/omit-deep.test.ts +25 -10
- package/tests/patch.test.ts +6 -5
- package/tests/plugin-all-features.test.ts +104 -1
- package/tests/plugin-complex-data.test.ts +1315 -0
- package/tests/plugin-event-created.test.ts +10 -10
- package/tests/plugin-event-deleted.test.ts +10 -10
- package/tests/plugin-event-updated.test.ts +9 -9
- package/tests/plugin-global.test.ts +6 -6
- package/tests/plugin-omit-all.test.ts +1 -1
- package/tests/plugin-patch-history-disabled.test.ts +1 -1
- package/tests/plugin-pre-delete.test.ts +8 -8
- package/tests/plugin-pre-save.test.ts +2 -2
- package/tests/plugin.test.ts +3 -3
- package/vite.config.mts +2 -1
|
@@ -35,7 +35,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
afterEach(() => {
|
|
38
|
-
vi.
|
|
38
|
+
vi.resetAllMocks()
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
describe('normal cases', () => {
|
|
@@ -46,7 +46,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
46
46
|
const history = await HistoryModel.find({})
|
|
47
47
|
expect(history).toHaveLength(0)
|
|
48
48
|
|
|
49
|
-
expect(em.emit).
|
|
49
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
50
50
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, {
|
|
51
51
|
doc: expect.objectContaining({
|
|
52
52
|
_id: john._id,
|
|
@@ -70,7 +70,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
70
70
|
const history = await HistoryModel.find({})
|
|
71
71
|
expect(history).toHaveLength(0)
|
|
72
72
|
|
|
73
|
-
expect(em.emit).
|
|
73
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
74
74
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, {
|
|
75
75
|
doc: expect.objectContaining({
|
|
76
76
|
_id: user._id,
|
|
@@ -164,7 +164,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
164
164
|
const history = await HistoryModel.find({})
|
|
165
165
|
expect(history).toHaveLength(0)
|
|
166
166
|
|
|
167
|
-
expect(em.emit).
|
|
167
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
168
168
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, {
|
|
169
169
|
doc: expect.objectContaining({
|
|
170
170
|
_id: user?._id,
|
|
@@ -190,7 +190,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
190
190
|
const history = await HistoryModel.find({})
|
|
191
191
|
expect(history).toHaveLength(0)
|
|
192
192
|
|
|
193
|
-
expect(em.emit).
|
|
193
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
194
194
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, {
|
|
195
195
|
doc: expect.objectContaining({
|
|
196
196
|
_id: user?._id,
|
|
@@ -216,7 +216,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
216
216
|
const history = await HistoryModel.find({})
|
|
217
217
|
expect(history).toHaveLength(0)
|
|
218
218
|
|
|
219
|
-
expect(em.emit).
|
|
219
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
220
220
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, {
|
|
221
221
|
doc: expect.objectContaining({
|
|
222
222
|
_id: user?._id,
|
|
@@ -241,7 +241,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
241
241
|
const history = await HistoryModel.find({})
|
|
242
242
|
expect(history).toHaveLength(0)
|
|
243
243
|
|
|
244
|
-
expect(em.emit).
|
|
244
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
245
245
|
expect(em.emit).toHaveBeenNthCalledWith(1, USER_CREATED, {
|
|
246
246
|
doc: expect.objectContaining({
|
|
247
247
|
_id: users?._id,
|
|
@@ -267,7 +267,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
267
267
|
const history = await HistoryModel.find({})
|
|
268
268
|
expect(history).toHaveLength(0)
|
|
269
269
|
|
|
270
|
-
expect(em.emit).
|
|
270
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
271
271
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, {
|
|
272
272
|
doc: expect.objectContaining({
|
|
273
273
|
_id: user?._id,
|
|
@@ -293,7 +293,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
293
293
|
const history = await HistoryModel.find({})
|
|
294
294
|
expect(history).toHaveLength(0)
|
|
295
295
|
|
|
296
|
-
expect(em.emit).
|
|
296
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
297
297
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, {
|
|
298
298
|
doc: expect.objectContaining({
|
|
299
299
|
_id: user?._id,
|
|
@@ -320,7 +320,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
320
320
|
const history = await HistoryModel.find({})
|
|
321
321
|
expect(history).toHaveLength(0)
|
|
322
322
|
|
|
323
|
-
expect(em.emit).
|
|
323
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
324
324
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, {
|
|
325
325
|
doc: expect.objectContaining({
|
|
326
326
|
_id: user?._id,
|
|
@@ -35,7 +35,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
35
35
|
await mongoose.connection.collection('history').deleteMany({})
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
-
afterEach(
|
|
38
|
+
afterEach(() => {
|
|
39
39
|
vi.resetAllMocks()
|
|
40
40
|
})
|
|
41
41
|
|
|
@@ -52,7 +52,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
52
52
|
const history = await HistoryModel.find({})
|
|
53
53
|
expect(history).toHaveLength(0)
|
|
54
54
|
|
|
55
|
-
expect(em.emit).
|
|
55
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
56
56
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
57
57
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
58
58
|
})
|
|
@@ -119,7 +119,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
119
119
|
const history = await HistoryModel.find({})
|
|
120
120
|
expect(history).toHaveLength(0)
|
|
121
121
|
|
|
122
|
-
expect(em.emit).
|
|
122
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
123
123
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
124
124
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
125
125
|
})
|
|
@@ -146,7 +146,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
146
146
|
const history = await HistoryModel.find({})
|
|
147
147
|
expect(history).toHaveLength(0)
|
|
148
148
|
|
|
149
|
-
expect(em.emit).
|
|
149
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
150
150
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
151
151
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
152
152
|
})
|
|
@@ -178,7 +178,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
178
178
|
const history = await HistoryModel.find({})
|
|
179
179
|
expect(history).toHaveLength(0)
|
|
180
180
|
|
|
181
|
-
expect(em.emit).
|
|
181
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
182
182
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
183
183
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
184
184
|
})
|
|
@@ -205,7 +205,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
205
205
|
const history = await HistoryModel.find({})
|
|
206
206
|
expect(history).toHaveLength(0)
|
|
207
207
|
|
|
208
|
-
expect(em.emit).
|
|
208
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
209
209
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
210
210
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
211
211
|
})
|
|
@@ -237,7 +237,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
237
237
|
const history = await HistoryModel.find({})
|
|
238
238
|
expect(history).toHaveLength(0)
|
|
239
239
|
|
|
240
|
-
expect(em.emit).
|
|
240
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
241
241
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
242
242
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
243
243
|
})
|
|
@@ -264,7 +264,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
264
264
|
const history = await HistoryModel.find({})
|
|
265
265
|
expect(history).toHaveLength(0)
|
|
266
266
|
|
|
267
|
-
expect(em.emit).
|
|
267
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
268
268
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
269
269
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
270
270
|
})
|
|
@@ -328,7 +328,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
328
328
|
const history = await HistoryModel.find({})
|
|
329
329
|
expect(history).toHaveLength(0)
|
|
330
330
|
|
|
331
|
-
expect(em.emit).
|
|
331
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
332
332
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
333
333
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
334
334
|
})
|
|
@@ -354,7 +354,7 @@ describe('plugin - event delete & patch history disabled', () => {
|
|
|
354
354
|
const history = await HistoryModel.find({})
|
|
355
355
|
expect(history).toHaveLength(0)
|
|
356
356
|
|
|
357
|
-
expect(em.emit).
|
|
357
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
358
358
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
359
359
|
oldDoc: expect.objectContaining(john.toObject(toObjectOptions)),
|
|
360
360
|
})
|
|
@@ -35,7 +35,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
35
35
|
await mongoose.connection.collection('history').deleteMany({})
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
-
afterEach(
|
|
38
|
+
afterEach(() => {
|
|
39
39
|
vi.resetAllMocks()
|
|
40
40
|
})
|
|
41
41
|
|
|
@@ -50,7 +50,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
50
50
|
const history = await HistoryModel.find({})
|
|
51
51
|
expect(history).toHaveLength(0)
|
|
52
52
|
|
|
53
|
-
expect(em.emit).
|
|
53
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
54
54
|
|
|
55
55
|
expect(em.emit).toHaveBeenCalledWith(USER_UPDATED, {
|
|
56
56
|
oldDoc: expect.objectContaining({
|
|
@@ -134,7 +134,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
134
134
|
const history = await HistoryModel.find({})
|
|
135
135
|
expect(history).toHaveLength(0)
|
|
136
136
|
|
|
137
|
-
expect(em.emit).
|
|
137
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
138
138
|
|
|
139
139
|
// Confirm that the document is updated
|
|
140
140
|
const updated = await UserModel.find({}).sort({ name: 1 })
|
|
@@ -162,7 +162,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
162
162
|
const history = await HistoryModel.find({})
|
|
163
163
|
expect(history).toHaveLength(0)
|
|
164
164
|
|
|
165
|
-
expect(em.emit).
|
|
165
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
166
166
|
expect(em.emit).toHaveBeenCalledWith(USER_UPDATED, {
|
|
167
167
|
oldDoc: expect.objectContaining({
|
|
168
168
|
__v: 0,
|
|
@@ -235,7 +235,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
235
235
|
const history = await HistoryModel.find({})
|
|
236
236
|
expect(history).toHaveLength(0)
|
|
237
237
|
|
|
238
|
-
expect(em.emit).
|
|
238
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
239
239
|
expect(em.emit).toHaveBeenCalledWith(USER_UPDATED, {
|
|
240
240
|
oldDoc: expect.objectContaining({
|
|
241
241
|
__v: 0,
|
|
@@ -274,7 +274,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
274
274
|
const history = await HistoryModel.find({})
|
|
275
275
|
expect(history).toHaveLength(0)
|
|
276
276
|
|
|
277
|
-
expect(em.emit).
|
|
277
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
278
278
|
expect(em.emit).toHaveBeenCalledWith(USER_UPDATED, {
|
|
279
279
|
oldDoc: expect.objectContaining({
|
|
280
280
|
__v: 0,
|
|
@@ -312,7 +312,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
312
312
|
const history = await HistoryModel.find({})
|
|
313
313
|
expect(history).toHaveLength(0)
|
|
314
314
|
|
|
315
|
-
expect(em.emit).
|
|
315
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
316
316
|
expect(em.emit).toHaveBeenCalledWith(USER_UPDATED, {
|
|
317
317
|
oldDoc: expect.objectContaining({
|
|
318
318
|
__v: 0,
|
|
@@ -352,7 +352,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
352
352
|
const history = await HistoryModel.find({})
|
|
353
353
|
expect(history).toHaveLength(0)
|
|
354
354
|
|
|
355
|
-
expect(em.emit).
|
|
355
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
356
356
|
expect(em.emit).toHaveBeenCalledWith(USER_UPDATED, {
|
|
357
357
|
oldDoc: expect.objectContaining({
|
|
358
358
|
__v: 0,
|
|
@@ -458,7 +458,7 @@ describe('plugin - event updated & patch history disabled', () => {
|
|
|
458
458
|
const history = await HistoryModel.find({})
|
|
459
459
|
expect(history).toHaveLength(0)
|
|
460
460
|
|
|
461
|
-
expect(em.emit).
|
|
461
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
462
462
|
expect(em.emit).toHaveBeenCalledWith(USER_UPDATED, {
|
|
463
463
|
oldDoc: expect.objectContaining({
|
|
464
464
|
__v: 0,
|
|
@@ -38,8 +38,8 @@ describe('plugin - global', () => {
|
|
|
38
38
|
await mongoose.connection.collection('history').deleteMany({})
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
-
afterEach(
|
|
42
|
-
vi.
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
vi.resetAllMocks()
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
it('should save array', async () => {
|
|
@@ -477,8 +477,8 @@ describe('plugin - global', () => {
|
|
|
477
477
|
expect(second.doc).toHaveProperty('_id', alice._id)
|
|
478
478
|
expect(second.doc).toHaveProperty('name', 'Alice')
|
|
479
479
|
expect(second.doc).toHaveProperty('role', 'user')
|
|
480
|
-
expect(
|
|
481
|
-
expect(
|
|
480
|
+
expect(second.doc).not.toHaveProperty('createdAt')
|
|
481
|
+
expect(second.doc).not.toHaveProperty('updatedAt')
|
|
482
482
|
|
|
483
483
|
expect(second.patch).toHaveLength(0)
|
|
484
484
|
|
|
@@ -492,8 +492,8 @@ describe('plugin - global', () => {
|
|
|
492
492
|
expect(third.doc).toHaveProperty('_id', product._id)
|
|
493
493
|
expect(third.doc).toHaveProperty('name', 'paper')
|
|
494
494
|
expect(third.doc).toHaveProperty('addedBy', john._id)
|
|
495
|
-
expect(
|
|
496
|
-
expect(
|
|
495
|
+
expect(third.doc).not.toHaveProperty('createdAt')
|
|
496
|
+
expect(third.doc).not.toHaveProperty('updatedAt')
|
|
497
497
|
|
|
498
498
|
expect(third.patch).toHaveLength(0)
|
|
499
499
|
|
|
@@ -36,7 +36,7 @@ describe('plugin - preDelete test', () => {
|
|
|
36
36
|
await mongoose.connection.collection('history').deleteMany({})
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
afterEach(
|
|
39
|
+
afterEach(() => {
|
|
40
40
|
vi.resetAllMocks()
|
|
41
41
|
})
|
|
42
42
|
|
|
@@ -45,13 +45,13 @@ describe('plugin - preDelete test', () => {
|
|
|
45
45
|
await UserModel.create({ name: 'Jane', role: 'user' })
|
|
46
46
|
await UserModel.create({ name: 'Jack', role: 'user' })
|
|
47
47
|
|
|
48
|
-
const users = await UserModel.find({}).sort().lean().exec()
|
|
48
|
+
const users = await UserModel.find({}).sort({ _id: 1 }).lean().exec()
|
|
49
49
|
expect(users).toHaveLength(3)
|
|
50
50
|
|
|
51
51
|
const [john, jane, jack] = users
|
|
52
52
|
|
|
53
53
|
await UserModel.deleteMany({ role: 'user' })
|
|
54
|
-
expect(preDeleteMock).
|
|
54
|
+
expect(preDeleteMock).toHaveBeenCalledOnce()
|
|
55
55
|
expect(preDeleteMock).toHaveBeenCalledWith([john, jane, jack])
|
|
56
56
|
|
|
57
57
|
expect(em.emit).toHaveBeenCalledTimes(3)
|
|
@@ -92,13 +92,13 @@ describe('plugin - preDelete test', () => {
|
|
|
92
92
|
await UserModel.create({ name: 'Jane', role: 'user' })
|
|
93
93
|
await UserModel.create({ name: 'Jack', role: 'user' })
|
|
94
94
|
|
|
95
|
-
const users = await UserModel.find({}).sort().lean().exec()
|
|
95
|
+
const users = await UserModel.find({}).sort({ _id: 1 }).lean().exec()
|
|
96
96
|
expect(users).toHaveLength(3)
|
|
97
97
|
|
|
98
98
|
const [john] = users
|
|
99
99
|
|
|
100
100
|
await UserModel.deleteOne({ name: 'John' })
|
|
101
|
-
expect(preDeleteMock).
|
|
101
|
+
expect(preDeleteMock).toHaveBeenCalledOnce()
|
|
102
102
|
expect(preDeleteMock).toHaveBeenCalledWith([
|
|
103
103
|
{
|
|
104
104
|
__v: 0,
|
|
@@ -110,7 +110,7 @@ describe('plugin - preDelete test', () => {
|
|
|
110
110
|
},
|
|
111
111
|
])
|
|
112
112
|
|
|
113
|
-
expect(em.emit).
|
|
113
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
114
114
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
115
115
|
oldDoc: {
|
|
116
116
|
__v: 0,
|
|
@@ -133,7 +133,7 @@ describe('plugin - preDelete test', () => {
|
|
|
133
133
|
await john?.deleteOne()
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
expect(preDeleteMock).
|
|
136
|
+
expect(preDeleteMock).toHaveBeenCalledOnce()
|
|
137
137
|
expect(preDeleteMock).toHaveBeenCalledWith([
|
|
138
138
|
{
|
|
139
139
|
__v: 0,
|
|
@@ -145,7 +145,7 @@ describe('plugin - preDelete test', () => {
|
|
|
145
145
|
},
|
|
146
146
|
])
|
|
147
147
|
|
|
148
|
-
expect(em.emit).
|
|
148
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
149
149
|
expect(em.emit).toHaveBeenCalledWith(USER_DELETED, {
|
|
150
150
|
oldDoc: {
|
|
151
151
|
__v: 0,
|
|
@@ -32,7 +32,7 @@ describe('plugin - preSave test', () => {
|
|
|
32
32
|
await mongoose.connection.collection('history').deleteMany({})
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
afterEach(
|
|
35
|
+
afterEach(() => {
|
|
36
36
|
vi.resetAllMocks()
|
|
37
37
|
})
|
|
38
38
|
|
|
@@ -40,7 +40,7 @@ describe('plugin - preSave test', () => {
|
|
|
40
40
|
const john = await UserModel.create({ name: 'John', role: 'user' })
|
|
41
41
|
const { __v, role, ...doc } = john.toJSON()
|
|
42
42
|
|
|
43
|
-
expect(em.emit).
|
|
43
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
44
44
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, { doc })
|
|
45
45
|
|
|
46
46
|
expect(john).toMatchObject({ name: 'John', role: 'user' })
|
package/tests/plugin.test.ts
CHANGED
|
@@ -36,7 +36,7 @@ describe('plugin', () => {
|
|
|
36
36
|
await mongoose.connection.collection('history').deleteMany({})
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
afterEach(
|
|
39
|
+
afterEach(() => {
|
|
40
40
|
vi.resetAllMocks()
|
|
41
41
|
})
|
|
42
42
|
|
|
@@ -161,7 +161,7 @@ describe('plugin', () => {
|
|
|
161
161
|
|
|
162
162
|
expect(first.patch).toHaveLength(0)
|
|
163
163
|
|
|
164
|
-
expect(em.emit).
|
|
164
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
165
165
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, { doc: first.doc })
|
|
166
166
|
// no update event emitted because role is omitted
|
|
167
167
|
})
|
|
@@ -480,7 +480,7 @@ describe('plugin', () => {
|
|
|
480
480
|
|
|
481
481
|
expect(first.patch).toHaveLength(0)
|
|
482
482
|
|
|
483
|
-
expect(em.emit).
|
|
483
|
+
expect(em.emit).toHaveBeenCalledOnce()
|
|
484
484
|
expect(em.emit).toHaveBeenCalledWith(USER_CREATED, { doc: first.doc })
|
|
485
485
|
// updated event is not emitted because it's an upsert
|
|
486
486
|
})
|