|
1 | | -// import { Mongo } from 'meteor/mongo' |
2 | | -// import { Tinytest } from 'meteor/tinytest' |
3 | | -// import { InsecureLogin } from './insecure_login' |
4 | | - |
5 | | -// NOTE: no async find hooks in v3 |
6 | | -// Tinytest.addAsync('find - selector should be {} when called without arguments', function (test, next) { |
7 | | -// const collection = new Mongo.Collection(null) |
8 | | - |
9 | | -// // eslint-disable-next-line array-callback-return |
10 | | -// collection.before.find(function (userId, selector, options) { |
11 | | -// test.equal(selector, {}) |
12 | | -// next() |
13 | | -// }) |
14 | | - |
15 | | -// collection.find() |
16 | | -// }) |
17 | | - |
18 | | -// NOTE: no async find hooks in v3 |
19 | | -// Tinytest.addAsync('find - selector should have extra property', function (test, next) { |
20 | | -// const collection = new Mongo.Collection(null) |
21 | | - |
22 | | -// // eslint-disable-next-line array-callback-return |
23 | | -// collection.before.find(function (userId, selector, options) { |
24 | | -// if (options && options.test) { |
25 | | -// delete selector.bogus_value |
26 | | -// selector.before_find = true |
27 | | -// } |
28 | | -// }) |
29 | | - |
30 | | -// InsecureLogin.ready(function () { |
31 | | -// collection.insert({ start_value: true, before_find: true }, function (err, id) { |
32 | | -// if (err) throw err |
33 | | -// test.equal(collection.find({ start_value: true, bogus_value: true }, { test: 1 }).count(), 1) |
34 | | -// next() |
35 | | -// }) |
36 | | -// }) |
37 | | -// }) |
38 | | - |
39 | | -// NOTE: no async find hooks in v3 |
40 | | -// Tinytest.addAsync('find - tmp variable should have property added after the find', function (test, next) { |
41 | | -// const collection = new Mongo.Collection(null) |
42 | | -// const tmp = {} |
43 | | - |
44 | | -// // eslint-disable-next-line array-callback-return |
45 | | -// collection.after.find(function (userId, selector, options) { |
46 | | -// if (options && options.test) { |
47 | | -// tmp.after_find = true |
48 | | -// } |
49 | | -// }) |
50 | | - |
51 | | -// InsecureLogin.ready(function () { |
52 | | -// collection.insert({ start_value: true }, function (err, id) { |
53 | | -// if (err) throw err |
54 | | -// collection.find({ start_value: true }, { test: 1 }) |
55 | | -// test.equal(tmp.after_find, true) |
56 | | -// next() |
57 | | -// }) |
58 | | -// }) |
59 | | -// }) |
| 1 | +import { Mongo } from 'meteor/mongo' |
| 2 | +import { Tinytest } from 'meteor/tinytest' |
| 3 | +import { InsecureLogin } from './insecure_login' |
| 4 | + |
| 5 | +Tinytest.addAsync('find - selector should be {} when called without arguments', async function (test) { |
| 6 | + const collection = new Mongo.Collection(null) |
| 7 | + |
| 8 | + let findSelector = null |
| 9 | + collection.before.find(async function (userId, selector, options) { |
| 10 | + findSelector = selector |
| 11 | + }) |
| 12 | + |
| 13 | + // hooks won't be triggered on find() alone, we must call fetchAsync() |
| 14 | + await collection.find().fetchAsync() |
| 15 | + |
| 16 | + test.equal(findSelector, {}) |
| 17 | +}) |
| 18 | + |
| 19 | +Tinytest.addAsync('find - selector should have extra property', async function (test) { |
| 20 | + const collection = new Mongo.Collection(null) |
| 21 | + |
| 22 | + collection.before.find(async function (userId, selector, options) { |
| 23 | + if (options && options.test) { |
| 24 | + delete selector.bogus_value |
| 25 | + selector.before_find = true |
| 26 | + } |
| 27 | + }) |
| 28 | + |
| 29 | + await InsecureLogin.ready(async function () { |
| 30 | + await collection.insertAsync({ start_value: true, before_find: true }) |
| 31 | + test.equal(await collection.find({ start_value: true, bogus_value: true }, { test: 1 }).countAsync(), 1) |
| 32 | + }) |
| 33 | +}) |
| 34 | + |
| 35 | +Tinytest.addAsync('find - tmp variable should have property added after the find', async function (test) { |
| 36 | + const collection = new Mongo.Collection(null) |
| 37 | + const tmp = {} |
| 38 | + |
| 39 | + // eslint-disable-next-line array-callback-return |
| 40 | + collection.after.find(async function (userId, selector, options) { |
| 41 | + if (options && options.test) { |
| 42 | + tmp.after_find = true |
| 43 | + } |
| 44 | + }) |
| 45 | + |
| 46 | + await InsecureLogin.ready(async function () { |
| 47 | + await collection.insertAsync({ start_value: true }) |
| 48 | + await collection.find({ start_value: true }, { test: 1 }).fetchAsync() |
| 49 | + |
| 50 | + test.equal(tmp.after_find, true) |
| 51 | + }) |
| 52 | +}) |
0 commit comments