Skip to content

Commit

Permalink
Merge pull request #317 from vparpoil/migrate/3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
harryadel authored Nov 4, 2024
2 parents ac628f4 + 2b8ab22 commit bc47e08
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
2 changes: 1 addition & 1 deletion collection-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CollectionHooks.extendCollectionInstance = function extendCollectionInstance (
// Example: collection.before.insert(func);
['before', 'after'].forEach(function (timing) {
Object.entries(wrappers).forEach(function ([method, wrapper]) {
if (wrapper === 'upsert' && timing === 'after') return
if (method === 'upsert' && timing === 'after') return

Meteor._ensure(self, timing, method)
Meteor._ensure(self, '_hooks', method)
Expand Down
11 changes: 0 additions & 11 deletions tests/upsert.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Tinytest.addAsync('upsert - hooks should all fire the appropriate number of time
insert: 0,
update: 0,
remove: 0,

Check failure on line 18 in tests/upsert.js

View workflow job for this annotation

GitHub Actions / test

Unexpected trailing comma
upsert: 0
}
}

Expand All @@ -28,7 +27,6 @@ Tinytest.addAsync('upsert - hooks should all fire the appropriate number of time
collection.after.insert(function () { counts.after.insert++ })
collection.after.update(function () { counts.after.update++ })
collection.after.remove(function () { counts.after.remove++ })
collection.after.upsert(function () { counts.after.upsert++ })

await InsecureLogin.ready(async function () {
await collection.removeAsync({ test: true })
Expand All @@ -42,7 +40,6 @@ Tinytest.addAsync('upsert - hooks should all fire the appropriate number of time
test.equal(counts.after.insert, 1, 'after.insert should be 1')
test.equal(counts.after.update, 1, 'after.update should be 1')
test.equal(counts.after.remove, 0, 'after.remove should be 0')
test.equal(counts.after.upsert, 0, 'after.upsert should be 0')

// TODO(v3): callbacks are not working as expected, not passed to collection-hooks. Need to investigate
// await collection.removeAsync({ test: true }, async function (err) {
Expand Down Expand Up @@ -81,7 +78,6 @@ if (Meteor.isServer) {
insert: 0,
update: 0,
remove: 0,

Check failure on line 80 in tests/upsert.js

View workflow job for this annotation

GitHub Actions / test

Unexpected trailing comma
upsert: 0
}
}

Expand All @@ -93,7 +89,6 @@ if (Meteor.isServer) {
collection.after.insert(function () { counts.after.insert++ })
collection.after.update(function () { counts.after.update++ })
collection.after.remove(function () { counts.after.remove++ })
collection.after.upsert(function () { counts.after.upsert++ })

await collection.removeAsync({ test: true })
const obj = await collection.upsertAsync({ test: true }, { test: true, step: 'insert' })
Expand All @@ -106,7 +101,6 @@ if (Meteor.isServer) {
test.equal(counts.after.insert, 1, 'after.insert should be 1')
test.equal(counts.after.update, 1, 'after.update should be 1')
test.equal(counts.after.remove, 0, 'after.remove should be 0')
test.equal(counts.after.upsert, 0, 'after.upsert should be 0')
})
}

Expand Down Expand Up @@ -182,13 +176,9 @@ if (Meteor.isClient) {
const collectionForSync = new Mongo.Collection(null)
Tinytest.add('upsert - hooks are not called for sync methods', function (test) {
let beforeCalled = false
let afterCalled = false
collectionForSync.before.upsert(function (userId, selector, options) {
beforeCalled = true
})
collectionForSync.after.upsert(function (userId, selector, options) {
afterCalled = true
})

const result = collectionForSync.upsert({ test: 1 }, {
$set: { name: 'abc' }
Expand All @@ -197,6 +187,5 @@ if (Meteor.isClient) {
test.equal(result.numberAffected, 1)

test.equal(beforeCalled, false)
test.equal(afterCalled, false)
})
}

0 comments on commit bc47e08

Please sign in to comment.