Skip to content

Commit d2f12b6

Browse files
committed
chore: add tests for SavePlayoutModel
1 parent 1a0fbca commit d2f12b6

File tree

2 files changed

+399
-10
lines changed

2 files changed

+399
-10
lines changed

packages/job-worker/src/__mocks__/collection.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ export class MockMongoCollection<TDoc extends { _id: ProtectedString<any> }> imp
175175
async remove(selector: MongoQuery<TDoc> | TDoc['_id']): Promise<number> {
176176
this.#ops.push({ type: 'remove', args: [selector] })
177177

178-
return this.removeInner(selector)
179-
}
180-
private async removeInner(selector: MongoQuery<TDoc> | TDoc['_id']): Promise<number> {
181178
const docs: Pick<TDoc, '_id'>[] = await this.findFetchInner(selector, { projection: { _id: 1 } })
182179
for (const doc of docs) {
183180
this.#documents.delete(doc._id)
@@ -186,15 +183,15 @@ export class MockMongoCollection<TDoc extends { _id: ProtectedString<any> }> imp
186183
return docs.length
187184
}
188185
async update(selector: MongoQuery<TDoc> | TDoc['_id'], modifier: MongoModifier<TDoc>): Promise<number> {
189-
this.#ops.push({ type: 'update', args: [selector, modifier] })
190-
191186
return this.updateInner(selector, modifier, false)
192187
}
193188
private async updateInner(
194189
selector: MongoQuery<TDoc> | TDoc['_id'],
195190
modifier: MongoModifier<TDoc>,
196191
single: boolean
197192
) {
193+
this.#ops.push({ type: 'update', args: [selector, modifier] })
194+
198195
const docs = await this.findFetchInner(selector)
199196

200197
for (const doc of docs) {
@@ -210,9 +207,6 @@ export class MockMongoCollection<TDoc extends { _id: ProtectedString<any> }> imp
210207
async replace(doc: TDoc | ReadonlyDeep<TDoc>): Promise<boolean> {
211208
this.#ops.push({ type: 'replace', args: [doc._id] })
212209

213-
return this.replaceInner(doc)
214-
}
215-
private async replaceInner(doc: TDoc | ReadonlyDeep<TDoc>): Promise<boolean> {
216210
if (!doc._id) throw new Error(`replace requires document to have an _id`)
217211

218212
const exists = this.#documents.has(doc._id)
@@ -228,9 +222,9 @@ export class MockMongoCollection<TDoc extends { _id: ProtectedString<any> }> imp
228222
} else if ('updateOne' in op) {
229223
await this.updateInner(op.updateOne.filter, op.updateOne.update, true)
230224
} else if ('replaceOne' in op) {
231-
await this.replaceInner(op.replaceOne.replacement as any)
225+
await this.replace(op.replaceOne.replacement as any)
232226
} else if ('deleteMany' in op) {
233-
await this.removeInner(op.deleteMany.filter)
227+
await this.remove(op.deleteMany.filter)
234228
} else {
235229
// Note: implement more as we start using them
236230
throw new Error(`Unknown mongo Bulk Operation: ${JSON.stringify(op)}`)

0 commit comments

Comments
 (0)