ts-patch-mongoose 2.7.0 → 2.8.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 +1 -1
- package/dist/cjs/helpers.js +7 -7
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/hooks/delete-hooks.js.map +1 -1
- package/dist/cjs/hooks/save-hooks.js.map +1 -1
- package/dist/cjs/hooks/update-hooks.js.map +1 -1
- package/dist/cjs/models/History.js +5 -5
- package/dist/cjs/models/History.js.map +1 -1
- package/dist/cjs/patch.js +4 -4
- package/dist/cjs/patch.js.map +1 -1
- package/dist/cjs/plugin.js.map +1 -1
- package/dist/cjs/types/helpers.d.ts +2 -1
- package/dist/cjs/types/helpers.d.ts.map +1 -1
- package/dist/cjs/types/hooks/delete-hooks.d.ts +2 -2
- package/dist/cjs/types/hooks/delete-hooks.d.ts.map +1 -1
- package/dist/cjs/types/hooks/save-hooks.d.ts +2 -2
- package/dist/cjs/types/hooks/save-hooks.d.ts.map +1 -1
- package/dist/cjs/types/hooks/update-hooks.d.ts +2 -2
- package/dist/cjs/types/hooks/update-hooks.d.ts.map +1 -1
- package/dist/cjs/types/models/History.d.ts +6 -6
- package/dist/cjs/types/models/History.d.ts.map +1 -1
- package/dist/cjs/types/patch.d.ts +12 -15
- package/dist/cjs/types/patch.d.ts.map +1 -1
- package/dist/cjs/types/plugin.d.ts +2 -2
- package/dist/cjs/types/plugin.d.ts.map +1 -1
- package/dist/cjs/types/types.d.ts +49 -0
- package/dist/cjs/types/types.d.ts.map +1 -0
- package/dist/cjs/{interfaces/IEvent.js → types.js} +1 -1
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/helpers.js +7 -7
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/hooks/delete-hooks.js.map +1 -1
- package/dist/esm/hooks/save-hooks.js.map +1 -1
- package/dist/esm/hooks/update-hooks.js.map +1 -1
- package/dist/esm/models/History.js +2 -3
- package/dist/esm/models/History.js.map +1 -1
- package/dist/esm/patch.js +4 -4
- package/dist/esm/patch.js.map +1 -1
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/types/helpers.d.ts +2 -1
- package/dist/esm/types/helpers.d.ts.map +1 -1
- package/dist/esm/types/hooks/delete-hooks.d.ts +2 -2
- package/dist/esm/types/hooks/delete-hooks.d.ts.map +1 -1
- package/dist/esm/types/hooks/save-hooks.d.ts +2 -2
- package/dist/esm/types/hooks/save-hooks.d.ts.map +1 -1
- package/dist/esm/types/hooks/update-hooks.d.ts +2 -2
- package/dist/esm/types/hooks/update-hooks.d.ts.map +1 -1
- package/dist/esm/types/models/History.d.ts +6 -6
- package/dist/esm/types/models/History.d.ts.map +1 -1
- package/dist/esm/types/patch.d.ts +12 -15
- package/dist/esm/types/patch.d.ts.map +1 -1
- package/dist/esm/types/plugin.d.ts +2 -2
- package/dist/esm/types/plugin.d.ts.map +1 -1
- package/dist/esm/types/types.d.ts +49 -0
- package/dist/esm/types/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +7 -10
- package/src/helpers.ts +8 -8
- package/src/hooks/delete-hooks.ts +4 -5
- package/src/hooks/save-hooks.ts +3 -4
- package/src/hooks/update-hooks.ts +4 -5
- package/src/models/History.ts +3 -5
- package/src/patch.ts +17 -21
- package/src/plugin.ts +25 -9
- package/src/types.ts +52 -0
- package/tests/helpers.test.ts +5 -6
- package/tests/patch.test.ts +21 -26
- package/tests/plugin-event-created.test.ts +50 -51
- package/tests/plugin-event-deleted.test.ts +76 -77
- package/tests/plugin-event-updated.test.ts +65 -67
- package/tests/plugin-global.test.ts +24 -25
- package/tests/plugin-omit-all.test.ts +36 -37
- package/tests/plugin-patch-history-disabled.test.ts +36 -37
- package/tests/plugin-pre-delete.test.ts +17 -18
- package/tests/plugin-pre-save.test.ts +6 -7
- package/tests/plugin.test.ts +37 -39
- package/tests/schemas/{DescriptionSchema.ts → Description.ts} +4 -4
- package/tests/schemas/{ProductSchema.ts → Product.ts} +12 -5
- package/tests/schemas/{UserSchema.ts → User.ts} +7 -4
- package/.swcrc +0 -17
- package/dist/cjs/interfaces/IContext.js +0 -3
- package/dist/cjs/interfaces/IContext.js.map +0 -1
- package/dist/cjs/interfaces/IEvent.js.map +0 -1
- package/dist/cjs/interfaces/IHistory.js +0 -3
- package/dist/cjs/interfaces/IHistory.js.map +0 -1
- package/dist/cjs/interfaces/IHookContext.js +0 -3
- package/dist/cjs/interfaces/IHookContext.js.map +0 -1
- package/dist/cjs/interfaces/IPluginOptions.js +0 -3
- package/dist/cjs/interfaces/IPluginOptions.js.map +0 -1
- package/dist/cjs/types/interfaces/IContext.d.ts +0 -13
- package/dist/cjs/types/interfaces/IContext.d.ts.map +0 -1
- package/dist/cjs/types/interfaces/IEvent.d.ts +0 -9
- package/dist/cjs/types/interfaces/IEvent.d.ts.map +0 -1
- package/dist/cjs/types/interfaces/IHistory.d.ts +0 -16
- package/dist/cjs/types/interfaces/IHistory.d.ts.map +0 -1
- package/dist/cjs/types/interfaces/IHookContext.d.ts +0 -8
- package/dist/cjs/types/interfaces/IHookContext.d.ts.map +0 -1
- package/dist/cjs/types/interfaces/IPluginOptions.d.ts +0 -18
- package/dist/cjs/types/interfaces/IPluginOptions.d.ts.map +0 -1
- package/dist/esm/interfaces/IContext.js +0 -2
- package/dist/esm/interfaces/IContext.js.map +0 -1
- package/dist/esm/interfaces/IEvent.js +0 -2
- package/dist/esm/interfaces/IEvent.js.map +0 -1
- package/dist/esm/interfaces/IHistory.js +0 -2
- package/dist/esm/interfaces/IHistory.js.map +0 -1
- package/dist/esm/interfaces/IHookContext.js +0 -2
- package/dist/esm/interfaces/IHookContext.js.map +0 -1
- package/dist/esm/interfaces/IPluginOptions.js +0 -2
- package/dist/esm/interfaces/IPluginOptions.js.map +0 -1
- package/dist/esm/types/interfaces/IContext.d.ts +0 -13
- package/dist/esm/types/interfaces/IContext.d.ts.map +0 -1
- package/dist/esm/types/interfaces/IEvent.d.ts +0 -9
- package/dist/esm/types/interfaces/IEvent.d.ts.map +0 -1
- package/dist/esm/types/interfaces/IHistory.d.ts +0 -16
- package/dist/esm/types/interfaces/IHistory.d.ts.map +0 -1
- package/dist/esm/types/interfaces/IHookContext.d.ts +0 -8
- package/dist/esm/types/interfaces/IHookContext.d.ts.map +0 -1
- package/dist/esm/types/interfaces/IPluginOptions.d.ts +0 -18
- package/dist/esm/types/interfaces/IPluginOptions.d.ts.map +0 -1
- package/src/interfaces/IContext.ts +0 -14
- package/src/interfaces/IEvent.ts +0 -10
- package/src/interfaces/IHistory.ts +0 -17
- package/src/interfaces/IHookContext.ts +0 -6
- package/src/interfaces/IPluginOptions.ts +0 -20
- package/tests/interfaces/IDescription.ts +0 -5
- package/tests/interfaces/IProduct.ts +0 -14
- package/tests/interfaces/IUser.ts +0 -8
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
-
|
|
3
1
|
import mongoose, { Types, model } from 'mongoose'
|
|
4
|
-
import {
|
|
2
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
3
|
|
|
6
|
-
import History from '../src/models/History'
|
|
7
4
|
import { patchHistoryPlugin } from '../src/plugin'
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import { USER_CREATED } from './constants/events'
|
|
5
|
+
import { isMongooseLessThan7 } from '../src/version'
|
|
11
6
|
|
|
12
7
|
import em from '../src/em'
|
|
8
|
+
import { USER_CREATED } from './constants/events'
|
|
13
9
|
import server from './mongo/server'
|
|
14
10
|
|
|
11
|
+
import { HistoryModel } from '../src/models/History'
|
|
12
|
+
import { type User, UserSchema } from './schemas/User'
|
|
13
|
+
|
|
15
14
|
vi.mock('../src/em', () => ({ default: { emit: vi.fn((event: string, data: Record<string, unknown>) => console.log(event, data)) } }))
|
|
16
15
|
|
|
17
16
|
describe('plugin - event created & patch history disabled', () => {
|
|
@@ -22,7 +21,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
22
21
|
patchHistoryDisabled: true,
|
|
23
22
|
})
|
|
24
23
|
|
|
25
|
-
const
|
|
24
|
+
const UserModel = model<User>('User', UserSchema)
|
|
26
25
|
|
|
27
26
|
beforeAll(async () => {
|
|
28
27
|
await instance.create()
|
|
@@ -43,10 +42,10 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
43
42
|
|
|
44
43
|
describe('normal cases', () => {
|
|
45
44
|
it('should save() and emit one create event', async () => {
|
|
46
|
-
const john = new
|
|
45
|
+
const john = new UserModel({ name: 'John', role: 'user' })
|
|
47
46
|
await john.save()
|
|
48
47
|
|
|
49
|
-
const history = await
|
|
48
|
+
const history = await HistoryModel.find({})
|
|
50
49
|
expect(history).toHaveLength(0)
|
|
51
50
|
|
|
52
51
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -61,16 +60,16 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
61
60
|
})
|
|
62
61
|
|
|
63
62
|
// Check if the document is saved
|
|
64
|
-
const found = await
|
|
63
|
+
const found = await UserModel.findOne({})
|
|
65
64
|
expect(found).not.toBeNull()
|
|
66
65
|
expect(found?.name).toBe('John')
|
|
67
66
|
expect(found?.role).toBe('user')
|
|
68
67
|
})
|
|
69
68
|
|
|
70
69
|
it('should create() and emit one create event', async () => {
|
|
71
|
-
const user = await
|
|
70
|
+
const user = await UserModel.create({ name: 'John', role: 'user' })
|
|
72
71
|
|
|
73
|
-
const history = await
|
|
72
|
+
const history = await HistoryModel.find({})
|
|
74
73
|
expect(history).toHaveLength(0)
|
|
75
74
|
|
|
76
75
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -85,14 +84,14 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
85
84
|
})
|
|
86
85
|
|
|
87
86
|
// Check if the document is saved
|
|
88
|
-
const found = await
|
|
87
|
+
const found = await UserModel.findOne({})
|
|
89
88
|
expect(found).not.toBeNull()
|
|
90
89
|
expect(found?.name).toBe('John')
|
|
91
90
|
expect(found?.role).toBe('user')
|
|
92
91
|
})
|
|
93
92
|
|
|
94
93
|
it('should insertMany() and emit three create events', async () => {
|
|
95
|
-
const users = await
|
|
94
|
+
const users = await UserModel.insertMany(
|
|
96
95
|
[
|
|
97
96
|
{ name: 'John', role: 'user' },
|
|
98
97
|
{ name: 'Alice', role: 'user' },
|
|
@@ -103,7 +102,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
103
102
|
|
|
104
103
|
const [john, alice, bob] = users
|
|
105
104
|
|
|
106
|
-
const history = await
|
|
105
|
+
const history = await HistoryModel.find({})
|
|
107
106
|
expect(history).toHaveLength(0)
|
|
108
107
|
|
|
109
108
|
expect(em.emit).toHaveBeenCalledTimes(3)
|
|
@@ -136,7 +135,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
136
135
|
})
|
|
137
136
|
|
|
138
137
|
// Check if the documents are saved
|
|
139
|
-
const found = await
|
|
138
|
+
const found = await UserModel.find({})
|
|
140
139
|
expect(found).toHaveLength(3)
|
|
141
140
|
|
|
142
141
|
const [foundJohn, foundAlice, foundBob] = found
|
|
@@ -156,15 +155,15 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
156
155
|
it('should update() + upsert and emit one create event', async () => {
|
|
157
156
|
if (isMongooseLessThan7) {
|
|
158
157
|
// @ts-expect-error update() not available in Mongoose v6 and below
|
|
159
|
-
await
|
|
158
|
+
await UserModel.update({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
|
|
160
159
|
} else {
|
|
161
|
-
await
|
|
160
|
+
await UserModel.findOneAndUpdate({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
|
|
162
161
|
}
|
|
163
162
|
|
|
164
|
-
const user = await
|
|
163
|
+
const user = await UserModel.findOne({ name: 'John', role: 'admin' })
|
|
165
164
|
expect(user).not.toBeNull()
|
|
166
165
|
|
|
167
|
-
const history = await
|
|
166
|
+
const history = await HistoryModel.find({})
|
|
168
167
|
expect(history).toHaveLength(0)
|
|
169
168
|
|
|
170
169
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -178,19 +177,19 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
178
177
|
})
|
|
179
178
|
|
|
180
179
|
// Check if the document is saved
|
|
181
|
-
const found = await
|
|
180
|
+
const found = await UserModel.findOne({})
|
|
182
181
|
expect(found).not.toBeNull()
|
|
183
182
|
expect(found?.name).toBe('John')
|
|
184
183
|
expect(found?.role).toBe('admin')
|
|
185
184
|
})
|
|
186
185
|
|
|
187
186
|
it('should updateOne() + upsert and emit one create event', async () => {
|
|
188
|
-
await
|
|
187
|
+
await UserModel.updateOne({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
|
|
189
188
|
|
|
190
|
-
const user = await
|
|
189
|
+
const user = await UserModel.findOne({ name: 'John', role: 'admin' })
|
|
191
190
|
expect(user).not.toBeNull()
|
|
192
191
|
|
|
193
|
-
const history = await
|
|
192
|
+
const history = await HistoryModel.find({})
|
|
194
193
|
expect(history).toHaveLength(0)
|
|
195
194
|
|
|
196
195
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -204,19 +203,19 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
204
203
|
})
|
|
205
204
|
|
|
206
205
|
// Check if the document is saved
|
|
207
|
-
const found = await
|
|
206
|
+
const found = await UserModel.findOne({})
|
|
208
207
|
expect(found).not.toBeNull()
|
|
209
208
|
expect(found?.name).toBe('John')
|
|
210
209
|
expect(found?.role).toBe('admin')
|
|
211
210
|
})
|
|
212
211
|
|
|
213
212
|
it('should replaceOne() + upsert and emit one create event', async () => {
|
|
214
|
-
await
|
|
213
|
+
await UserModel.replaceOne({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
|
|
215
214
|
|
|
216
|
-
const user = await
|
|
215
|
+
const user = await UserModel.findOne({ name: 'John', role: 'admin' })
|
|
217
216
|
expect(user).not.toBeNull()
|
|
218
217
|
|
|
219
|
-
const history = await
|
|
218
|
+
const history = await HistoryModel.find({})
|
|
220
219
|
expect(history).toHaveLength(0)
|
|
221
220
|
|
|
222
221
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -230,18 +229,18 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
230
229
|
})
|
|
231
230
|
|
|
232
231
|
// Check if the document is saved
|
|
233
|
-
const found = await
|
|
232
|
+
const found = await UserModel.findOne({})
|
|
234
233
|
expect(found).not.toBeNull()
|
|
235
234
|
expect(found?.name).toBe('John')
|
|
236
235
|
expect(found?.role).toBe('admin')
|
|
237
236
|
})
|
|
238
237
|
|
|
239
238
|
it('should updateMany() + upsert and emit one create event', async () => {
|
|
240
|
-
await
|
|
239
|
+
await UserModel.updateMany({ name: { $in: ['John', 'Alice', 'Bob'] } }, { name: 'Steve', role: 'admin' }, { upsert: true })
|
|
241
240
|
|
|
242
|
-
const users = await
|
|
241
|
+
const users = await UserModel.findOne({ name: 'Steve', role: 'admin' })
|
|
243
242
|
|
|
244
|
-
const history = await
|
|
243
|
+
const history = await HistoryModel.find({})
|
|
245
244
|
expect(history).toHaveLength(0)
|
|
246
245
|
|
|
247
246
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -255,19 +254,19 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
255
254
|
})
|
|
256
255
|
|
|
257
256
|
// Check if the document is saved
|
|
258
|
-
const found = await
|
|
257
|
+
const found = await UserModel.findById(users?._id)
|
|
259
258
|
expect(found).not.toBeNull()
|
|
260
259
|
expect(found?.name).toBe('Steve')
|
|
261
260
|
expect(found?.role).toBe('admin')
|
|
262
261
|
})
|
|
263
262
|
|
|
264
263
|
it('should findOneAndUpdate() + upsert and emit one create event', async () => {
|
|
265
|
-
await
|
|
264
|
+
await UserModel.findOneAndUpdate({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
|
|
266
265
|
|
|
267
|
-
const user = await
|
|
266
|
+
const user = await UserModel.findOne({ name: 'John', role: 'admin' })
|
|
268
267
|
expect(user).not.toBeNull()
|
|
269
268
|
|
|
270
|
-
const history = await
|
|
269
|
+
const history = await HistoryModel.find({})
|
|
271
270
|
expect(history).toHaveLength(0)
|
|
272
271
|
|
|
273
272
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -281,19 +280,19 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
281
280
|
})
|
|
282
281
|
|
|
283
282
|
// Check if the document is saved
|
|
284
|
-
const found = await
|
|
283
|
+
const found = await UserModel.findOne({})
|
|
285
284
|
expect(found).not.toBeNull()
|
|
286
285
|
expect(found?.name).toBe('John')
|
|
287
286
|
expect(found?.role).toBe('admin')
|
|
288
287
|
})
|
|
289
288
|
|
|
290
289
|
it('should findOneAndReplace() + upsert and emit one create event', async () => {
|
|
291
|
-
await
|
|
290
|
+
await UserModel.findOneAndReplace({ name: 'John' }, { name: 'John', role: 'admin' }, { upsert: true })
|
|
292
291
|
|
|
293
|
-
const user = await
|
|
292
|
+
const user = await UserModel.findOne({ name: 'John', role: 'admin' })
|
|
294
293
|
expect(user).not.toBeNull()
|
|
295
294
|
|
|
296
|
-
const history = await
|
|
295
|
+
const history = await HistoryModel.find({})
|
|
297
296
|
expect(history).toHaveLength(0)
|
|
298
297
|
|
|
299
298
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -307,7 +306,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
307
306
|
})
|
|
308
307
|
|
|
309
308
|
// Check if the document is saved
|
|
310
|
-
const found = await
|
|
309
|
+
const found = await UserModel.findOne({})
|
|
311
310
|
expect(found).not.toBeNull()
|
|
312
311
|
expect(found?.name).toBe('John')
|
|
313
312
|
expect(found?.role).toBe('admin')
|
|
@@ -315,12 +314,12 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
315
314
|
|
|
316
315
|
it('should findByIdAndUpdate() + upsert and emit one create event', async () => {
|
|
317
316
|
const _id = new Types.ObjectId()
|
|
318
|
-
await
|
|
317
|
+
await UserModel.findByIdAndUpdate(_id, { name: 'John', role: 'admin' }, { upsert: true })
|
|
319
318
|
|
|
320
|
-
const user = await
|
|
319
|
+
const user = await UserModel.findOne({ name: 'John', role: 'admin' })
|
|
321
320
|
expect(user).not.toBeNull()
|
|
322
321
|
|
|
323
|
-
const history = await
|
|
322
|
+
const history = await HistoryModel.find({})
|
|
324
323
|
expect(history).toHaveLength(0)
|
|
325
324
|
|
|
326
325
|
expect(em.emit).toHaveBeenCalledTimes(1)
|
|
@@ -333,7 +332,7 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
333
332
|
})
|
|
334
333
|
|
|
335
334
|
// Check if the document is saved
|
|
336
|
-
const found = await
|
|
335
|
+
const found = await UserModel.findOne({})
|
|
337
336
|
expect(found).not.toBeNull()
|
|
338
337
|
expect(found?.name).toBe('John')
|
|
339
338
|
expect(found?.role).toBe('admin')
|
|
@@ -341,19 +340,19 @@ describe('plugin - event created & patch history disabled', () => {
|
|
|
341
340
|
|
|
342
341
|
it('should findOneAndUpdate() with $set + upsert and emit one create event', async () => {
|
|
343
342
|
const _id = new Types.ObjectId()
|
|
344
|
-
const john = await
|
|
343
|
+
const john = await UserModel.create({ _id, name: 'John', role: 'admin' })
|
|
345
344
|
|
|
346
345
|
if (isMongooseLessThan7) {
|
|
347
346
|
// @ts-expect-error update() not available in Mongoose v6 and below
|
|
348
|
-
await
|
|
347
|
+
await UserModel.update({ name: 'Alex', role: 'user' }, { $set: { name: 'Alex', role: 'user' } }, { upsert: true, setDefaultsOnInsert: false, overwriteDiscriminatorKey: true }).exec()
|
|
349
348
|
} else {
|
|
350
|
-
await
|
|
349
|
+
await UserModel.findOneAndUpdate({ name: 'Alex', role: 'user' }, { $set: { name: 'Alex', role: 'user' } }, { upsert: true, setDefaultsOnInsert: false, overwriteDiscriminatorKey: true }).exec()
|
|
351
350
|
}
|
|
352
351
|
|
|
353
|
-
const alex = await
|
|
352
|
+
const alex = await UserModel.findOne({ name: 'Alex', role: 'user' })
|
|
354
353
|
expect(alex).not.toBeNull()
|
|
355
354
|
|
|
356
|
-
const history = await
|
|
355
|
+
const history = await HistoryModel.find({})
|
|
357
356
|
expect(history).toHaveLength(0)
|
|
358
357
|
|
|
359
358
|
expect(em.emit).toHaveBeenCalledTimes(2)
|