diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 00000000..fd630693
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+github: [StorytellerCZ]
diff --git a/.github/workflows/comment-issue.yml b/.github/workflows/comment-issue.yml
new file mode 100644
index 00000000..f71d991e
--- /dev/null
+++ b/.github/workflows/comment-issue.yml
@@ -0,0 +1,31 @@
+name: Add immediate comment on new issues
+
+on:
+ issues:
+ types: [opened]
+
+jobs:
+ createComment:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Create Comment
+ uses: peter-evans/create-or-update-comment@v1.4.2
+ with:
+ issue-number: ${{ github.event.issue.number }}
+ body: |
+ Thank you for submitting this issue!
+
+ We, the Members of Meteor Community Packages take every issue seriously.
+ Our goal is to provide long-term lifecycles for packages and keep up
+ with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem.
+
+ However, we contribute to these packages mostly in our free time.
+ Therefore, we can't guarantee you issues to be solved within certain time.
+
+ If you think this issue is trivial to solve, don't hesitate to submit
+ a pull request, too! We will accompany you in the process with reviews and hints
+ on how to get development set up.
+
+ Please also consider sponsoring the maintainers of the package.
+ If you don't know who is currently maintaining this package, just leave a comment
+ and we'll let you know
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 00000000..186e541c
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,32 @@
+name: Tests
+
+on: [push, pull_request]
+
+jobs:
+ test:
+ runs-on: ubuntu-20.04
+ strategy:
+ matrix:
+ meteor: [1.12.2, 2.6.1, 2.7.3, 2.8.1, 2.12]
+ redis-version: [4, 5, 6, 7]
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Start Redis
+ uses: supercharge/redis-github-action@1.5.0
+ with:
+ redis-version: ${{ matrix.redis-version }}
+
+ - name: Setup Meteor
+ uses: meteorengineer/setup-meteor@v1
+ with:
+ meteor-release: ${{ matrix.meteor }}
+ - name: Setup tests
+ run: |
+ meteor create --release ${{ matrix.meteor }} --bare test
+ cd test
+ meteor npm i --save puppeteer@1.18.1 simpl-schema chai
+ - name: Test
+ working-directory: ./test
+ run: METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../
diff --git a/.gitignore b/.gitignore
index 9aaee737..04913f99 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
.DS_Store
dump.rdb
-npm-debug.log
\ No newline at end of file
+npm-debug.log
+.idea/
+
+test/
diff --git a/.meteorignore b/.meteorignore
new file mode 100644
index 00000000..51621298
--- /dev/null
+++ b/.meteorignore
@@ -0,0 +1,5 @@
+.idea/
+.github/
+test/
+docs/
+testing/
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index ffee1a5b..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-services:
- - redis-server
-
-language: node_js
-
-node_js:
- - "8.9.1"
-
-before_install:
- - curl https://install.meteor.com | /bin/sh
- - export PATH="$HOME/.meteor:$PATH"
-
-cache:
- directories:
- - $HOME/.npm
- - $HOME/.meteor
-
-notifications:
- email: false
-
-script:
- - meteor create --release 1.8.1 --bare test
- - cd test
- - meteor npm i --save puppeteer@1.18.1 simpl-schema chai
- - METEOR_PACKAGE_DIRS="../" TEST_BROWSER_DRIVER=puppeteer meteor test-packages --raw-logs --once --driver-package meteortesting:mocha ../
diff --git a/.versions b/.versions
new file mode 100644
index 00000000..12ac1f34
--- /dev/null
+++ b/.versions
@@ -0,0 +1,68 @@
+accounts-base@2.2.4
+accounts-password@2.3.1
+alanning:roles@3.4.0
+aldeed:collection2@3.0.6
+allow-deny@1.1.1
+babel-compiler@7.9.2
+babel-runtime@1.5.1
+base64@1.0.12
+binary-heap@1.0.11
+boilerplate-generator@1.7.1
+callback-hook@1.4.0
+check@1.3.1
+cultofcoders:redis-oplog@2.1.1
+ddp@1.4.0
+ddp-client@2.5.0
+ddp-common@1.4.0
+ddp-rate-limiter@1.1.0
+ddp-server@2.5.0
+diff-sequence@1.1.1
+dynamic-import@0.7.2
+ecmascript@0.16.2
+ecmascript-runtime@0.8.0
+ecmascript-runtime-client@0.12.1
+ecmascript-runtime-server@0.11.0
+ejson@1.1.2
+email@2.2.1
+fetch@0.1.1
+geojson-utils@1.0.10
+id-map@1.1.1
+inter-process-messaging@0.1.1
+local-test:cultofcoders:redis-oplog@2.1.1
+localstorage@1.2.0
+logging@1.3.1
+matb33:collection-hooks@1.1.4
+meteor@1.10.0
+meteortesting:browser-tests@0.1.2
+meteortesting:mocha@0.4.4
+minimongo@1.8.0
+modern-browsers@0.1.8
+modules@0.18.0
+modules-runtime@0.13.0
+mongo@1.15.0
+mongo-decimal@0.1.3
+mongo-dev-server@1.1.0
+mongo-id@1.0.8
+natestrauser:publish-performant-counts@0.1.2
+npm-mongo@4.3.1
+ordered-dict@1.1.0
+practicalmeteor:mocha-core@1.0.1
+promise@0.12.0
+raix:eventemitter@0.1.3
+random@1.2.0
+rate-limit@1.0.9
+react-fast-refresh@0.2.3
+reactive-var@1.0.11
+reload@1.3.1
+retry@1.1.0
+reywood:publish-composite@1.7.3
+routepolicy@1.1.1
+service-configuration@1.3.0
+sha@1.0.9
+socket-stream-client@0.5.0
+tmeasday:check-npm-versions@0.3.2
+tracker@1.2.0
+underscore@1.0.10
+url@1.3.2
+webapp@1.13.1
+webapp-hashing@1.1.0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89d12997..6aee7206 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,26 @@
## CHANGELOG
+### 2.2.0
+- Bumped minimum Meteor version to v1.12.2
+- Updated tests to cover from Meteor v1.12.2 to the latest v2.12
+- Added testing for Redis v7
+- Updated `node-redis` to v3.1.2
+- Updated `deep-extend` to v0.6.0
+- Fix update not returning number
+- Fix SyntheticMutator not applying `globalRedisPrefix`
+
+### 2.1.1
+- Fixes callback is not a function error when using SyntheticMutator.update
+
+### 2.1.0
+- Meteor 2.6 support
+- Projections option support
+- Update Mocha tests
+- Update tests to use Meteor 1.12.2 to fix certificates issues
+
### 1.2.3
- Redis connection failover handling
-- Refetching the up to date collection when Redis connection resumes
+- Re-fetching the up-to-date collection when Redis connection resumes
- Bug fixes and improvements
### 1.2.2
@@ -29,4 +47,4 @@
### 1.0.3
- Added support for publish composite
-- Fixed randomly failing tests
\ No newline at end of file
+- Fixed randomly failing tests
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a18b2a8b..d5584094 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -28,9 +28,9 @@ It is also always helpful to have some context for your pull request. What was t
### Setup
```
-meteor create --release 1.8.1 --bare test
+meteor create --release 1.12.2 --bare test
cd test
-meteor npm i --save puppeteer@1.18.1 simpl-schema
+meteor npm i --save puppeteer@1.18.1 simpl-schema chai
```
### Start Tests
@@ -78,4 +78,4 @@ Thank you to all our sponsors! (please ask your company to also support this ope
-
\ No newline at end of file
+
diff --git a/README.md b/README.md
index 25d8082f..6589cb8b 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,15 @@
-# Welcome to Redis Oplog
+## Introducing BlueLibs
+
+- [GitHub BlueLibs Monorepo](https://github.com/bluelibs/bluelibs)
+- Following the same bold vision of Meteor, but with a modern twist. www.bluelibs.com
+- Read more about our approach coming from Meteor: https://www.bluelibs.com/blog/2021/11/26/the-meteor-of-2022
+- We've implemented [RedisOplog](https://www.bluelibs.com/docs/package-x-bundle#live-data) in our framework as well, but it also works with in-memory and with customisable pubsub, not bound to redis.
+# Welcome to Redis Oplog
### LICENSE: MIT
-[![Build Status](https://api.travis-ci.org/cult-of-coders/redis-oplog.svg?branch=master)](https://travis-ci.org/cult-of-coders/redis-oplog) [![Backers on Open Collective](https://opencollective.com/redis-oplog/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/redis-oplog/sponsors/badge.svg)](#sponsors)
+[![Backers on Open Collective](https://opencollective.com/redis-oplog/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/redis-oplog/sponsors/badge.svg)](#sponsors)
## RedisOplog
diff --git a/docs/failover.md b/docs/failover.md
index 2d97dee0..ffa2a7b7 100644
--- a/docs/failover.md
+++ b/docs/failover.md
@@ -15,7 +15,7 @@ In order to configure these events, you can do it like this:
// in a server-side file that is loaded on startup
import { Config } from 'meteor/cultofcoders:redis-oplog';
-_.extend(Config.redisExtras.events, {
+Object.assign(Config.redisExtras.events, {
reconnect({delay, attempt, error}) {
// put your logic here.
},
@@ -30,4 +30,4 @@ _.extend(Config.redisExtras.events, {
Since we have the logic of refreshing an observable collection, we can make it so it falls back to polling.
But polling is very dangerous and very expensive, so we should avoid it at all costs, however
this could be implemented and customized per collection, but honestly, your redis-server needs to have
-high-availability, since it's a core component of your app.
\ No newline at end of file
+high-availability, since it's a core component of your app.
diff --git a/docs/finetuning.md b/docs/finetuning.md
index 744931a1..babababe 100644
--- a/docs/finetuning.md
+++ b/docs/finetuning.md
@@ -188,11 +188,11 @@ Messages.configureRedisOplog({
}
if (event === Events.REMOVE) {
// If it performs a remove by _id (which is the most usual)
- threadId = Messages.findOne({_id: selector._id}, {fields: {threadId: 1}}).threadId;
+ threadId = Messages.findOne({_id: selector._id}, {projection: {threadId: 1}}).threadId;
}
if (event === Events.UPDATE) {
// If it performs an update by _id (which is the most usual)
- threadId = Messages.findOne({_id: selector._id}, {fields: {threadId: 1}}).threadId;
+ threadId = Messages.findOne({_id: selector._id}, {projection: {threadId: 1}}).threadId;
}
options.namespace = `threads::${threadId}`;
diff --git a/docs/outside_mutations.md b/docs/outside_mutations.md
index 9177b2c5..49203bc9 100644
--- a/docs/outside_mutations.md
+++ b/docs/outside_mutations.md
@@ -38,7 +38,7 @@ redis.publish('tasks', JSON.stringify({
You have to be careful, if in your app you subscribe by `_id`:
```js
-return Task.find({_id: taskId})
+return Tasks.find({_id: taskId})
```
In order for the processor to catch the event you have to send it to the `tasks::taskId` channel, where `taskId` represents the actual id inside MongoDB.
@@ -47,7 +47,7 @@ So, if you have both types of publications, you have to publish it to both `task
If you use namespaces, the channels also change:
```js
-return Task.find({groupId}, {
+return Tasks.find({groupId}, {
namespace: `group::${groupId}`
})
```
@@ -57,7 +57,7 @@ you have to send it to both `group::groupId::tasks` and `tasks::taskId`, where `
Keep in mind, that namespaces don't affect direct query processing:
```js
-return Task.find({_id: taskId}, {
+return Tasks.find({_id: taskId}, {
namespace: `group::${groupId}`
})
```
diff --git a/lib/cache/ObservableCollection.js b/lib/cache/ObservableCollection.js
index 12e29094..127171df 100644
--- a/lib/cache/ObservableCollection.js
+++ b/lib/cache/ObservableCollection.js
@@ -14,6 +14,7 @@ const allowedOptions = [
'skip',
'sort',
'fields',
+ 'projection',
'channels',
'channel',
'namespace',
@@ -89,26 +90,29 @@ export default class ObservableCollection {
this.options = {};
}
+ var fields = this.options.projection || this.options.fields;
+
// check for empty projector object and delete.
- if (this.options.fields && _.isEmpty(this.options.fields)) {
+ if (fields && _.isEmpty(fields)) {
+ delete this.options.projection;
delete this.options.fields;
}
- if (this.options.fields) {
- this.fieldsArray = _.keys(this.options.fields);
+ if (fields) {
+ this.fieldsArray = Object.keys(fields);
if (!_.isArray(this.fieldsArray)) {
throw new Meteor.Error(
- 'We could not properly extract any fields. "fields" must be an object. This was provided: ' +
- JSON.stringify(this.options.fields)
+ 'We could not properly extract any fields. "projection" or "fields" must be an object. This was provided: ' +
+ JSON.stringify(fields)
);
}
this.projectFieldsOnDoc = LocalCollection._compileProjection(
- this.options.fields
+ fields
);
this.isFieldsProjectionByExclusion = fieldProjectionIsExclusion(
- this.options.fields
+ fields
);
}
@@ -116,7 +120,7 @@ export default class ObservableCollection {
this.fieldsOfInterest = this._getFieldsOfInterest();
this.__isInitialized = false;
- var projection = this.options.fields || {};
+ var projection = fields || {};
this._projectionFn = LocalCollection._compileProjection(projection); // Projection function, result of combining important fields for selector and
// existing fields projection
@@ -152,7 +156,7 @@ export default class ObservableCollection {
isEligibleByDB(_id) {
if (this.matcher) {
return !!this.collection.findOne(
- _.extend({}, this.selector, { _id }),
+ Object.assign({}, this.selector, { _id }),
{ fields: { _id: 1 } }
);
}
@@ -308,7 +312,9 @@ export default class ObservableCollection {
* @return {true|object}
*/
_getFieldsOfInterest() {
- if (!this.options.fields) {
+ const fields = this.options.projection || this.options.fields;
+
+ if (!fields) {
return true;
}
@@ -320,7 +326,7 @@ export default class ObservableCollection {
// if we have options, we surely have fields array
let fieldsArray = this.fieldsArray.slice();
- if (_.keys(this.selector).length > 0) {
+ if (Object.keys(this.selector).length > 0) {
fieldsArray = _.union(
fieldsArray,
extractFieldsFromFilters(this.selector)
diff --git a/lib/cache/lib/extractFieldsFromFilters.js b/lib/cache/lib/extractFieldsFromFilters.js
index ffe8bd2d..11b089f1 100644
--- a/lib/cache/lib/extractFieldsFromFilters.js
+++ b/lib/cache/lib/extractFieldsFromFilters.js
@@ -1,3 +1,5 @@
+import { _ } from 'meteor/underscore';
+
const deepFilterFieldsArray = ['$and', '$or', '$nor'];
const deepFilterFieldsObject = ['$not'];
diff --git a/lib/cache/lib/getChannels.js b/lib/cache/lib/getChannels.js
index d229fba1..659836c1 100644
--- a/lib/cache/lib/getChannels.js
+++ b/lib/cache/lib/getChannels.js
@@ -1,7 +1,6 @@
-import { _ } from 'meteor/underscore';
import getChannelName from '../../utils/getChannelName';
-export default (collectionName, {namespace, channel, namespaces, channels}) => {
+export default (collectionName, {namespace, channel, namespaces, channels} = {}) => {
let channelStrings = [];
if (namespaces) {
diff --git a/lib/cache/lib/getSnapbackFields.js b/lib/cache/lib/getSnapbackFields.js
index 13182b55..8e113025 100644
--- a/lib/cache/lib/getSnapbackFields.js
+++ b/lib/cache/lib/getSnapbackFields.js
@@ -19,6 +19,6 @@ const isArray = (doc, parts) => {
if (parts.length > 1) {
return isArray(doc[parts[0]], parts.slice(1));
} else {
- return _.isArray(doc[parts[0]]);
+ return Array.isArray(doc[parts[0]]);
}
-};
\ No newline at end of file
+};
diff --git a/lib/init.js b/lib/init.js
index 43122673..f56cd4e4 100644
--- a/lib/init.js
+++ b/lib/init.js
@@ -18,7 +18,7 @@ export default (config = {}) => {
deepExtend(Config, config);
- _.extend(Config, {
+ Object.assign(Config, {
isInitialized: true,
oldPublish: Meteor.publish,
});
diff --git a/lib/mongo/Mutator.js b/lib/mongo/Mutator.js
index fe16970b..029ab305 100644
--- a/lib/mongo/Mutator.js
+++ b/lib/mongo/Mutator.js
@@ -1,3 +1,5 @@
+import { Meteor } from 'meteor/meteor';
+import { _ } from 'meteor/underscore';
import getMutationConfig from "./lib/getMutationConfig";
import getFields from "../utils/getFields";
import {
@@ -152,7 +154,7 @@ export default class Mutator {
Originals,
selector,
modifier,
- config,
+ Object.assign({}, {_returnObject: false}, config),
callback,
docIds,
docs
@@ -163,7 +165,7 @@ export default class Mutator {
// we need the exact _ids
// and we extend the selector, because if between finding the docIds and updating
// another matching insert sneaked in, it's update will not be pushed
- const updateSelector = _.extend({}, selector, {
+ const updateSelector = Object.assign({}, selector, {
_id: { $in: docIds }
});
@@ -238,7 +240,7 @@ export default class Mutator {
this,
selector,
modifier,
- _.extend({}, config, { _returnObject: true })
+ Object.assign({}, config, { _returnObject: true })
);
if (callback) {
@@ -250,7 +252,7 @@ export default class Mutator {
if (config.pushToRedis) {
if (data.insertedId) {
- doc = {
+ let doc = {
_id: data.insertedId
};
@@ -294,7 +296,11 @@ export default class Mutator {
}
}
- return data;
+ if(config._returnObject) {
+ return data;
+ } else {
+ return data.numberAffected;
+ }
} catch (e) {
if (callback) {
const self = this;
@@ -329,7 +335,7 @@ export default class Mutator {
);
}
- const removeSelector = _.extend({}, selector);
+ const removeSelector = Object.assign({}, selector);
const removeOptions = {
fields: { _id: 1 },
transform: null
@@ -337,6 +343,7 @@ export default class Mutator {
if (shouldIncludePrevDocument(this)) {
delete removeOptions.fields;
+ delete removeOptions.projection;
}
// TODO: optimization check if it has _id or _id with {$in} so we don't have to redo this.
diff --git a/lib/mongo/ObserveMultiplex.js b/lib/mongo/ObserveMultiplex.js
index 7a086974..53e0c103 100644
--- a/lib/mongo/ObserveMultiplex.js
+++ b/lib/mongo/ObserveMultiplex.js
@@ -2,6 +2,7 @@
// This code is MIT and licensed to Meteor.
import { Meteor } from 'meteor/meteor';
+import { _ } from 'meteor/underscore';
import { LocalCollection } from 'meteor/minimongo';
import OptimisticInvocation from './OptimisticInvocation';
@@ -40,7 +41,7 @@ export function ObserveMultiplexer(options) {
});
}
-_.extend(ObserveMultiplexer.prototype, {
+Object.assign(ObserveMultiplexer.prototype, {
addHandleAndSendInitialAdds: function(handle) {
var self = this;
@@ -212,7 +213,7 @@ _.extend(ObserveMultiplexer.prototype, {
// can continue until these are done. (But we do have to be careful to not
// use a handle that got removed, because removeHandle does not use the
// queue; thus, we iterate over an array of keys that we control.)
- _.each(_.keys(self._handles), function(handleId) {
+ Object.keys(self._handles).forEach(function(handleId) {
var handle = self._handles && self._handles[handleId];
if (!handle) return;
var callback = handle['_' + callbackName];
diff --git a/lib/mongo/PollingObserveDriver.js b/lib/mongo/PollingObserveDriver.js
index 1271079f..f2a6f1d0 100644
--- a/lib/mongo/PollingObserveDriver.js
+++ b/lib/mongo/PollingObserveDriver.js
@@ -1,3 +1,4 @@
+import { _ } from 'meteor/underscore';
import { LocalCollection } from 'meteor/minimongo';
function listenAll(cursorDescription, listenCallback) {
@@ -28,7 +29,7 @@ function forEachTrigger(cursorDescription, triggerCallback) {
if (specificIds) {
_.each(specificIds, function(id) {
triggerCallback(
- _.extend(
+ Object.assign(
{
id: id,
},
@@ -38,7 +39,7 @@ function forEachTrigger(cursorDescription, triggerCallback) {
});
triggerCallback(
- _.extend(
+ Object.assign(
{
dropCollection: true,
id: null,
@@ -141,7 +142,7 @@ export default function PollingObserveDriver(options) {
);
}
-_.extend(PollingObserveDriver.prototype, {
+Object.assign(PollingObserveDriver.prototype, {
// This is always called through _.throttle (except once at startup).
_unthrottledEnsurePollIsScheduled: function() {
var self = this;
diff --git a/lib/mongo/RedisOplogObserveDriver.js b/lib/mongo/RedisOplogObserveDriver.js
index a19f3742..11f45d99 100644
--- a/lib/mongo/RedisOplogObserveDriver.js
+++ b/lib/mongo/RedisOplogObserveDriver.js
@@ -46,7 +46,7 @@ export default class RedisOplogObserveDriver {
let oc = this.observableCollection;
if (oc.selector._id) {
oc.__containsOtherSelectorsThanId =
- _.keys(oc.selector).length > 1;
+ Object.keys(oc.selector).length > 1;
}
}
@@ -88,9 +88,11 @@ export default class RedisOplogObserveDriver {
// If a fields projection option is given check if it is supported by
// minimongo (some operators are not supported).
- if (options.fields) {
+ var fields = options.projection || options.fields;
+
+ if (fields) {
try {
- LocalCollection._checkSupportedProjection(options.fields);
+ LocalCollection._checkSupportedProjection(fields);
} catch (e) {
if (e.name === 'MinimongoError') {
return false;
diff --git a/lib/mongo/SyntheticMutator.js b/lib/mongo/SyntheticMutator.js
index 5c881fb8..5d2c9730 100644
--- a/lib/mongo/SyntheticMutator.js
+++ b/lib/mongo/SyntheticMutator.js
@@ -5,6 +5,8 @@ import { EJSON } from 'meteor/ejson';
import getFields from '../utils/getFields';
import { Events, RedisPipe } from '../constants';
import containsOperators from '../mongo/lib/containsOperators';
+import getChannels from '../cache/lib/getChannels';
+import getDedicatedChannel from '../utils/getDedicatedChannel';
/**
* call(Mongo.Collection).insert(data)
@@ -28,7 +30,7 @@ export default class SyntheticMutator {
* @param data
*/
static insert(channels, data) {
- channels = SyntheticMutator._extractChannels(channels);
+ channels = SyntheticMutator._extractChannels(channels, data._id);
if (!data._id) {
data._id = Random.id();
@@ -47,7 +49,7 @@ export default class SyntheticMutator {
* @param modifier
*/
static update(channels, _id, modifier) {
- channels = SyntheticMutator._extractChannels(channels);
+ channels = SyntheticMutator._extractChannels(channels, _id);
if (!containsOperators(modifier)) {
throw new Meteor.Error(
@@ -73,7 +75,7 @@ export default class SyntheticMutator {
* @param _id
*/
static remove(channels, _id) {
- channels = SyntheticMutator._extractChannels(channels);
+ channels = SyntheticMutator._extractChannels(channels, _id);
SyntheticMutator.publish(channels, {
[RedisPipe.EVENT]: Events.REMOVE,
@@ -89,16 +91,16 @@ export default class SyntheticMutator {
* @private
*/
static _extractChannels(channels, _id) {
- if (!_.isArray(channels)) {
+ if (!Array.isArray(channels)) {
if (channels instanceof Mongo.Collection) {
const name = channels._name;
- channels = [name];
+ channels = getChannels(name);
if (_id) {
- channels.push(`${name}::${_id}`);
+ channels.push(getDedicatedChannel(name, _id));
}
+ } else {
+ channels = [channels];
}
-
- channels = [channels];
}
return channels;
diff --git a/lib/mongo/allow-deny/docToValidate.js b/lib/mongo/allow-deny/docToValidate.js
index 517d95a3..2636685f 100644
--- a/lib/mongo/allow-deny/docToValidate.js
+++ b/lib/mongo/allow-deny/docToValidate.js
@@ -1,4 +1,4 @@
-import {EJSON} from 'meteor/ejson'
+import { EJSON } from 'meteor/ejson'
export default function docToValidate(validator, doc, generatedId) {
let ret = doc
diff --git a/lib/mongo/allow-deny/validatedInsert.js b/lib/mongo/allow-deny/validatedInsert.js
index 5ec2da30..ed7a8df3 100644
--- a/lib/mongo/allow-deny/validatedInsert.js
+++ b/lib/mongo/allow-deny/validatedInsert.js
@@ -1,5 +1,5 @@
-import {Meteor} from 'meteor/meteor'
-import {_} from 'meteor/underscore'
+import { Meteor } from 'meteor/meteor'
+import { _ } from 'meteor/underscore'
import docToValidate from './docToValidate'
export default function validatedInsert(userId, doc, generatedId) {
diff --git a/lib/mongo/allow-deny/validatedRemove.js b/lib/mongo/allow-deny/validatedRemove.js
index b04eeab6..f325b795 100644
--- a/lib/mongo/allow-deny/validatedRemove.js
+++ b/lib/mongo/allow-deny/validatedRemove.js
@@ -1,14 +1,16 @@
/* eslint no-param-reassign: 0 no-underscore-dangle: 0 */
-import {Meteor} from 'meteor/meteor'
-import {_} from 'meteor/underscore'
+import { Meteor } from 'meteor/meteor'
+import { _ } from 'meteor/underscore'
import transformDoc from './transformDoc'
export default function validatedRemove(userId, selector) {
const findOptions = {transform: null}
if (!this._validators.fetchAllFields) {
findOptions.fields = {}
+ findOptions.projection = {}
_.each(this._validators.fetch, fieldName => {
findOptions.fields[fieldName] = 1
+ findOptions.projection[fieldName] = 1
})
}
diff --git a/lib/mongo/allow-deny/validatedUpdate.js b/lib/mongo/allow-deny/validatedUpdate.js
index 1b93c8ab..35f5f1e2 100644
--- a/lib/mongo/allow-deny/validatedUpdate.js
+++ b/lib/mongo/allow-deny/validatedUpdate.js
@@ -65,7 +65,7 @@ export default function validatedUpdate(userId, selector, mutator, options) {
`Access denied. Operator ${op} not allowed in a restricted collection.`
);
} else {
- _.each(_.keys(params), field => {
+ Object.keys(params).forEach(field => {
// treat dotted fields as if they are replacing their
// top-level part
if (field.indexOf('.') !== -1) {
@@ -73,7 +73,7 @@ export default function validatedUpdate(userId, selector, mutator, options) {
}
// record the field we are trying to change
- if (!_.contains(fields, field)) {
+ if (!fields.includes(field)) {
fields.push(field);
}
});
@@ -83,8 +83,10 @@ export default function validatedUpdate(userId, selector, mutator, options) {
const findOptions = { transform: null };
if (!this._validators.fetchAllFields) {
findOptions.fields = {};
+ findOptions.projection = {};
_.each(this._validators.fetch, fieldName => {
findOptions.fields[fieldName] = 1;
+ findOptions.projection[fieldName] = 1;
});
}
@@ -124,7 +126,7 @@ export default function validatedUpdate(userId, selector, mutator, options) {
this.update(
selector,
mutator,
- _.extend(options, {
+ Object.assign(options, {
optimistic: true,
})
);
diff --git a/lib/mongo/extendMongoCollection.js b/lib/mongo/extendMongoCollection.js
index b9bc6e20..15b84dc1 100644
--- a/lib/mongo/extendMongoCollection.js
+++ b/lib/mongo/extendMongoCollection.js
@@ -19,7 +19,7 @@ export default () => {
extendObserveChanges();
- _.extend(Mongo.Collection.prototype, {
+ Object.assign(Mongo.Collection.prototype, {
/**
* @param data
* @param config
diff --git a/lib/mongo/extendObserveChanges.js b/lib/mongo/extendObserveChanges.js
index c9f1d571..c3966ea2 100644
--- a/lib/mongo/extendObserveChanges.js
+++ b/lib/mongo/extendObserveChanges.js
@@ -1,10 +1,7 @@
-import { DDP } from 'meteor/ddp';
-import { Mongo, MongoInternals } from 'meteor/mongo';
-import { LocalCollection } from 'meteor/minimongo';
-import { Random } from 'meteor/random';
+import { MongoInternals } from 'meteor/mongo';
import observeChanges from './observeChanges';
-const MongoCursor = Object.getPrototypeOf(
+export const MongoCursor = Object.getPrototypeOf(
MongoInternals.defaultRemoteCollectionDriver().mongo.find()
).constructor;
diff --git a/lib/mongo/lib/getMutationConfig.js b/lib/mongo/lib/getMutationConfig.js
index 467b5ebe..0a3cb78a 100644
--- a/lib/mongo/lib/getMutationConfig.js
+++ b/lib/mongo/lib/getMutationConfig.js
@@ -24,7 +24,7 @@ export default function (collection, _config, mutationObject) {
defaultOverrides.optimistic = false;
}
- let config = _.extend({}, Config.mutationDefaults, defaultOverrides, _config);
+ let config = Object.assign({}, Config.mutationDefaults, defaultOverrides, _config);
if (collection._redisOplog) {
const {mutation} = collection._redisOplog;
diff --git a/lib/mongo/mongoCollectionNames.js b/lib/mongo/mongoCollectionNames.js
index 99a4d823..1a6cea6b 100644
--- a/lib/mongo/mongoCollectionNames.js
+++ b/lib/mongo/mongoCollectionNames.js
@@ -4,7 +4,7 @@ const constructor = Mongo.Collection;
const proto = Mongo.Collection.prototype;
const hook = function() {
- var ret = constructor.apply(this, arguments);
+ let ret = constructor.apply(this, arguments);
map[arguments[0]] = this;
return ret;
};
@@ -16,7 +16,7 @@ hook.__getCollectionByName = function (name) {
hook.prototype = proto;
hook.prototype.constructor = hook;
-for (var prop in constructor) {
+for (let prop in constructor) {
if (constructor.hasOwnProperty(prop)) {
hook[prop] = constructor[prop];
}
diff --git a/lib/mongo/observeChanges.js b/lib/mongo/observeChanges.js
index 270d532d..84a15781 100644
--- a/lib/mongo/observeChanges.js
+++ b/lib/mongo/observeChanges.js
@@ -1,13 +1,12 @@
// This code was started based on meteor/meteor github repository
// This code is MIT and licensed to Meteor.
-
+import { _ } from 'meteor/underscore';
import RedisOplogObserveDriver from './RedisOplogObserveDriver';
-import { MongoInternals } from 'meteor/mongo';
import { ObserveMultiplexer, ObserveHandle } from './ObserveMultiplex';
import PollingObserveDriver from './PollingObserveDriver';
export default function(cursorDescription, ordered, callbacks) {
- var self = this;
+ const self = this;
if (cursorDescription.options.tailable) {
return self._observeChangesTailable(
cursorDescription,
@@ -19,16 +18,17 @@ export default function(cursorDescription, ordered, callbacks) {
// You may not filter out _id when observing changes, because the id is a core
// part of the observeChanges API.
+ const fields = cursorDescription.options.projection || cursorDescription.options.fields;
+
if (
- cursorDescription.options.fields &&
- (cursorDescription.options.fields._id === 0 ||
- cursorDescription.options.fields._id === false)
+ fields &&
+ (fields._id === 0 || fields._id === false)
) {
- throw Error('You may not observe a cursor with {fields: {_id: 0}}');
+ throw Error('You may not observe a cursor with {projection: {_id: 0}}');
}
var observeKey = EJSON.stringify(
- _.extend(
+ Object.assign(
{
ordered: ordered,
},
diff --git a/lib/processors/actions/reload.js b/lib/processors/actions/reload.js
index 2105404a..49f9a305 100644
--- a/lib/processors/actions/reload.js
+++ b/lib/processors/actions/reload.js
@@ -1,4 +1,4 @@
-import {_} from 'meteor/underscore';
+import { _ } from 'meteor/underscore';
import { MongoIDMap } from '../../cache/mongoIdMap';
/**
@@ -17,7 +17,7 @@ export default function (observableCollection) {
store.compareWith(newStore, {
both(docId, oldDoc, newDoc) {
- const modifiedFields = _.union(_.keys(oldDoc), _.keys(newDoc));
+ const modifiedFields = _.union(Object.keys(oldDoc), Object.keys(newDoc));
observableCollection.change(newDoc, modifiedFields);
},
leftOnly(docId) {
diff --git a/lib/processors/actions/requery.js b/lib/processors/actions/requery.js
index e23b311e..78b00f25 100644
--- a/lib/processors/actions/requery.js
+++ b/lib/processors/actions/requery.js
@@ -1,4 +1,3 @@
-import { _ } from 'meteor/underscore';
import { EJSON } from 'meteor/ejson';
import { Events } from '../../constants';
import { MongoIDMap } from '../../cache/mongoIdMap';
diff --git a/lib/processors/getStrategy.js b/lib/processors/getStrategy.js
index f99724d3..6170e3b1 100644
--- a/lib/processors/getStrategy.js
+++ b/lib/processors/getStrategy.js
@@ -1,5 +1,4 @@
import { Strategy } from '../constants';
-import { _ } from 'meteor/underscore';
/**
* @param selector
@@ -21,4 +20,4 @@ export default function getStrategy(selector = {}, options = {}) {
}
return Strategy.DEFAULT;
-}
\ No newline at end of file
+}
diff --git a/lib/processors/lib/fieldsExist.js b/lib/processors/lib/fieldsExist.js
index cbf313ad..f96ee43a 100644
--- a/lib/processors/lib/fieldsExist.js
+++ b/lib/processors/lib/fieldsExist.js
@@ -1,11 +1,9 @@
-import { _ } from 'meteor/underscore';
-
/**
* @param fieldsObject {Object} {"profile.firstName": 1, "roles": 1, "something": 1 }
* @param fieldsArray {Array} ["profile", "roles.xx", "something" ]
*/
export function hasSortFields(fieldsObject, fieldsArray) {
- const existingFields = _.keys(fieldsObject);
+ const existingFields = Object.keys(fieldsObject);
for (let i = 0 ; i < fieldsArray.length ; i++) {
const field = fieldsArray[i];
@@ -21,4 +19,4 @@ export function hasSortFields(fieldsObject, fieldsArray) {
}
return false;
-}
\ No newline at end of file
+}
diff --git a/lib/redis/RedisSubscriber.js b/lib/redis/RedisSubscriber.js
index 22968524..e4a5b3d9 100644
--- a/lib/redis/RedisSubscriber.js
+++ b/lib/redis/RedisSubscriber.js
@@ -1,6 +1,5 @@
import { Strategy } from '../constants';
import { getProcessor } from '../processors';
-import { _ } from 'meteor/underscore';
import { Meteor } from 'meteor/meteor';
import extractIdsFromSelector from '../utils/extractIdsFromSelector';
import RedisSubscriptionManager from './RedisSubscriptionManager';
diff --git a/lib/redis/RedisSubscriptionManager.js b/lib/redis/RedisSubscriptionManager.js
index 5ced6f27..08aa1131 100644
--- a/lib/redis/RedisSubscriptionManager.js
+++ b/lib/redis/RedisSubscriptionManager.js
@@ -24,7 +24,7 @@ class RedisSubscriptionManager {
*/
getAllRedisSubscribers() {
let redisSubscribers = [];
- for (channel in this.store) {
+ for (let channel in this.store) {
this.store[channel].forEach(_redisSubscriber =>
redisSubscribers.push(_redisSubscriber)
);
diff --git a/lib/redis/getRedisClient.js b/lib/redis/getRedisClient.js
index 4bf2ecad..cda5a07c 100644
--- a/lib/redis/getRedisClient.js
+++ b/lib/redis/getRedisClient.js
@@ -1,7 +1,6 @@
import redis from 'redis';
import Config from '../config';
-import { _ } from 'meteor/underscore';
-import {Meteor} from 'meteor/meteor';
+import { Meteor } from 'meteor/meteor';
// Redis requires two connections for pushing and listening to data
let redisPusher;
@@ -14,7 +13,7 @@ let redisListener;
*/
export function getRedisPusher() {
if (!redisPusher) {
- redisPusher = redis.createClient(_.extend({}, Config.redis, {
+ redisPusher = redis.createClient(Object.assign({}, Config.redis, {
retry_strategy: getRetryStrategy()
}));
}
@@ -30,7 +29,7 @@ export function getRedisPusher() {
*/
export function getRedisListener({onConnect} = {}) {
if (!redisListener) {
- redisListener = redis.createClient(_.extend({}, Config.redis, {
+ redisListener = redis.createClient(Object.assign({}, Config.redis, {
retry_strategy: getRetryStrategy()
}));
@@ -71,4 +70,4 @@ function getRetryStrategy() {
return Config.redisExtras.retry_strategy(...args);
}
}
-}
\ No newline at end of file
+}
diff --git a/lib/utils/getFields.js b/lib/utils/getFields.js
index ffec25ae..2457c0c7 100644
--- a/lib/utils/getFields.js
+++ b/lib/utils/getFields.js
@@ -1,7 +1,5 @@
-import { _ } from 'meteor/underscore';
-
/**
- * Taken from: https://github.com/matb33/meteor-collection-hooks/blob/master/collection-hooks.js#L198 and modified.
+ * Taken from: https://github.com/Meteor-Community-Packages/meteor-collection-hooks/blob/master/collection-hooks.js#L194 and modified.
* @param mutator
*/
export default function getFields(mutator) {
@@ -9,11 +7,11 @@ export default function getFields(mutator) {
var fields = [];
var topLevelFields = [];
- _.each(mutator, function (params, op) {
+ Object.entries(mutator).forEach(function ([op, params]) {
if (op[0] == '$') {
- _.each(_.keys(params), function (field) {
+ Object.keys(params).forEach(function (field) {
// record the field we are trying to change
- if (!_.contains(fields, field)) {
+ if (!fields.includes(field)) {
// fields.push(field);
// topLevelFields.push(field.split('.')[0]);
diff --git a/lib/utils/shouldPublicationBeWithPolling.js b/lib/utils/shouldPublicationBeWithPolling.js
index 5ffec9e1..b76e507a 100644
--- a/lib/utils/shouldPublicationBeWithPolling.js
+++ b/lib/utils/shouldPublicationBeWithPolling.js
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
+import { _ } from 'meteor/underscore';
export default function(cursors) {
let isDisabledOplog = undefined;
diff --git a/lib/vent/Vent.js b/lib/vent/Vent.js
index 5ed7aaa6..8e5d5c6e 100644
--- a/lib/vent/Vent.js
+++ b/lib/vent/Vent.js
@@ -1,7 +1,6 @@
-import {getRedisListener, getRedisPusher} from '../redis/getRedisClient';
-import {VentConstants} from '../constants';
-import {Meteor} from 'meteor/meteor';
-import {Random} from 'meteor/random';
+import { VentConstants } from '../constants';
+import { Meteor } from 'meteor/meteor';
+import { _ } from 'meteor/underscore';
import Config from '../config';
// TODO:
diff --git a/lib/vent/VentClient.js b/lib/vent/VentClient.js
index c2e57437..21304d84 100644
--- a/lib/vent/VentClient.js
+++ b/lib/vent/VentClient.js
@@ -1,6 +1,6 @@
-import {VentConstants} from '../constants';
-import {Random} from 'meteor/random';
-import {DDPCommon} from 'meteor/ddp-common';
+import { VentConstants } from '../constants';
+import { Random } from 'meteor/random';
+import { DDPCommon } from 'meteor/ddp-common';
/**
* Handles vents inside Meteor
@@ -104,4 +104,4 @@ class VentClientSubscription {
}
}
-}
\ No newline at end of file
+}
diff --git a/package.js b/package.js
index d447275b..4e03a69e 100644
--- a/package.js
+++ b/package.js
@@ -1,6 +1,6 @@
Package.describe({
name: 'cultofcoders:redis-oplog',
- version: '2.0.5',
+ version: '2.2.0',
// Brief, one-line summary of the package.
summary: "Replacement for Meteor's MongoDB oplog implementation",
// URL to the Git repository containing the source code for this package.
@@ -11,13 +11,13 @@ Package.describe({
});
Npm.depends({
- redis: '2.8.0',
- 'deep-extend': '0.5.0',
+ redis: '3.1.2',
+ 'deep-extend': '0.6.0',
'lodash.clonedeep': '4.5.0'
});
Package.onUse(function(api) {
- api.versionsFrom('1.5.1');
+ api.versionsFrom(['1.12.2', '2.8.1', '2.12']);
api.use([
'underscore',
'ecmascript',
@@ -41,17 +41,17 @@ Package.onTest(function(api) {
// extensions
api.use('aldeed:collection2@3.0.0');
- api.use('reywood:publish-composite@1.5.2');
+ api.use('reywood:publish-composite@1.7.3');
api.use('natestrauser:publish-performant-counts@0.1.2');
- api.use('socialize:user-presence@0.4.0');
+ // api.use('socialize:user-presence@1.0.4');
api.use('ecmascript');
api.use('tracker');
api.use('mongo');
api.use('random');
api.use('accounts-password');
- api.use('matb33:collection-hooks@0.8.4');
- api.use('alanning:roles@1.2.16');
+ api.use('matb33:collection-hooks@1.1.2');
+ api.use('alanning:roles@3.4.0');
api.use(['meteortesting:mocha']);
diff --git a/testing/accounts/client.js b/testing/accounts/client.js
index 762624f1..311a2aef 100644
--- a/testing/accounts/client.js
+++ b/testing/accounts/client.js
@@ -1,6 +1,5 @@
import { assert } from 'chai';
-import {Meteor} from 'meteor/meteor';
-import { DDP } from 'meteor/ddp-client';
+import { Meteor } from 'meteor/meteor';
describe('Testing accounts functionality', function () {
it('Should properly subscribe and login', function (done) {
diff --git a/testing/accounts/server.js b/testing/accounts/server.js
index dfc24925..ea3922e1 100644
--- a/testing/accounts/server.js
+++ b/testing/accounts/server.js
@@ -1,11 +1,16 @@
import { Accounts } from 'meteor/accounts-base';
+import { Random } from 'meteor/random';
+import { Meteor } from 'meteor/meteor'
+import { Roles } from 'meteor/alanning:roles'
+
+// import { UserPresence } from 'meteor/socialize:user-presence';
// UserPresence.onCleanup(function(){
// Meteor.users.update({}, {$unset:{status:true}}, {multi:true});
// });
-UserPresence.onUserOnline(function(userId) {
- Meteor.users.update({ _id: userId }, { $set: { status: 'online' } });
-});
+// UserPresence.onUserOnline(function(userId) {
+// Meteor.users.update({ _id: userId }, { $set: { status: 'online' } });
+// });
// UserPresence.onUserIdle(function(userId){
// Meteor.users.update({_id:userId}, {$set:{status:"idle"}})
// });
diff --git a/testing/boot.js b/testing/boot.js
index d6b70de5..b68373c7 100644
--- a/testing/boot.js
+++ b/testing/boot.js
@@ -64,18 +64,18 @@ if (Meteor.isServer) {
filters,
options
) {
- return Collection.find(filters, _.extend({}, options, opts[key]));
+ return Collection.find(filters, Object.assign({}, options, opts[key]));
});
Meteor.methods({
[`create.${config[key].suffix}`](item, options = {}) {
if (_.isArray(item)) {
return _.map(item, i =>
- Collection.insert(i, _.extend(options, opts[key]))
+ Collection.insert(i, Object.assign(options, opts[key]))
);
}
- return Collection.insert(item, _.extend(options, opts[key]));
+ return Collection.insert(item, Object.assign(options, opts[key]));
},
[`fetch.${config[key].suffix}`](selector = {}, options = {}) {
return Collection.find(selector, options).fetch();
@@ -84,20 +84,20 @@ if (Meteor.isServer) {
return Collection.update(
selectors,
modifier,
- _.extend({}, opts[key], options)
+ Object.assign({}, opts[key], options)
);
},
[`upsert.${config[key].suffix}`](selectors, modifier, options) {
return Collection.upsert(
selectors,
modifier,
- _.extend({}, opts[key], options)
+ Object.assign({}, opts[key], options)
);
},
[`remove.${config[key].suffix}`](selectors, options = {}) {
return Collection.remove(
selectors,
- _.extend(options, opts[key])
+ Object.assign(options, opts[key])
);
},
[`synthetic.${config[key].suffix}`](
diff --git a/testing/client_side_mutators.js b/testing/client_side_mutators.js
index 013b32e9..37bf10ea 100644
--- a/testing/client_side_mutators.js
+++ b/testing/client_side_mutators.js
@@ -1,5 +1,5 @@
import { assert } from 'chai';
-import {Collections, config} from './boot';
+import { Collections, config } from './boot';
import helperGenerator from './lib/helpers';
const Collection = Collections['Standard'];
@@ -11,66 +11,66 @@ describe('Client-side Mutators', function () {
waitForHandleToBeReady
} = helperGenerator(config['Standard'].suffix);
- it('Should detect an insert/update and removal from client side', async function (done) {
+ it('Should detect an insert/update and removal from client side', function (done) {
const handle = subscribe({
client_side_mutators: true
});
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ client_side_mutators: true });
- cursor = Collection.find({ client_side_mutators: true });
+ let testDocId, inChanged = false, inAdded = false, inRemoved = false;
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ if (inAdded) {
+ return;
+ }
+ inAdded = true;
- let testDocId, inChanged = false, inAdded = false, inRemoved = false;
- const observer = cursor.observeChanges({
- added(docId, doc) {
- if (inAdded) {
- return;
- }
- inAdded = true;
-
- testDocId = docId;
- assert.equal(doc.number, 5);
+ testDocId = docId;
+ assert.equal(doc.number, 5);
- setTimeout(async () => {
- const result = await fetchSync({ _id: docId });
- assert.isArray(result);
- assert.lengthOf(result, 1);
- assert.equal(result[0].number, 5);
+ setTimeout(async () => {
+ const result = await fetchSync({ _id: docId });
+ assert.isArray(result);
+ assert.lengthOf(result, 1);
+ assert.equal(result[0].number, 5);
- Collection.update(docId, {
- $set: {number: 10}
- })
- }, 100)
- },
- changed(docId, doc) {
- if (inChanged) {
- return;
- }
- inChanged = true;
- assert.equal(docId, testDocId);
- assert.equal(doc.number, 10);
+ Collection.update(docId, {
+ $set: { number: 10 }
+ })
+ }, 100)
+ },
+ changed(docId, doc) {
+ if (inChanged) {
+ return;
+ }
+ inChanged = true;
+ assert.equal(docId, testDocId);
+ assert.equal(doc.number, 10);
- setTimeout(async () => {
- const result = await fetchSync({_id: docId});
- assert.lengthOf(result, 1);
- assert.equal(result[0].number, 10);
+ setTimeout(async () => {
+ const result = await fetchSync({ _id: docId });
+ assert.lengthOf(result, 1);
+ assert.equal(result[0].number, 10);
- Collection.remove(docId)
- }, 100);
- },
- removed(docId) {
- if (inRemoved) {
- return;
+ Collection.remove(docId)
+ }, 100);
+ },
+ removed(docId) {
+ if (inRemoved) {
+ return;
+ }
+ inRemoved = true;
+ assert.equal(docId, testDocId);
+ done();
}
- inRemoved = true;
- assert.equal(docId, testDocId);
- done();
- }
- });
+ });
- Collection.insert({
- client_side_mutators: true,
- number: 5
+ Collection.insert({
+ client_side_mutators: true,
+ number: 5
+ });
});
});
-});
\ No newline at end of file
+});
diff --git a/testing/collection-defaults/client.js b/testing/collection-defaults/client.js
index 15163a1b..b6895240 100644
--- a/testing/collection-defaults/client.js
+++ b/testing/collection-defaults/client.js
@@ -1,67 +1,66 @@
import { assert } from 'chai';
-import {Items} from './collections';
-import {_} from 'meteor/underscore';
-import {waitForHandleToBeReady, callWithPromise} from '../lib/sync_utils';
-import {Random} from 'meteor/random';
+import { Items } from './collections';
+import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils';
+import { Random } from 'meteor/random';
describe('Collection Defaults', () => {
- it('Should detect changes based on mutation defaults', async function (done) {
+ it('Should detect changes based on mutation defaults', function (done) {
const context = Random.id();
- const handle = Meteor.subscribe('collection_defaults.items', {context});
- await waitForHandleToBeReady(handle);
+ const handle = Meteor.subscribe('collection_defaults.items', { context });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Items.find({});
- const cursor = Items.find({});
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ assert.isObject(doc);
+ callWithPromise('collection_defaults.items.update', {
+ _id: docId
+ }, {
+ $set: {
+ number: 10
+ }
+ })
+ },
+ changed(docId, doc) {
+ assert.equal(doc.number, 10);
+ handle.stop();
+ observer.stop();
+ done();
+ }
+ });
- const observer = cursor.observeChanges({
- added(docId, doc) {
- assert.isObject(doc);
- callWithPromise('collection_defaults.items.update', {
- _id: docId
- }, {
- $set: {
- number: 10
- }
- })
- },
- changed(docId, doc) {
- assert.equal(doc.number, 10);
- handle.stop();
- observer.stop();
- done();
- }
- });
-
- await callWithPromise('collection_defaults.items.insert', {
- text: 'hello',
- context
+ callWithPromise('collection_defaults.items.insert', {
+ text: 'hello',
+ context
+ });
});
});
- it('Should not detect changes based if a namespace is specified', async function (done) {
+ it('Should not detect changes based if a namespace is specified', function (done) {
const context = Random.id();
- const handle = Meteor.subscribe('collection_defaults.items', {context}, {
+ const handle = Meteor.subscribe('collection_defaults.items', { context }, {
namespace: 'someothernamespace'
});
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Items.find({});
- const cursor = Items.find({});
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ done('It should not be here')
+ },
+ });
- const observer = cursor.observeChanges({
- added(docId, doc) {
- done('It should not be here')
- },
+ callWithPromise('collection_defaults.items.insert', {
+ text: 'hello again',
+ context
+ }).then(function () {
+ setTimeout(function () {
+ handle.stop();
+ observer.stop();
+ done();
+ }, 200);
+ });
});
-
- await callWithPromise('collection_defaults.items.insert', {
- text: 'hello again',
- context
- });
-
- setTimeout(function () {
- handle.stop();
- observer.stop();
- done();
- }, 200);
});
-});
\ No newline at end of file
+});
diff --git a/testing/collection-defaults/collections.js b/testing/collection-defaults/collections.js
index 918c4d04..c68b6117 100644
--- a/testing/collection-defaults/collections.js
+++ b/testing/collection-defaults/collections.js
@@ -1,5 +1,7 @@
+import { Mongo } from 'meteor/mongo'
+
const Items = new Mongo.Collection('collection_defaults_items');
export {
Items
-}
\ No newline at end of file
+}
diff --git a/testing/collection-defaults/server.js b/testing/collection-defaults/server.js
index a7b4b897..39283747 100644
--- a/testing/collection-defaults/server.js
+++ b/testing/collection-defaults/server.js
@@ -1,3 +1,4 @@
+import { Meteor } from 'meteor/meteor'
import { Items } from './collections';
if (Meteor.isServer) {
diff --git a/testing/collection_hooks.server.js b/testing/collection_hooks.server.js
index 30aad0a9..398ffd32 100644
--- a/testing/collection_hooks.server.js
+++ b/testing/collection_hooks.server.js
@@ -6,8 +6,8 @@ describe('It should work with collection:hooks', function () {
const opts = [
{},
- {channel: 'xxx'},
- {namespace: 'xxx'}
+ { channel: 'xxx' },
+ { namespace: 'xxx' }
];
let idx = 1;
@@ -45,8 +45,8 @@ describe('It should work with collection:hooks', function () {
updates['after.remove'] = true;
});
- const id = Collection.insert({someData: true});
- Collection.update(id, {someData: false});
+ const id = Collection.insert({ someData: true });
+ Collection.update(id, { someData: false });
Collection.remove(id);
_.each(updates, (value, key) => {
diff --git a/testing/custom-publications/client.js b/testing/custom-publications/client.js
index 7a24e8af..230624fc 100644
--- a/testing/custom-publications/client.js
+++ b/testing/custom-publications/client.js
@@ -1,7 +1,7 @@
import { assert } from 'chai';
-import {Items} from './collections';
-import {Meteor} from 'meteor/meteor';
-import {Counter} from 'meteor/natestrauser:publish-performant-counts'
+import { Items } from './collections';
+import { Meteor } from 'meteor/meteor';
+// import {Counter} from 'meteor/natestrauser:publish-performant-counts'
describe('Testing custom publications functionality', function () {
it('Should be able to retrieve the correct number', function (done) {
diff --git a/testing/custom-publications/collections.js b/testing/custom-publications/collections.js
index 78979234..f985b16c 100644
--- a/testing/custom-publications/collections.js
+++ b/testing/custom-publications/collections.js
@@ -1,4 +1,4 @@
-import {Mongo} from 'meteor/mongo';
+import { Mongo } from 'meteor/mongo';
const Items = new Mongo.Collection('custom_publication_items');
diff --git a/testing/custom-publications/server.js b/testing/custom-publications/server.js
index 29775f1e..584d474b 100644
--- a/testing/custom-publications/server.js
+++ b/testing/custom-publications/server.js
@@ -1,4 +1,5 @@
-import {Items} from './collections';
+import { Meteor } from 'meteor/meteor';
+import { Items } from './collections';
Meteor.publish('custom_publications', function () {
const cursor = Items.find();
@@ -17,4 +18,4 @@ Meteor.methods({
Items.insert({name: 'Item 2'});
Items.insert({name: 'Item 3'});
}
-});
\ No newline at end of file
+});
diff --git a/testing/include_prev_doc.js b/testing/include_prev_doc.js
index 7eec0d63..58d2dae8 100644
--- a/testing/include_prev_doc.js
+++ b/testing/include_prev_doc.js
@@ -9,48 +9,48 @@ const PrevDocCollection = new Mongo.Collection('test_redis_prev_doc');
const NoPrevDocCollection = new Mongo.Collection('test_redis_no_prev_doc');
PrevDocCollection.configureRedisOplog({
- shouldIncludePrevDocument: true,
+ shouldIncludePrevDocument: true,
});
describe('PrevDocCollection Serverside', function () {
- it('Should receive an insert event with prev doc', async function (done) {
- Config.pubSubManager.subscribe('test_redis_prev_doc', function(payload) {
- // make sure events have prev document values
- if (payload.e === 'u') {
- assert.equal(payload.d.value, 'oldValue');
- }
- if (payload.e === 'r') {
- assert.equal(payload.d.value, 'newValue');
- done();
- }
+ it('Should receive an insert event with prev doc', function (done) {
+ Config.pubSubManager.subscribe('test_redis_prev_doc', function (payload) {
+ // make sure events have prev document values
+ if (payload.e === 'u') {
+ assert.equal(payload.d.value, 'oldValue');
+ }
+ if (payload.e === 'r') {
+ assert.equal(payload.d.value, 'newValue');
+ done();
+ }
+ });
+
+ const random = Random.id()
+
+ // trigger insert update and removed redis events
+ PrevDocCollection.insert({ _id: `${random}`, value: 'oldValue' });
+ PrevDocCollection.update({ _id: `${random}` }, { $set: { value: 'newValue' } });
+ PrevDocCollection.remove({ _id: `${random}` });
});
- const random = Random.id()
-
- // trigger insert update and removed redis events
- PrevDocCollection.insert({ _id: `${random}`, value: 'oldValue' });
- PrevDocCollection.update({ _id: `${random}` }, { $set: { value: 'newValue' } });
- PrevDocCollection.remove({ _id: `${random}` });
- });
-
- it('Should receive an insert event without prev doc', async function (done) {
- Config.pubSubManager.subscribe('test_redis_no_prev_doc', function(payload) {
- // make sure events do not have any prev document values
- // because NoPrevDocCollection does not have shouldIncludePrevDocument set
- // to true
- if (payload.e === 'u') {
- assert.equal(payload.d.value, undefined);
- }
- if (payload.e === 'r') {
- assert.equal(payload.d.value, undefined);
- done();
- }
+ it('Should receive an insert event without prev doc', function (done) {
+ Config.pubSubManager.subscribe('test_redis_no_prev_doc', function (payload) {
+ // make sure events do not have any prev document values
+ // because NoPrevDocCollection does not have shouldIncludePrevDocument set
+ // to true
+ if (payload.e === 'u') {
+ assert.equal(payload.d.value, undefined);
+ }
+ if (payload.e === 'r') {
+ assert.equal(payload.d.value, undefined);
+ done();
+ }
+ });
+
+ // trigger insert update and removed redis events
+ NoPrevDocCollection.insert({ _id: 'no_prev_doc_1', value: 'oldValue' });
+ NoPrevDocCollection.update({ _id: 'no_prev_doc_1' }, { $set: { value: 'newValue' } });
+ NoPrevDocCollection.remove({ _id: 'no_prev_doc_1' });
});
-
- // trigger insert update and removed redis events
- NoPrevDocCollection.insert({ _id: 'no_prev_doc_1', value: 'oldValue' });
- NoPrevDocCollection.update({ _id: 'no_prev_doc_1' }, { $set: { value: 'newValue' } });
- NoPrevDocCollection.remove({ _id: 'no_prev_doc_1' });
- });
});
diff --git a/testing/lib/helpers.js b/testing/lib/helpers.js
index 847573fc..d52fc836 100644
--- a/testing/lib/helpers.js
+++ b/testing/lib/helpers.js
@@ -1,4 +1,5 @@
-import {waitForHandleToBeReady, callWithPromise} from './sync_utils';
+import { Meteor } from 'meteor/meteor';
+import { waitForHandleToBeReady, callWithPromise } from './sync_utils';
export default (suffix) => {
const create = (...args) => {
@@ -69,4 +70,4 @@ export default (suffix) => {
syntheticSync,
waitForHandleToBeReady
}
-}
\ No newline at end of file
+}
diff --git a/testing/lib/sync_utils.js b/testing/lib/sync_utils.js
index c7dee4ca..bcb98d7f 100644
--- a/testing/lib/sync_utils.js
+++ b/testing/lib/sync_utils.js
@@ -1,3 +1,6 @@
+import { Meteor } from 'meteor/meteor';
+import { Tracker } from 'meteor/tracker';
+
const callWithPromise = (method, ...args) => {
return new Promise((resolve, reject) => {
Meteor.call(method, ...args, (err, res) => {
@@ -11,7 +14,7 @@ const callWithPromise = (method, ...args) => {
Meteor.callWithPromise = callWithPromise;
const waitForHandleToBeReady = handle => {
- return new Promise((resolve, reject) => {
+ return new Promise((resolve) => {
Tracker.autorun(c => {
if (handle.ready()) {
c.stop();
diff --git a/testing/main.client.js b/testing/main.client.js
index cbab9d3f..7ce6b9d0 100644
--- a/testing/main.client.js
+++ b/testing/main.client.js
@@ -32,8 +32,8 @@ _.each(Collections, (Collection, key) => {
waitForHandleToBeReady,
} = helperGenerator(config[key].suffix);
- describe('It should work with: ' + key, function() {
- it('Should detect a removal', async function(done) {
+ describe('It should work with: ' + key, function () {
+ it('Should detect a removal', function (done) {
let handle = subscribe(
{
game: 'chess',
@@ -62,12 +62,14 @@ _.each(Collections, (Collection, key) => {
},
});
- await waitForHandleToBeReady(handle);
-
- _id = await createSync({ game: 'chess', title: randomTitle });
+ waitForHandleToBeReady(handle).then(function () {
+ createSync({ game: 'chess', title: randomTitle }).then(function (id) {
+ _id = id;
+ });
+ });
});
- it('Should detect an insert', async function(done) {
+ it('Should detect an insert', function (done) {
let handle = subscribe(
{
game: 'chess',
@@ -85,25 +87,26 @@ _.each(Collections, (Collection, key) => {
if (doc.title === 'E') {
observeChangesHandle.stop();
handle.stop();
- remove({ _id: docId }, function() {
+ remove({ _id: docId }, function () {
done();
});
}
},
});
- await waitForHandleToBeReady(handle);
- let data = cursor.fetch();
+ waitForHandleToBeReady(handle).then(function () {
+ let data = cursor.fetch();
- assert.lengthOf(data, 3);
+ assert.lengthOf(data, 3);
- create({
- game: 'chess',
- title: 'E',
+ create({
+ game: 'chess',
+ title: 'E',
+ });
});
});
- it('Should detect an update simple', async function(done) {
+ it('Should detect an update simple', function (done) {
let handle = subscribe(
{
game: 'chess',
@@ -124,22 +127,22 @@ _.each(Collections, (Collection, key) => {
},
});
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ let data = cursor.fetch();
- let data = cursor.fetch();
-
- update(
- { _id: data[0]._id },
- {
- $set: {
- score: Math.random(),
- },
- }
- );
+ update(
+ { _id: data[0]._id },
+ {
+ $set: {
+ score: Math.random(),
+ },
+ }
+ );
+ });
});
- it('Should detect an update deeply nested', async function(done) {
- let docId = await createSync({
+ it('Should detect an update deeply nested', function (done) {
+ createSync({
game: 'chess',
nested: {
a: 1,
@@ -148,143 +151,143 @@ _.each(Collections, (Collection, key) => {
a: 1,
},
},
- });
+ }).then(function (docId) {
+ let handle = subscribe({ _id: docId });
+ const cursor = Collection.find({ _id: docId });
- let handle = subscribe({ _id: docId });
- const cursor = Collection.find({ _id: docId });
+ const observeChangesHandle = cursor.observeChanges({
+ changed(docId, doc) {
+ observeChangesHandle.stop();
+ handle.stop();
- const observeChangesHandle = cursor.observeChanges({
- changed(docId, doc) {
- observeChangesHandle.stop();
- handle.stop();
+ assert.equal(doc.nested.b, 2);
+ assert.equal(doc.nested.a, 1);
+ assert.equal(doc.nested.c.b, 1);
+ assert.equal(doc.nested.c.a, 1);
+ assert.equal(doc.nested.d, 1);
+ assert.lengthOf(Object.keys(doc), 1);
+ assert.lengthOf(Object.keys(doc.nested), 4);
- assert.equal(doc.nested.b, 2);
- assert.equal(doc.nested.a, 1);
- assert.equal(doc.nested.c.b, 1);
- assert.equal(doc.nested.c.a, 1);
- assert.equal(doc.nested.d, 1);
- assert.lengthOf(_.keys(doc), 1);
- assert.lengthOf(_.keys(doc.nested), 4);
+ remove({ _id: docId }, () => {
+ done();
+ });
+ },
+ });
- remove({ _id: docId }, () => {
- done();
- });
- },
+ waitForHandleToBeReady(handle).then(function () {
+ update(
+ { _id: docId },
+ {
+ $set: {
+ 'nested.c.b': 1,
+ 'nested.b': 2,
+ 'nested.d': 1,
+ },
+ }
+ );
+ });
});
-
- await waitForHandleToBeReady(handle);
-
- update(
- { _id: docId },
- {
- $set: {
- 'nested.c.b': 1,
- 'nested.b': 2,
- 'nested.d': 1,
- },
- }
- );
});
- it('Should not update multiple documents if not specified (multi:true)', async function(done) {
+ it('Should not update multiple documents if not specified (multi:true)', function (done) {
const context = Random.id();
- [_id1, _id2] = await createSync([
+ createSync([
{ context, game: 'monopoly', title: 'test' },
{ context, game: 'monopoly', title: 'test2' },
- ]);
-
- let handle = subscribe({ game: 'monopoly' });
- await waitForHandleToBeReady(handle);
-
- const cursor = Collection.find({ _id: { $in: [_id1, _id2] } });
+ ]).then(function ([_id1, _id2]) {
+ let handle = subscribe({ game: 'monopoly' });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ _id: { $in: [_id1, _id2] } });
+
+ const observeChangesHandle = cursor.observeChanges({
+ changed(docId) {
+ assert.equal(docId, _id1);
+ observeChangesHandle.stop();
+ handle.stop();
+ done();
- const observeChangesHandle = cursor.observeChanges({
- changed(docId) {
- assert.equal(docId, _id1);
- observeChangesHandle.stop();
- handle.stop();
- done();
+ remove({ context, game: 'monopoly' });
+ },
+ });
- remove({ context, game: 'monopoly' });
- },
+ update(
+ { context, game: 'monopoly' },
+ { $set: { score: Math.random() } }
+ );
+ });
});
-
- update(
- { context, game: 'monopoly' },
- { $set: { score: Math.random() } }
- );
});
- it('Should update multiple documents if specified', async function(done) {
+ it('Should update multiple documents if specified', function (done) {
const context = 'multi-update';
- [_id1, id2] = await createSync([
+ createSync([
{ context, title: 'test' },
{ context, title: 'test2' },
- ]);
-
- let handle = subscribe({ context });
- await waitForHandleToBeReady(handle);
-
- const cursor = Collection.find({ context });
-
- let changes = 0;
- const observeChangesHandle = cursor.observeChanges({
- changed(docId) {
- changes += 1;
+ ]).then(function ([_id1, _id2]) {
+ let handle = subscribe({ context });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
+
+ let changes = 0;
+ const observeChangesHandle = cursor.observeChanges({
+ changed(docId) {
+ changes += 1;
+
+ if (changes === 2) {
+ observeChangesHandle.stop();
+ handle.stop();
+ done();
+ }
+ },
+ });
- if (changes === 2) {
- observeChangesHandle.stop();
- handle.stop();
- done();
- }
- },
+ update(
+ { context },
+ {
+ $set: { score: Math.random() },
+ },
+ { multi: true }
+ );
+ });
});
-
- update(
- { context },
- {
- $set: { score: Math.random() },
- },
- { multi: true }
- );
});
- it('Should detect an update of a non published document', async function(done) {
- let _id = await createSync({
+ it('Should detect an update of a non published document', function (done) {
+ let _id = createSync({
game: 'backgammon',
title: 'test',
- });
+ }).then(function (_id) {
+ let handle = subscribe({
+ game: 'chess',
+ });
- let handle = subscribe({
- game: 'chess',
- });
+ const score = Math.random();
+ const cursor = Collection.find();
- const score = Math.random();
- const cursor = Collection.find();
+ const observeChangesHandle = cursor.observeChanges({
+ added(docId, doc) {
+ if (docId !== _id) return;
- const observeChangesHandle = cursor.observeChanges({
- added(docId, doc) {
- if (docId !== _id) return;
+ assert.equal(doc.game, 'chess');
+ assert.equal(doc.score, score);
+ assert.equal(doc.title, 'test');
- assert.equal(doc.game, 'chess');
- assert.equal(doc.score, score);
- assert.equal(doc.title, 'test');
+ observeChangesHandle.stop();
+ handle.stop();
+ remove({ _id }, () => {
+ done();
+ });
+ },
+ });
- observeChangesHandle.stop();
- handle.stop();
- remove({ _id }, () => {
- done();
- });
- },
+ waitForHandleToBeReady(handle).then(function () {
+ update({ _id }, { $set: { game: 'chess', score } });
+ });
});
-
- await waitForHandleToBeReady(handle);
-
- update({ _id }, { $set: { game: 'chess', score } });
});
- it('Should detect an update of a nested field when fields is specified', async function(done) {
- let _id = await createSync({
+ it('Should detect an update of a nested field when fields is specified', function (done) {
+ createSync({
roles: {
_groups: ['company1', 'company2', 'company3'],
_main: 'company1',
@@ -292,34 +295,35 @@ _.each(Collections, (Collection, key) => {
roles: ['manage-users', 'manage-profiles'],
},
},
- });
+ }).then(function (_id) {
+ let handle = subscribe(
+ {},
+ {
+ fields: { roles: 1 },
+ }
+ );
- let handle = subscribe(
- {},
- {
- fields: { roles: 1 },
- }
- );
+ const cursor = Collection.find();
+ const observeChangesHandle = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ handle.stop();
+ observeChangesHandle.stop();
+ done();
+ remove({ _id });
+ },
+ });
- const cursor = Collection.find();
- const observeChangesHandle = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- handle.stop();
- observeChangesHandle.stop();
- done();
- remove({ _id });
- },
+ waitForHandleToBeReady(handle).then(function () {
+ update({ _id }, { $set: { 'roles._main': 'company2' } });
+ });
});
-
- await waitForHandleToBeReady(handle);
- update({ _id }, { $set: { 'roles._main': 'company2' } });
});
- it('Should update properly a nested field when a positional parameter is used', async function(done) {
+ it('Should update properly a nested field when a positional parameter is used', function (done) {
const context = 'positional-paramter';
- let _id = await createSync({
+ createSync({
context,
bom: [
{
@@ -335,607 +339,610 @@ _.each(Collections, (Collection, key) => {
quantity: 3,
},
],
- });
+ }).then(function (_id) {
+ let handle = subscribe(
+ { context },
+ {
+ fields: {
+ context: 1,
+ bom: 1,
+ },
+ }
+ );
- let handle = subscribe(
- { context },
- {
- fields: {
- context: 1,
- bom: 1,
+ const cursor = Collection.find({ context });
+ const observeChangesHandle = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ doc.bom.forEach(element => {
+ assert.isTrue(Object.keys(element).length === 2);
+ if (element.stockId === 1) {
+ assert.equal(element.quantity, 30);
+ } else {
+ assert.equal(element.quantity, element.stockId);
+ }
+ });
+ handle.stop();
+ observeChangesHandle.stop();
+ remove({ _id });
+ done();
},
- }
- );
+ });
- const cursor = Collection.find({ context });
- const observeChangesHandle = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- doc.bom.forEach(element => {
- assert.isTrue(_.keys(element).length === 2);
- if (element.stockId === 1) {
- assert.equal(element.quantity, 30);
- } else {
- assert.equal(element.quantity, element.stockId);
+ waitForHandleToBeReady(handle).then(function () {
+ update(
+ { _id, 'bom.stockId': 1 },
+ {
+ $set: { 'bom.$.quantity': 30 },
}
- });
- handle.stop();
- observeChangesHandle.stop();
- remove({ _id });
- done();
- },
+ );
+ });
});
-
- await waitForHandleToBeReady(handle);
-
- update(
- { _id, 'bom.stockId': 1 },
- {
- $set: { 'bom.$.quantity': 30 },
- }
- );
});
['server'].forEach(context => {
- it('Should work with $and operators: ' + context, async function(
- done
- ) {
- let _id = await createSync({
+ it('Should work with $and operators: ' + context, function (done) {
+ createSync({
orgid: '1',
siteIds: ['1', '2'],
Year: 2017,
- });
-
- let handle = subscribe({
- $and: [
- {
- orgid: '1',
- },
- {
- siteIds: { $in: ['1'] },
- },
- {
- Year: { $in: [2017] },
- },
- ],
- });
+ }).then(function (_id) {
+ let handle = subscribe({
+ $and: [
+ {
+ orgid: '1',
+ },
+ {
+ siteIds: { $in: ['1'] },
+ },
+ {
+ Year: { $in: [2017] },
+ },
+ ],
+ });
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find();
+ let inChangedEvent = false;
+ const observeChangesHandle = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ inChangedEvent = true;
+ // assert.equal(doc.something, 30);
+ update({ _id }, { $set: { Year: 2018 } });
+ },
+ removed(docId) {
+ assert.isTrue(inChangedEvent);
+ assert.equal(docId, _id);
- const cursor = Collection.find();
- let inChangedEvent = false;
- const observeChangesHandle = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- inChangedEvent = true;
- // assert.equal(doc.something, 30);
- update({ _id }, { $set: { Year: 2018 } });
- },
- removed(docId) {
- assert.isTrue(inChangedEvent);
- assert.equal(docId, _id);
+ handle.stop();
+ observeChangesHandle.stop();
+ done();
+ },
+ });
- handle.stop();
- observeChangesHandle.stop();
- done();
- },
+ update(
+ { _id },
+ {
+ $set: {
+ something: 30,
+ },
+ }
+ );
+ });
});
-
- update(
- { _id },
- {
- $set: {
- something: 30,
- },
- }
- );
});
});
- it('Should be able to detect subsequent updates for direct processing with _ids', async function(done) {
- let [_id1, _id2] = await createSync([
+ it('Should be able to detect subsequent updates for direct processing with _ids', function (done) {
+ createSync([
{ subsequent_test: true, name: 'John Smith' },
{ subsequent_test: true, name: 'Michael Willow' },
- ]);
-
- let handle = subscribe(
- { _id: { $in: [_id1, _id2] } },
- {
- fields: { subsequent_test: 1, name: 1 },
- }
- );
-
- const cursor = Collection.find({ subsequent_test: true });
- let inFirst = false;
-
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- if (docId == _id1) {
- inFirst = true;
- assert.equal('John Smithy', doc.name);
- }
- if (docId == _id2) {
- assert.isTrue(inFirst);
- assert.equal('Michael Willowy', doc.name);
- handle.stop();
- observer.stop();
- done();
+ ]).then(function ([_id1, _id2]) {
+ let handle = subscribe(
+ { _id: { $in: [_id1, _id2] } },
+ {
+ fields: { subsequent_test: 1, name: 1 },
}
- },
- });
+ );
- await waitForHandleToBeReady(handle);
+ const cursor = Collection.find({ subsequent_test: true });
+ let inFirst = false;
- await updateSync(_id1, {
- $set: { name: 'John Smithy' },
- });
- await updateSync(_id2, {
- $set: { name: 'Michael Willowy' },
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ if (docId == _id1) {
+ inFirst = true;
+ assert.equal('John Smithy', doc.name);
+ }
+ if (docId == _id2) {
+ assert.isTrue(inFirst);
+ assert.equal('Michael Willowy', doc.name);
+ handle.stop();
+ observer.stop();
+ done();
+ }
+ },
+ });
+
+ waitForHandleToBeReady(handle).then(function () {
+ updateSync(_id1, {
+ $set: { name: 'John Smithy' },
+ }).then(function () {
+ updateSync(_id2, {
+ $set: { name: 'Michael Willowy' },
+ });
+ });
+ });
});
});
- it('Should work with the $addToSet', async function(done) {
- let _id = await createSync({
+ it('Should work with the $addToSet', function (done) {
+ createSync({
operators: true,
connections: [1, 2],
number: 10,
- });
+ }).then(function (_id) {
+ let handle = subscribe({ _id });
+ let cursor = Collection.find({ _id });
- let handle = subscribe({ _id });
- let cursor = Collection.find({ _id });
+ waitForHandleToBeReady(handle).then(function () {
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ assert.lengthOf(doc.connections, 3);
- await waitForHandleToBeReady(handle);
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- assert.lengthOf(doc.connections, 3);
-
- observer.stop();
- handle.stop();
- done();
- },
+ updateSync(
+ { _id },
+ {
+ $addToSet: {
+ connections: 3,
+ },
+ }
+ );
+ });
});
-
- await updateSync(
- { _id },
- {
- $addToSet: {
- connections: 3,
- },
- }
- );
});
- it('Should work with the $pull', async function(done) {
- let _id = await createSync({
+ it('Should work with the $pull', function (done) {
+ createSync({
operators: true,
connections: [1, 2],
number: 10,
- });
-
- let handle = subscribe({ _id });
- let cursor = Collection.find({ _id });
+ }).then(function (_id) {
+ let handle = subscribe({ _id });
+ let cursor = Collection.find({ _id });
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ assert.lengthOf(doc.connections, 1);
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- assert.lengthOf(doc.connections, 1);
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- observer.stop();
- handle.stop();
- done();
- },
+ updateSync(
+ { _id },
+ {
+ $pull: {
+ connections: 2,
+ },
+ }
+ );
+ });
});
-
- await updateSync(
- { _id },
- {
- $pull: {
- connections: 2,
- },
- }
- );
});
- it('Should work with nested field updates', async function(done) {
- let _id = await createSync({
+ it('Should work with nested field updates', function (done) {
+ createSync({
profile: {
language: 'EN',
email: 'xxx@xxx.com',
number: 5,
},
- });
-
- let handle = subscribe({ _id });
- let cursor = Collection.find({ _id });
+ }).then(function (_id) {
+ let handle = subscribe({ _id });
+ let cursor = Collection.find({ _id });
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ assert.equal(doc.profile.number, 10);
+ const fullDoc = Collection.findOne(docId);
+ assert.equal(fullDoc.profile.language, 'EN');
+ assert.equal(fullDoc.profile.email, 'xxx@xxx.com');
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- assert.equal(doc.profile.number, 10);
- const fullDoc = Collection.findOne(docId);
- assert.equal(fullDoc.profile.language, 'EN');
- assert.equal(fullDoc.profile.email, 'xxx@xxx.com');
-
- observer.stop();
- handle.stop();
- done();
- },
- });
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- await updateSync(_id, {
- $set: {
- 'profile.number': 10,
- },
+ updateSync(_id, {
+ $set: {
+ 'profile.number': 10,
+ },
+ });
+ });
});
});
- it('Should work with the $pull and $set in combination', async function(done) {
- let _id = await createSync({
+ it('Should work with the $pull and $set in combination', function (done) {
+ createSync({
test_pull_and_set_combo: true,
connections: [1],
number: 10,
- });
-
- let handle = subscribe({ test_pull_and_set_combo: true });
- let cursor = Collection.find(
- {
- _id: {
- $in: [_id],
- },
- },
- {
- fields: {
- connections: 1,
- number: 1,
+ }).then(function (_id) {
+ let handle = subscribe({ test_pull_and_set_combo: true });
+ let cursor = Collection.find(
+ {
+ _id: {
+ $in: [_id],
+ },
},
- }
- );
-
- await waitForHandleToBeReady(handle);
+ {
+ fields: {
+ connections: 1,
+ number: 1,
+ },
+ }
+ );
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- assert.equal(doc.number, 20);
- assert.lengthOf(doc.connections, 0);
+ waitForHandleToBeReady(handle).then(function () {
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ assert.equal(doc.number, 20);
+ assert.lengthOf(doc.connections, 0);
- observer.stop();
- handle.stop();
- done();
- },
- });
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- await updateSync(_id, {
- $pull: {
- connections: { $in: [1] },
- },
- $set: {
- number: 20,
- },
+ updateSync(_id, {
+ $pull: {
+ connections: { $in: [1] },
+ },
+ $set: {
+ number: 20,
+ },
+ });
+ });
});
});
- it('Should work properly with limit-sort kind of queries', async function(done) {
+ it('Should work properly with limit-sort kind of queries', function (done) {
const context = 'limit-sort-test';
const limit = 5;
- await removeSync({ context });
+ removeSync({ context }).then(function () {
+ createSync([
+ { context, number: 5, text: 'T - 1' },
+ { context, number: 10, text: 'T - 2' },
+ { context, number: 15, text: 'T - 3' },
+ { context, number: 20, text: 'T - 4' },
+ { context, number: 25, text: 'T - 5' },
+ { context, number: -1, text: 'T - Last one' },
+ ]).then(function (ids) {
+ const [_id1, _id2, _id3, _id4, _id5, _id6] = ids;
+
+ const handle = subscribe(
+ {
+ context,
+ },
+ {
+ limit,
+ sort: { number: -1 },
+ }
+ );
- const ids = await createSync([
- { context, number: 5, text: 'T - 1' },
- { context, number: 10, text: 'T - 2' },
- { context, number: 15, text: 'T - 3' },
- { context, number: 20, text: 'T - 4' },
- { context, number: 25, text: 'T - 5' },
- { context, number: -1, text: 'T - Last one' },
- ]);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
+ let inChanged = false;
+ let initialAddBlast = true;
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id2);
+ assert.equal(doc.number, 30);
+ inChanged = true;
+ },
+ removed(docId) {
+ if (docId === _id3) {
+ assert.equal(docId, _id3);
+
+ // Now we will add it back!
+ updateSync(
+ { _id: _id3 },
+ {
+ $set: { context },
+ }
+ );
+ }
+ },
+ added(docId, doc) {
+ if (initialAddBlast) {
+ return;
+ }
+
+ if (docId === _id6) {
+ // console.log('id6 has been added bc id3 has been removed.');
+ } else {
+ // console.log('id3 should be added back');
+ assert.equal(docId, _id3);
+ assert.isTrue(inChanged);
+
+ observer.stop();
+ handle.stop();
+ done();
+ }
+ }
+ });
- const [_id1, _id2, _id3, _id4, _id5, _id6] = ids;
+ initialAddBlast = false;
+ const data = cursor.fetch();
- const handle = subscribe(
- {
- context,
- },
- {
- limit,
- sort: { number: -1 },
- }
- );
+ assert.lengthOf(data, limit);
- await waitForHandleToBeReady(handle);
+ // We make sure that that the last element does not exist and is properly sorted.
+ assert.isTrue(data.find(el => el._id === _id6) === undefined);
+ // ids.forEach((_id, idx) => {
+ // assert.equal(data[limit - 1 - idx]._id, _id);
+ // });
- const cursor = Collection.find({ context });
- let inChanged = false;
- let initialAddBlast = true;
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id2);
- assert.equal(doc.number, 30);
- inChanged = true;
- },
- removed(docId) {
- if (docId === _id3) {
- assert.equal(docId, _id3);
-
- // Now we will add it back!
+ updateSync(
+ { _id: _id2 },
+ {
+ $set: { number: 30 },
+ }
+ );
updateSync(
{ _id: _id3 },
{
- $set: { context },
+ $set: { context: 'limit-sort-test-invalidate' },
}
);
- }
- },
- added(docId, doc) {
- if (initialAddBlast) {
- return;
- }
-
- if (docId === _id6) {
- // console.log('id6 has been added bc id3 has been removed.');
- } else {
- // console.log('id3 should be added back');
- assert.equal(docId, _id3);
- assert.isTrue(inChanged);
-
- observer.stop();
- handle.stop();
- done();
- }
- }
+ });
+ });
});
-
- initialAddBlast = false;
- const data = cursor.fetch();
-
- assert.lengthOf(data, limit);
-
- // We make sure that that the last element does not exist and is properly sorted.
- assert.isTrue(data.find(el => el._id === _id6) === undefined);
- // ids.forEach((_id, idx) => {
- // assert.equal(data[limit - 1 - idx]._id, _id);
- // });
-
- updateSync(
- { _id: _id2 },
- {
- $set: { number: 30 },
- }
- );
- updateSync(
- { _id: _id3 },
- {
- $set: { context: 'limit-sort-test-invalidate' },
- }
- );
});
- it('Should work with _ids direct processing and other filters present', async function(done) {
+ it('Should work with _ids direct processing and other filters present', function (done) {
const context = 'ids-process-test';
- const ids = await createSync([
+ createSync([
{ context, meta: { student: false } },
{ context, meta: { student: true } },
{ context, meta: { student: true } },
- ]);
-
- const handle = subscribe({
- _id: { $in: ids },
- 'meta.student': true,
- });
-
- await waitForHandleToBeReady(handle);
+ ]).then(function (ids) {
+ const handle = subscribe({
+ _id: { $in: ids },
+ 'meta.student': true,
+ });
- let cursor = Collection.find({ context });
- const data = cursor.fetch();
+ waitForHandleToBeReady(handle).then(function () {
+ let cursor = Collection.find({ context });
+ const data = cursor.fetch();
- assert.lengthOf(data, 2);
+ assert.lengthOf(data, 2);
- const observer = cursor.observeChanges({
- removed(docId) {
- assert.equal(docId, ids[0]);
+ const observer = cursor.observeChanges({
+ removed(docId) {
+ assert.equal(docId, ids[0]);
- observer.stop();
- handle.stop();
- done();
- },
- added(docId, doc) {
- if (docId == ids[0]) {
- assert.equal(docId, ids[0]);
- update(ids[0], {
- $set: { 'meta.changing': true },
- });
- }
- },
- changed(docId, doc) {
- if (docId == ids[0]) {
- update(ids[0], {
- $set: { 'meta.student': false },
- });
- }
- },
- });
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ added(docId, doc) {
+ if (docId == ids[0]) {
+ assert.equal(docId, ids[0]);
+ update(ids[0], {
+ $set: { 'meta.changing': true },
+ });
+ }
+ },
+ changed(docId, doc) {
+ if (docId == ids[0]) {
+ update(ids[0], {
+ $set: { 'meta.student': false },
+ });
+ }
+ },
+ });
- updateSync(ids[0], {
- $set: { 'meta.student': true },
+ updateSync(ids[0], {
+ $set: { 'meta.student': true },
+ });
+ });
});
});
- it('Should detect an insert with the default processor', async function(done) {
+ it('Should detect an insert with the default processor', function (done) {
const context = 'insert-default-processing' + Random.id();
const handle = subscribe({ context });
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
- const cursor = Collection.find({ context });
+ let observer;
+ observer = cursor.observeChanges({
+ added(docId, doc) {
+ assert.equal(doc.context, context);
+ setTimeout(() => {
+ observer.stop();
+ handle.stop();
+ done();
+ }, 50);
+ },
+ });
- let observer;
- observer = cursor.observeChanges({
- added(docId, doc) {
- assert.equal(doc.context, context);
- setTimeout(() => {
- observer.stop();
- handle.stop();
- done();
- }, 50);
- },
+ create({ context });
});
-
- create({ context });
});
- it('Should detect an update with string publication that should be id', async function(done) {
+ it('Should detect an update with string publication that should be id', function (done) {
const context = 'string-filters';
- let _id = await createSync({ context });
- const handle = subscribe(_id);
+ createSync({ context }).then(function (_id) {
+ const handle = subscribe(_id);
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
- const cursor = Collection.find({ context });
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ assert.equal(doc.number, 10);
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- assert.equal(doc.number, 10);
- observer.stop();
- handle.stop();
- done();
- },
+ update(_id, { $set: { number: 10 } });
+ });
});
-
- update(_id, { $set: { number: 10 } });
});
- it('Should work with deep nest specified fields', async function(done) {
+ it('Should work with deep nest specified fields', function (done) {
const context = 'edge-case-001';
- let _id = await createSync({
+ createSync({
context,
passengers: [],
- });
- const handle = subscribe(_id, {
- fields: {
- context: 1,
- 'passengers.name': 1,
- },
- });
-
- await waitForHandleToBeReady(handle);
+ }).then(function (_id) {
+ const handle = subscribe(_id, {
+ fields: {
+ context: 1,
+ 'passengers.name': 1,
+ },
+ });
- const cursor = Collection.find({ context });
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- assert.lengthOf(doc.passengers, 1);
- observer.stop();
- handle.stop();
- done();
- },
- });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ assert.lengthOf(doc.passengers, 1);
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- update(_id, {
- $addToSet: {
- passengers: {
- _id: 'y2MECXDgr9ggiP5D4',
- name: 'Marlee Nielsen',
- phone: '',
- },
- },
+ update(_id, {
+ $addToSet: {
+ passengers: {
+ _id: 'y2MECXDgr9ggiP5D4',
+ name: 'Marlee Nielsen',
+ phone: '',
+ },
+ },
+ });
+ });
});
});
- it('Should work with upsert', async function(done) {
+ it('Should work with upsert', function (done) {
const context = 'upsertion' + Random.id();
const handle = subscribe({ context });
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ assert.equal(doc.number, 10);
+ upsert(
+ { context },
+ {
+ $set: {
+ number: 20,
+ },
+ }
+ );
+ },
+ changed(docId, doc) {
+ assert.equal(doc.number, 20);
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- const cursor = Collection.find({ context });
- const observer = cursor.observeChanges({
- added(docId, doc) {
- assert.equal(doc.number, 10);
- upsert(
- { context },
- {
- $set: {
- number: 20,
- },
- }
- );
- },
- changed(docId, doc) {
- assert.equal(doc.number, 20);
- observer.stop();
- handle.stop();
- done();
- },
+ upsert(
+ { context },
+ {
+ context,
+ number: 10,
+ }
+ );
});
-
- upsert(
- { context },
- {
- context,
- number: 10,
- }
- );
});
- it('Should not detect a change if pushToRedis is false', async function(done) {
+ it('Should not detect a change if pushToRedis is false', function (done) {
const context = 'pushToRedis:false';
const handle = subscribe({ context });
- await waitForHandleToBeReady(handle);
-
- const cursor = Collection.find({ context });
- let _id;
- const observer = cursor.observeChanges({
- added(docId, doc) {
- if (docId === _id) {
- done('Should not be in added');
- }
- },
- changed(docId, doc) {
- if (docId === _id) {
- done('Should not be in changed');
- }
- },
- removed(docId) {
- if (docId === _id) {
- done('Should not be in changed');
- }
- },
- });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
+ let _id;
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ if (docId === _id) {
+ done('Should not be in added');
+ }
+ },
+ changed(docId, doc) {
+ if (docId === _id) {
+ done('Should not be in changed');
+ }
+ },
+ removed(docId) {
+ if (docId === _id) {
+ done('Should not be in changed');
+ }
+ },
+ });
- _id = await createSync(
- {
- context,
- },
- { pushToRedis: false }
- );
+ createSync(
+ {
+ context,
+ },
+ { pushToRedis: false }
+ ).then(function (id) {
+ _id = id;
- update(
- { _id },
- {
- $set: { number: 10 },
- },
- { pushToRedis: false },
- (err, res) => {
- remove({ _id }, { pushToRedis: false });
- }
- );
+ update(
+ { _id },
+ {
+ $set: { number: 10 },
+ },
+ { pushToRedis: false },
+ (err, res) => {
+ remove({ _id }, { pushToRedis: false });
+ }
+ );
- setTimeout(() => {
- observer.stop();
- handle.stop();
- done();
- }, 200);
+ setTimeout(() => {
+ observer.stop();
+ handle.stop();
+ done();
+ }, 200);
+ });
+ });
});
- it('Should work correctly when disallowed fields are specified', async function(done) {
+ it('Should work correctly when disallowed fields are specified', function (done) {
const context = 'disallowed-fields-' + Random.id();
const handle = subscribe(
{ context },
@@ -948,65 +955,67 @@ _.each(Collections, (Collection, key) => {
}
);
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
- const cursor = Collection.find({ context });
+ let _id;
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ if (doc.context !== context) return;
- let _id;
- const observer = cursor.observeChanges({
- added(docId, doc) {
- if (doc.context !== context) return;
+ assert.equal(doc.other, 'Public');
+ assert.isUndefined(doc.profile);
+ assert.isObject(doc.address);
+ assert.isString(doc.address.country);
+ assert.isUndefined(doc.address.city);
+ assert.isUndefined(doc.fullname);
- assert.equal(doc.other, 'Public');
- assert.isUndefined(doc.profile);
- assert.isObject(doc.address);
- assert.isString(doc.address.country);
- assert.isUndefined(doc.address.city);
- assert.isUndefined(doc.fullname);
+ update(
+ { _id: docId },
+ {
+ $set: {
+ 'address.country': 'Testing',
+ fullname: 'Testing',
+ other: 'Publico',
+ newField: 'public',
+ 'profile.firstName': 'John',
+ },
+ }
+ );
+ },
+ changed(docId, doc) {
+ assert.equal(doc.other, 'Publico');
+ assert.isUndefined(doc.profile);
+ assert.isObject(doc.address);
+ assert.equal(doc.address.country, 'Testing');
+ assert.equal(doc.newField, 'public');
+ assert.isUndefined(doc.address.city);
+ assert.isUndefined(doc.fullname);
- update(
- { _id: docId },
- {
- $set: {
- 'address.country': 'Testing',
- fullname: 'Testing',
- other: 'Publico',
- newField: 'public',
- 'profile.firstName': 'John',
- },
- }
- );
- },
- changed(docId, doc) {
- assert.equal(doc.other, 'Publico');
- assert.isUndefined(doc.profile);
- assert.isObject(doc.address);
- assert.equal(doc.address.country, 'Testing');
- assert.equal(doc.newField, 'public');
- assert.isUndefined(doc.address.city);
- assert.isUndefined(doc.fullname);
-
- observer.stop();
- handle.stop();
- done();
- },
- });
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- _id = await createSync({
- context,
- profile: {
- name: 'Secret',
- },
- address: {
- country: 'Country',
- city: 'Secret',
- },
- fullname: 'Secret',
- other: 'Public',
+ createSync({
+ context,
+ profile: {
+ name: 'Secret',
+ },
+ address: {
+ country: 'Country',
+ city: 'Secret',
+ },
+ fullname: 'Secret',
+ other: 'Public',
+ }).then(function (id) {
+ _id = id;
+ });
});
});
- it('Should work correctly with the allowed fields only specified', async function(done) {
+ it('Should work correctly with the allowed fields only specified', function (done) {
const context = 'allowed-fields';
const handle = subscribe(
{ context },
@@ -1020,59 +1029,59 @@ _.each(Collections, (Collection, key) => {
}
);
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ assert.isUndefined(doc.other);
+ assert.isObject(doc.profile);
+ assert.isObject(doc.address);
+ assert.isString(doc.address.city);
+ assert.isUndefined(doc.address.country);
+ assert.isString(doc.fullname);
- const cursor = Collection.find({ context });
- const observer = cursor.observeChanges({
- added(docId, doc) {
- assert.isUndefined(doc.other);
- assert.isObject(doc.profile);
- assert.isObject(doc.address);
- assert.isString(doc.address.city);
- assert.isUndefined(doc.address.country);
- assert.isString(doc.fullname);
+ update(
+ { _id: docId },
+ {
+ $set: {
+ 'address.country': 'Testing',
+ fullname: 'Testing',
+ other: 'secret',
+ newField: 'secret',
+ 'profile.firstName': 'John',
+ },
+ }
+ );
+ },
+ changed(docId, doc) {
+ assert.isUndefined(doc.other);
+ assert.isObject(doc.profile);
+ assert.equal(doc.profile.firstName, 'John');
+ assert.isUndefined(doc.newField);
+ assert.equal(doc.fullname, 'Testing');
- update(
- { _id: docId },
- {
- $set: {
- 'address.country': 'Testing',
- fullname: 'Testing',
- other: 'secret',
- newField: 'secret',
- 'profile.firstName': 'John',
- },
- }
- );
- },
- changed(docId, doc) {
- assert.isUndefined(doc.other);
- assert.isObject(doc.profile);
- assert.equal(doc.profile.firstName, 'John');
- assert.isUndefined(doc.newField);
- assert.equal(doc.fullname, 'Testing');
-
- observer.stop();
- handle.stop();
- done();
- },
- });
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- let _id = await createSync({
- context,
- profile: {
- name: 'Public',
- },
- address: {
- country: 'Country',
- city: 'Public',
- },
- fullname: 'Public',
- other: 'Secret',
+ createSync({
+ context,
+ profile: {
+ name: 'Public',
+ },
+ address: {
+ country: 'Country',
+ city: 'Public',
+ },
+ fullname: 'Public',
+ other: 'Secret',
+ });
});
});
- it('Should work with limit-sort when only _id is specified', async function(done) {
+ it('Should work with limit-sort when only _id is specified', function (done) {
const context = Random.id();
const handle = subscribe(
{ context },
@@ -1086,76 +1095,76 @@ _.each(Collections, (Collection, key) => {
}
);
- await waitForHandleToBeReady(handle);
-
- const cursor = Collection.find({ context });
- const observer = cursor.observeChanges({
- added(docId, doc) {
- assert.isUndefined(doc.something);
- assert.isTrue(_.keys(doc).length == 1);
- update(
- { _id: docId },
- {
- $set: {
- something: false,
- },
- }
- );
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ assert.isUndefined(doc.something);
+ assert.isTrue(Object.keys(doc).length == 1);
+ update(
+ { _id: docId },
+ {
+ $set: {
+ something: false,
+ },
+ }
+ );
- done();
- },
- changed(docId, doc) {
- done(
- 'Should not be in changed event because nothing changed'
- );
- },
- });
+ done();
+ },
+ changed(docId, doc) {
+ done(
+ 'Should not be in changed event because nothing changed'
+ );
+ },
+ });
- create({
- context,
- something: true,
+ create({
+ context,
+ something: true,
+ });
});
});
- it('Should work properly with $unset', async function(done) {
+ it('Should work properly with $unset', function (done) {
const context = 'test-$unset';
const handle = subscribe({ context });
- await waitForHandleToBeReady(handle);
-
- const cursor = Collection.find({ context });
- const observer = cursor.observeChanges({
- added(docId, doc) {
- assert.isTrue(doc.something);
-
- setTimeout(() => {
- update(
- { _id: docId },
- {
- $unset: {
- something: '',
- },
- }
- );
- }, 50);
- },
- changed(docId, doc) {
- assert.isTrue('something' in doc);
- assert.isUndefined(doc.something);
- remove({ _id: docId });
- observer.stop();
- handle.stop();
- done();
- },
- });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ assert.isTrue(doc.something);
+
+ setTimeout(() => {
+ update(
+ { _id: docId },
+ {
+ $unset: {
+ something: '',
+ },
+ }
+ );
+ }, 50);
+ },
+ changed(docId, doc) {
+ assert.isTrue('something' in doc);
+ assert.isUndefined(doc.something);
+ remove({ _id: docId });
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- create({
- context,
- something: true,
+ create({
+ context,
+ something: true,
+ });
});
});
- it('Should work when updating deep array when it is specified as a field', async function(done) {
+ it('Should work when updating deep array when it is specified as a field', function (done) {
const context = `deep-array-objects-${Random.id()}`;
let handle = subscribe(
@@ -1168,51 +1177,51 @@ _.each(Collections, (Collection, key) => {
}
);
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
- const cursor = Collection.find({ context });
-
- const observer = cursor.observeChanges({
- added(docId, doc) {
- assert.isArray(doc.deep.deep.array);
- assert.lengthOf(doc.deep.deep.array, 6);
- update(
- {
- _id: docId,
- 'deep.deep.array': 6,
- },
- {
- $set: {
- 'deep.deep.array.$': 20,
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ assert.isArray(doc.deep.deep.array);
+ assert.lengthOf(doc.deep.deep.array, 6);
+ update(
+ {
+ _id: docId,
+ 'deep.deep.array': 6,
},
- }
- );
- },
- changed(docId, doc) {
- assert.isArray(doc.deep.deep.array);
- assert.lengthOf(doc.deep.deep.array, 6);
- doc.deep.deep.array.forEach(number => {
- assert.isNumber(number);
- });
- assert.isTrue(_.contains(doc.deep.deep.array, 20));
+ {
+ $set: {
+ 'deep.deep.array.$': 20,
+ },
+ }
+ );
+ },
+ changed(docId, doc) {
+ assert.isArray(doc.deep.deep.array);
+ assert.lengthOf(doc.deep.deep.array, 6);
+ doc.deep.deep.array.forEach(number => {
+ assert.isNumber(number);
+ });
+ assert.isTrue(_.contains(doc.deep.deep.array, 20));
- observer.stop();
- handle.stop();
- done();
- },
- });
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
- create({
- context,
- deep: {
+ create({
+ context,
deep: {
- array: [1, 2, 3, 4, 5, 6],
+ deep: {
+ array: [1, 2, 3, 4, 5, 6],
+ },
},
- },
+ });
});
});
- it('Should work when updating a specific element in an array', async function(done) {
+ it('Should work when updating a specific element in an array', function (done) {
const context = 'update-specific-in-arrays';
let handle = subscribe(
@@ -1225,48 +1234,49 @@ _.each(Collections, (Collection, key) => {
}
);
- await waitForHandleToBeReady(handle);
- const cursor = Collection.find({ context });
-
- const observer = cursor.observeChanges({
- added(docId, doc) {
- update(
- { _id: docId },
- {
- $set: {
- 'passengers.1.phone': 'ZZZ',
- },
- }
- );
- },
- changed(docId, doc) {
- doc.passengers.forEach(passenger => {
- if (passenger.previous === 'YYY') {
- assert.equal(passenger.phone, 'ZZZ');
- observer.stop();
- handle.stop();
- done();
- }
- });
- },
- });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ context });
- create({
- context,
- passengers: [
- {
- previous: 'XXX',
- phone: 'XXX',
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ update(
+ { _id: docId },
+ {
+ $set: {
+ 'passengers.1.phone': 'ZZZ',
+ },
+ }
+ );
},
- {
- previous: 'YYY',
- phone: 'YYY',
+ changed(docId, doc) {
+ doc.passengers.forEach(passenger => {
+ if (passenger.previous === 'YYY') {
+ assert.equal(passenger.phone, 'ZZZ');
+ observer.stop();
+ handle.stop();
+ done();
+ }
+ });
},
- ],
+ });
+
+ create({
+ context,
+ passengers: [
+ {
+ previous: 'XXX',
+ phone: 'XXX',
+ },
+ {
+ previous: 'YYY',
+ phone: 'YYY',
+ },
+ ],
+ });
});
});
- it('Should work with $elemMatch query selector', async function(done) {
+ it('Should work with $elemMatch query selector', function (done) {
const context = 'work-with-elemMatch-' + Random.id();
let handle = subscribe({
@@ -1278,113 +1288,115 @@ _.each(Collections, (Collection, key) => {
},
});
- await waitForHandleToBeReady(handle);
- const cursor = Collection.find({
- context,
- });
-
- const observer = cursor.observeChanges({
- added(docId, doc) {
- assert.isArray(doc.emails);
- assert.equal('x@x.com', doc.emails[0].address);
- handle.stop();
- observer.stop();
- done();
- },
- });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({
+ context,
+ });
- create({
- context,
- emails: [
- {
- address: 'x@x.com',
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ assert.isArray(doc.emails);
+ assert.equal('x@x.com', doc.emails[0].address);
+ handle.stop();
+ observer.stop();
+ done();
},
- ],
+ });
+
+ create({
+ context,
+ emails: [
+ {
+ address: 'x@x.com',
+ },
+ ],
+ });
});
});
- it('Should detect 3rd level nesting changes', async function(done) {
+ it('Should detect 3rd level nesting changes', function (done) {
const context = 'deep-level-nesting-' + Random.id();
let handle = subscribe({
context,
});
- await waitForHandleToBeReady(handle);
- const cursor = Collection.find({
- context,
- });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({
+ context,
+ });
- const observer = cursor.observeChanges({
- added(docId, doc) {
- update(docId, {
- $set: {
- 'item.profile.name': 'Elena Smith',
- },
- });
- },
- changed(docId, doc) {
- assert.isObject(doc.item);
- assert.equal('Elena Smith', doc.item.profile.name);
- done();
- },
- });
+ const observer = cursor.observeChanges({
+ added(docId, doc) {
+ update(docId, {
+ $set: {
+ 'item.profile.name': 'Elena Smith',
+ },
+ });
+ },
+ changed(docId, doc) {
+ assert.isObject(doc.item);
+ assert.equal('Elena Smith', doc.item.profile.name);
+ done();
+ },
+ });
- create({
- context,
- item: {
- profile: {
- name: 'John Smith',
+ create({
+ context,
+ item: {
+ profile: {
+ name: 'John Smith',
+ },
},
- },
+ });
});
});
- it('Should work with a filter on a subfield and a top field specified', async function(done) {
- _id = await createSync({
+ it('Should work with a filter on a subfield and a top field specified', function (done) {
+ createSync({
master: {
sub: 'TEST',
sub2: 1,
sub3: 1,
},
- });
-
- let handle = subscribe(
- {
- _id,
- 'master.sub': 'TEST',
- },
- {
- fields: {
- master: 1,
+ }).then(function (_id) {
+ let handle = subscribe(
+ {
+ _id,
+ 'master.sub': 'TEST',
},
- }
- );
-
- await waitForHandleToBeReady(handle);
+ {
+ fields: {
+ master: 1,
+ },
+ }
+ );
- const cursor = Collection.find({ _id });
- const document = Collection.findOne({ _id });
- assert.isObject(document.master);
- assert.equal(document.master.sub, 'TEST');
- assert.equal(document.master.sub2, 1);
- assert.equal(document.master.sub3, 1);
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Collection.find({ _id });
+ const document = Collection.findOne({ _id });
+ assert.isObject(document.master);
+ assert.equal(document.master.sub, 'TEST');
+ assert.equal(document.master.sub2, 1);
+ assert.equal(document.master.sub3, 1);
+
+ let observeChangesHandle = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(doc.master.sub2, 2);
+ handle.stop();
+ observeChangesHandle.stop();
+ done();
+ },
+ });
- let observeChangesHandle = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(doc.master.sub2, 2);
- handle.stop();
- observeChangesHandle.stop();
- done();
- },
+ update(
+ { _id },
+ {
+ $set: { 'master.sub2': 2 },
+ }
+ );
+ });
});
-
- update(
- { _id },
- {
- $set: { 'master.sub2': 2 },
- }
- );
});
});
});
diff --git a/testing/main.server.js b/testing/main.server.js
index 4e930e69..343f9736 100644
--- a/testing/main.server.js
+++ b/testing/main.server.js
@@ -19,6 +19,7 @@ import './collection-defaults/server';
import './polling/server';
import './object-id/server';
import './include_prev_doc';
+import './return_value';
import { _ } from 'meteor/underscore';
diff --git a/testing/object-id/client.js b/testing/object-id/client.js
index 629cc169..205d8d57 100644
--- a/testing/object-id/client.js
+++ b/testing/object-id/client.js
@@ -2,22 +2,22 @@ import { assert } from 'chai';
import { SmartIds } from './collections';
import { Meteor } from 'meteor/meteor';
-describe('ObjectId', function() {
- it('Should work!', async function(done) {
- const [id1, id2] = await Meteor.callWithPromise('smart_ids_reset');
+describe('ObjectId', function () {
+ it('Should work!', function (done) {
+ Meteor.callWithPromise('smart_ids_reset').then(function ([id1, id2]) {
+ const handle = Meteor.subscribe(
+ 'smart_ids',
+ {
+ _id: id1
+ },
+ function () {
+ const result = SmartIds.findOne();
- const handle = Meteor.subscribe(
- 'smart_ids',
- {
- _id: id1
- },
- function() {
- const result = SmartIds.findOne();
-
- assert.isObject(result);
- assert.isObject(result._id);
- done();
- }
- );
+ assert.isObject(result);
+ assert.isObject(result._id);
+ done();
+ }
+ );
+ });
});
-});
+});
\ No newline at end of file
diff --git a/testing/object-id/server.js b/testing/object-id/server.js
index d5dd0ae3..afb62664 100644
--- a/testing/object-id/server.js
+++ b/testing/object-id/server.js
@@ -1,3 +1,4 @@
+import { Meteor } from 'meteor/meteor';
import { SmartIds } from './collections';
Meteor.publish('smart_ids', function(filters = {}) {
diff --git a/testing/optimistic-ui/boot.js b/testing/optimistic-ui/boot.js
index d3066847..cfb963da 100644
--- a/testing/optimistic-ui/boot.js
+++ b/testing/optimistic-ui/boot.js
@@ -1,3 +1,4 @@
+import { Meteor } from 'meteor/meteor';
import { Items } from './collections';
if (Meteor.isServer) {
diff --git a/testing/optimistic-ui/client.test.js b/testing/optimistic-ui/client.test.js
index 92e64dad..f4f5b15e 100644
--- a/testing/optimistic-ui/client.test.js
+++ b/testing/optimistic-ui/client.test.js
@@ -1,54 +1,54 @@
+import { Meteor } from 'meteor/meteor';
import { assert } from 'chai';
import { Items } from './collections';
-import { _ } from 'meteor/underscore';
import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils';
import { Random } from 'meteor/random';
import './boot';
describe('Optimistic UI', () => {
- it('Should not cause a flicker with method calls', async function(done) {
+ it('Should not cause a flicker with method calls', function (done) {
const context = Random.id();
- const itemId = await callWithPromise('optimistic_ui.items.insert', {
+ callWithPromise('optimistic_ui.items.insert', {
context,
liked: ['ZZZ'],
- });
-
- const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId });
- await waitForHandleToBeReady(handle);
-
- const cursor = Items.find({ _id: itemId });
-
- let alreadyIn = 0;
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- alreadyIn++;
- if (alreadyIn > 1) {
- done('A flicker was caused.');
- }
-
- assert.lengthOf(doc.liked, 2);
- assert.isTrue(_.contains(doc.liked, 'XXX'));
-
- setTimeout(() => {
- handle.stop();
- observer.stop();
- done();
- }, 200);
- },
- });
-
- const item = _.first(cursor.fetch());
- assert.isObject(item);
-
- Meteor.call('optimistic_ui.items.update', item._id, {
- $addToSet: {
- liked: 'XXX',
- },
+ }).then(function (itemId) {
+ const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId });
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Items.find({ _id: itemId });
+
+ let alreadyIn = 0;
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ alreadyIn++;
+ if (alreadyIn > 1) {
+ done('A flicker was caused.');
+ }
+
+ assert.lengthOf(doc.liked, 2);
+ assert.isTrue(doc.liked.includes('XXX'));
+
+ setTimeout(() => {
+ handle.stop();
+ observer.stop();
+ done();
+ }, 200);
+ },
+ });
+
+ const item = cursor.fetch()[0];
+ assert.isObject(item);
+
+ Meteor.call('optimistic_ui.items.update', item._id, {
+ $addToSet: {
+ liked: 'XXX',
+ },
+ });
+ });
});
});
- it('Should not cause a flicker with isomorphic calls', async function(done) {
+ it('Should not cause a flicker with isomorphic calls', function (done) {
const context = Random.id();
const itemId = Items.insert({
@@ -57,36 +57,36 @@ describe('Optimistic UI', () => {
});
const handle = Meteor.subscribe('optimistic_ui.items', { _id: itemId });
- await waitForHandleToBeReady(handle);
-
- const cursor = Items.find({ _id: itemId });
-
- let alreadyIn = 0;
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- alreadyIn++;
- if (alreadyIn > 1) {
- done('A flicker was caused.');
- }
-
- assert.lengthOf(doc.liked, 2);
- assert.isTrue(_.contains(doc.liked, 'XXX'));
-
- setTimeout(() => {
- handle.stop();
- observer.stop();
- done();
- }, 200);
- },
- });
-
- const item = _.first(cursor.fetch());
- assert.isObject(item);
-
- Items.update(item._id, {
- $addToSet: {
- liked: 'XXX',
- },
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Items.find({ _id: itemId });
+
+ let alreadyIn = 0;
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ alreadyIn++;
+ if (alreadyIn > 1) {
+ done('A flicker was caused.');
+ }
+
+ assert.lengthOf(doc.liked, 2);
+ assert.isTrue(doc.liked.includes('XXX'));
+
+ setTimeout(() => {
+ handle.stop();
+ observer.stop();
+ done();
+ }, 200);
+ },
+ });
+
+ const item = cursor.fetch()[0];
+ assert.isObject(item);
+
+ Items.update(item._id, {
+ $addToSet: {
+ liked: 'XXX',
+ },
+ });
});
});
});
diff --git a/testing/optimistic-ui/collections.js b/testing/optimistic-ui/collections.js
index 8da4e384..7649fe26 100644
--- a/testing/optimistic-ui/collections.js
+++ b/testing/optimistic-ui/collections.js
@@ -1,5 +1,7 @@
+import { Mongo } from 'meteor/mongo';
+
const Items = new Mongo.Collection('optimistic_ui_items');
export {
Items
-}
\ No newline at end of file
+}
diff --git a/testing/polling/client.js b/testing/polling/client.js
index 805919b3..cf0a3753 100644
--- a/testing/polling/client.js
+++ b/testing/polling/client.js
@@ -2,36 +2,36 @@ import { assert } from 'chai';
import { Campaigns } from './collections';
import { Meteor } from 'meteor/meteor';
-describe('Polling', function() {
- it('Should work!', async function(done) {
- await Meteor.callWithPromise('campaign_search_reset');
+describe('Polling', function () {
+ it('Should work!', function (done) {
+ Meteor.callWithPromise('campaign_search_reset').then(function () {
+ const pollingIntervalMs = 100;
- const pollingIntervalMs = 100;
+ const handle = Meteor.subscribe(
+ 'campaign_search',
+ 'John',
+ pollingIntervalMs,
+ function () {
+ const results = Campaigns.find().fetch();
- const handle = Meteor.subscribe(
- 'campaign_search',
- 'John',
- pollingIntervalMs,
- function() {
- const results = Campaigns.find().fetch();
+ assert.lengthOf(results, 2);
- assert.lengthOf(results, 2);
+ Meteor.call(
+ 'campaign_search_insert',
+ {
+ text: 'John Broman'
+ },
+ function () {
+ setTimeout(() => {
+ const results = Campaigns.find().fetch();
+ assert.lengthOf(results, 3);
- Meteor.call(
- 'campaign_search_insert',
- {
- text: 'John Broman'
- },
- function() {
- setTimeout(() => {
- const results = Campaigns.find().fetch();
- assert.lengthOf(results, 3);
-
- done();
- }, pollingIntervalMs + 100);
- }
- );
- }
- );
+ done();
+ }, pollingIntervalMs + 100);
+ }
+ );
+ }
+ );
+ });
});
-});
+});
\ No newline at end of file
diff --git a/testing/polling/server.js b/testing/polling/server.js
index bbc6f061..09a23a11 100644
--- a/testing/polling/server.js
+++ b/testing/polling/server.js
@@ -1,3 +1,4 @@
+import { Meteor } from 'meteor/meteor';
import { Campaigns } from './collections';
Meteor.publish('campaign_search', function(search, pollingIntervalMs = 100) {
diff --git a/testing/publish-counts/client.js b/testing/publish-counts/client.js
index dcb613a1..b2124100 100644
--- a/testing/publish-counts/client.js
+++ b/testing/publish-counts/client.js
@@ -1,5 +1,4 @@
import { assert } from 'chai';
-import {Items} from './collections';
import {Meteor} from 'meteor/meteor';
import {Counter} from 'meteor/natestrauser:publish-performant-counts'
diff --git a/testing/publish-counts/collections.js b/testing/publish-counts/collections.js
index a918f9a9..d6aaa6ce 100644
--- a/testing/publish-counts/collections.js
+++ b/testing/publish-counts/collections.js
@@ -1,5 +1,3 @@
-import {Mongo} from 'meteor/mongo';
+import { Mongo } from 'meteor/mongo';
-const Items = new Mongo.Collection('performant_counts_items');
-
-export {Items}
+export const Items = new Mongo.Collection('performant_counts_items');
diff --git a/testing/publish-counts/server.js b/testing/publish-counts/server.js
index 1b217eda..2ac113b3 100644
--- a/testing/publish-counts/server.js
+++ b/testing/publish-counts/server.js
@@ -1,5 +1,6 @@
+import { Meteor } from 'meteor/meteor';
import { Counter } from 'meteor/natestrauser:publish-performant-counts'
-import {Items} from './collections';
+import { Items } from './collections';
Meteor.publish('performant_counts', function () {
return new Counter(
@@ -20,4 +21,4 @@ Meteor.methods({
'performant_counts_add'() {
Items.insert({name: 'Item'});
}
-});
\ No newline at end of file
+});
diff --git a/testing/publishComposite/boot.js b/testing/publishComposite/boot.js
index f43c64fb..3f57b224 100644
--- a/testing/publishComposite/boot.js
+++ b/testing/publishComposite/boot.js
@@ -1,3 +1,4 @@
+import { Meteor } from 'meteor/meteor';
import { Items, Children } from './collections';
import loadFixtures from './loadFixtures';
@@ -50,4 +51,4 @@ Meteor.methods({
'publish_composite.children.remove'(...args) {
return Children.remove(...args)
}
-});
\ No newline at end of file
+});
diff --git a/testing/publishComposite/client.test.js b/testing/publishComposite/client.test.js
index 8edac25d..c50ff43b 100644
--- a/testing/publishComposite/client.test.js
+++ b/testing/publishComposite/client.test.js
@@ -1,44 +1,44 @@
+import { Meteor } from 'meteor/meteor';
import { assert } from 'chai';
-import {Items, Children} from './collections';
-import {_} from 'meteor/underscore';
-import {waitForHandleToBeReady, callWithPromise} from '../lib/sync_utils';
+import { Items, Children } from './collections';
+import { waitForHandleToBeReady, callWithPromise } from '../lib/sync_utils';
describe('Publish Composite', () => {
- it('Should be able to detect updates on parent element', async function (done) {
- await callWithPromise('publish_composite.load_fixtures');
-
- const handle = Meteor.subscribe('items_publish_composite');
- await waitForHandleToBeReady(handle);
-
- const cursor = Items.find();
-
- const observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(doc.name, 'Other Name');
- const firstChild = Children.find({itemId: docId}).fetch()[0];
-
- Meteor.call('publish_composite.children.update', firstChild._id, {
- $set: {name: 'Other Name'}
+ it('Should be able to detect updates on parent element', function (done) {
+ callWithPromise('publish_composite.load_fixtures').then(function () {
+ const handle = Meteor.subscribe('items_publish_composite');
+ waitForHandleToBeReady(handle).then(function () {
+ const cursor = Items.find();
+
+ const observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(doc.name, 'Other Name');
+ const firstChild = Children.find({ itemId: docId }).fetch()[0];
+
+ Meteor.call('publish_composite.children.update', firstChild._id, {
+ $set: { name: 'Other Name' }
+ });
+ }
});
- }
- });
- const item = _.first(cursor.fetch());
- assert.isObject(item);
+ const item = cursor.fetch()[0];
+ assert.isObject(item);
- const childCursor = Children.find({itemId: item._id});
- const childObserver = childCursor.observeChanges({
- changed(docId, doc) {
- assert.equal(doc.name, 'Other Name');
+ const childCursor = Children.find({ itemId: item._id });
+ const childObserver = childCursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(doc.name, 'Other Name');
- done();
- handle.stop();
- observer.stop();
- }
- });
+ done();
+ handle.stop();
+ observer.stop();
+ }
+ });
- await callWithPromise('publish_composite.items.update', item._id, {
- $set: {name: 'Other Name'}
+ callWithPromise('publish_composite.items.update', item._id, {
+ $set: { name: 'Other Name' }
+ });
+ });
});
})
-});
\ No newline at end of file
+});
diff --git a/testing/publishComposite/collections.js b/testing/publishComposite/collections.js
index 8115835f..6c1619a3 100644
--- a/testing/publishComposite/collections.js
+++ b/testing/publishComposite/collections.js
@@ -1,7 +1,9 @@
+import { Mongo } from 'meteor/mongo';
+
const Items = new Mongo.Collection('publish_composition');
const Children = new Mongo.Collection('publish_composition_children');
export {
Items,
Children
-}
\ No newline at end of file
+}
diff --git a/testing/publishComposite/loadFixtures.js b/testing/publishComposite/loadFixtures.js
index ff8eba22..f7428877 100644
--- a/testing/publishComposite/loadFixtures.js
+++ b/testing/publishComposite/loadFixtures.js
@@ -1,4 +1,4 @@
-import {Items, Children} from './collections';
+import { Items, Children } from './collections';
const ITEMS = 5;
const CHILDREN_PER_ITEM = 5;
diff --git a/testing/return_value.js b/testing/return_value.js
new file mode 100644
index 00000000..3278da3c
--- /dev/null
+++ b/testing/return_value.js
@@ -0,0 +1,23 @@
+import { assert } from 'chai';
+
+describe('Collection', function () {
+
+ let idx = 1;
+ const Collection = new Mongo.Collection('test_return_value_' + idx++);
+
+ it('should return the amount of updated documents when updating', function () {
+ const id = Collection.insert({someData: true})
+ const r = Collection.update(id, {someData: false});
+ assert.strictEqual(r, 1)
+ })
+ it('should return the amount of updated documents when upserting with update', function () {
+ const id = Collection.insert({someData: true})
+ const r = Collection.update(id, {someData: false}, {upsert: true});
+ assert.strictEqual(r, 1)
+ })
+ it('should return an object with the amount of updated documents when upserting', function () {
+ const id = Collection.insert({someData: true})
+ const r = Collection.upsert(id, {someData: false});
+ assert.deepEqual(r, {numberAffected: 1})
+ })
+});
diff --git a/testing/server-autorun/client.js b/testing/server-autorun/client.js
index 9c968655..4d5610fd 100644
--- a/testing/server-autorun/client.js
+++ b/testing/server-autorun/client.js
@@ -1,6 +1,6 @@
import { assert } from 'chai';
-import {Orders, Items} from './collections';
-import {Meteor} from 'meteor/meteor';
+import { Orders, Items } from './collections';
+import { Meteor } from 'meteor/meteor';
describe('Testing autorun functionality', function () {
it('Should be able to subscribe', function (done) {
diff --git a/testing/server-autorun/collections.js b/testing/server-autorun/collections.js
index 9c10c885..91a27020 100644
--- a/testing/server-autorun/collections.js
+++ b/testing/server-autorun/collections.js
@@ -1,6 +1,4 @@
-import {Mongo} from 'meteor/mongo';
+import { Mongo } from 'meteor/mongo';
-const Items = new Mongo.Collection('autorun_test_items');
-const Orders = new Mongo.Collection('autorun_test_orders');
-
-export {Orders, Items}
+export const Items = new Mongo.Collection('autorun_test_items');
+export const Orders = new Mongo.Collection('autorun_test_orders');
diff --git a/testing/server-autorun/publication.js b/testing/server-autorun/publication.js
index 62f00502..e005457d 100644
--- a/testing/server-autorun/publication.js
+++ b/testing/server-autorun/publication.js
@@ -1 +1 @@
-import {Orders, Items} from './collections';
+import { Orders, Items } from './collections';
diff --git a/testing/server-autorun/server.js b/testing/server-autorun/server.js
index 186f0b6e..96d8d4d5 100644
--- a/testing/server-autorun/server.js
+++ b/testing/server-autorun/server.js
@@ -1,4 +1,5 @@
-import {Orders, Items} from './collections';
+import { Meteor } from 'meteor/meteor';
+import { Orders, Items } from './collections';
import './publication';
diff --git a/testing/synthetic_mutators.js b/testing/synthetic_mutators.js
index 8dfa1200..20c2d50a 100644
--- a/testing/synthetic_mutators.js
+++ b/testing/synthetic_mutators.js
@@ -18,13 +18,13 @@ _.each(Collections, (Collection, key) => {
return;
}
- describe('It should work with synthetic mutators: ' + key, function() {
- it('Should work with insert', async function(done) {
+ describe('It should work with synthetic mutators: ' + key, function () {
+ it('Should work with insert', function (done) {
let handle = subscribe({
game: `synthetic.${config[key].suffix}`,
});
- const cursor = Collection.find();
+ const cursor = Collection.find({});
let observeChangesHandle = cursor.observeChanges({
added(docId, doc) {
@@ -35,14 +35,14 @@ _.each(Collections, (Collection, key) => {
},
});
- await waitForHandleToBeReady(handle);
-
- synthetic('insert', {
- game: `synthetic.${config[key].suffix}`,
+ waitForHandleToBeReady(handle).then(function () {
+ synthetic('insert', {
+ game: `synthetic.${config[key].suffix}`,
+ });
});
});
- it('Should work with update with operators: $set', async function(done) {
+ it('Should work with update with operators: $set', function (done) {
let handle = subscribe({
game: 'chess',
});
@@ -58,49 +58,49 @@ _.each(Collections, (Collection, key) => {
},
});
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ let _id = cursor.fetch()[0]._id;
+ assert.isString(_id);
- let _id = cursor.fetch()[0]._id;
- assert.isString(_id);
-
- synthetic('update', _id, {
- $set: {
- isPlaying: true,
- },
+ synthetic('update', _id, {
+ $set: {
+ isPlaying: true,
+ },
+ });
});
});
- it('Should work with update with operators: $push', async function(done) {
- let _id = await createSync({
+ it('Should work with update with operators: $push', function (done) {
+ createSync({
synthetic_test: true,
connections: [],
- });
+ }).then(function (_id) {
+ let handle = subscribe({ synthetic_test: true });
- let handle = subscribe({ synthetic_test: true });
+ const cursor = Collection.find({
+ synthetic_test: true,
+ });
- const cursor = Collection.find({
- synthetic_test: true,
- });
+ let observeChangesHandle = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.lengthOf(doc.connections, 1);
+ observeChangesHandle.stop();
+ handle.stop();
+ done();
+ },
+ });
- let observeChangesHandle = cursor.observeChanges({
- changed(docId, doc) {
- assert.lengthOf(doc.connections, 1);
- observeChangesHandle.stop();
- handle.stop();
- done();
- },
- });
-
- await waitForHandleToBeReady(handle);
-
- synthetic('update', _id, {
- $push: {
- connections: 1,
- },
+ waitForHandleToBeReady(handle).then(function () {
+ synthetic('update', _id, {
+ $push: {
+ connections: 1,
+ },
+ });
+ });
});
});
- it('Should work with update', async function(done) {
+ it('Should work with update', function (done) {
let handle = subscribe({ game: 'chess' });
const cursor = Collection.find();
@@ -114,19 +114,19 @@ _.each(Collections, (Collection, key) => {
},
});
- await waitForHandleToBeReady(handle);
-
- let _id = cursor.fetch()[0]._id;
- assert.isString(_id);
+ waitForHandleToBeReady(handle).then(function () {
+ let _id = cursor.fetch()[0]._id;
+ assert.isString(_id);
- synthetic('update', _id, {
- $set: {
- isPlaying: true,
- },
+ synthetic('update', _id, {
+ $set: {
+ isPlaying: true,
+ },
+ });
});
});
- it('Should work with remove', async function(done) {
+ it('Should work with remove', function (done) {
let handle = subscribe({
game: 'chess',
});
@@ -144,45 +144,46 @@ _.each(Collections, (Collection, key) => {
},
});
- await waitForHandleToBeReady(handle);
+ waitForHandleToBeReady(handle).then(function () {
+ _id = cursor.fetch()[0]._id;
+ assert.isString(_id);
- _id = cursor.fetch()[0]._id;
- assert.isString(_id);
-
- synthetic('remove', _id);
+ synthetic('remove', _id);
+ });
});
- it('Should work with update with _id', async function(done) {
+ it('Should work with update with _id', function (done) {
const context = 'synth-with-id';
- let _id = await createSync({ context });
- let handle = subscribe({
- _id: { $in: [_id] },
+ createSync({ context }).then(function (_id) {
+ let handle = subscribe({
+ _id: { $in: [_id] },
+ });
+
+ const cursor = Collection.find();
+ waitForHandleToBeReady(handle).then(function () {
+ let observer = cursor.observeChanges({
+ changed(docId, doc) {
+ assert.equal(docId, _id);
+ assert.equal(doc.isPlaying, true);
+ observer.stop();
+ handle.stop();
+ done();
+ },
+ });
+
+ synthetic(
+ 'update',
+ _id,
+ {
+ $set: {
+ isPlaying: true,
+ },
+ },
+ `${Collection._name}::${_id}`
+ );
+ });
});
-
- const cursor = Collection.find();
- await waitForHandleToBeReady(handle);
-
- let observer = cursor.observeChanges({
- changed(docId, doc) {
- assert.equal(docId, _id);
- assert.equal(doc.isPlaying, true);
- observer.stop();
- handle.stop();
- done();
- },
- });
-
- synthetic(
- 'update',
- _id,
- {
- $set: {
- isPlaying: true,
- },
- },
- `${Collection._name}::${_id}`
- );
});
});
-});
+});
\ No newline at end of file
diff --git a/testing/transformations/client.js b/testing/transformations/client.js
index 2f741e69..7359dc58 100644
--- a/testing/transformations/client.js
+++ b/testing/transformations/client.js
@@ -1,5 +1,5 @@
import { assert } from 'chai';
-import {Items} from './collections';
+import { Items } from './collections';
describe('Transformations', function () {
it('Should receive correct data', function (done) {
diff --git a/testing/transformations/collections.js b/testing/transformations/collections.js
index c227edfb..8be541cf 100644
--- a/testing/transformations/collections.js
+++ b/testing/transformations/collections.js
@@ -1,4 +1,5 @@
-import {Mongo} from 'meteor/mongo';
+import { Meteor } from 'meteor/meteor';
+import { Mongo } from 'meteor/mongo';
let Items;
@@ -18,4 +19,4 @@ if (Meteor.isServer) {
});
}
-export {Items}
+export { Items }
diff --git a/testing/transformations/server.js b/testing/transformations/server.js
index bf20cbb6..28c1f194 100644
--- a/testing/transformations/server.js
+++ b/testing/transformations/server.js
@@ -1,3 +1,4 @@
+import { Meteor } from 'meteor/meteor';
import { assert } from 'chai';
import { Items } from './collections';
diff --git a/testing/vent/boot.js b/testing/vent/boot.js
index 32910000..60b0c7c6 100644
--- a/testing/vent/boot.js
+++ b/testing/vent/boot.js
@@ -1,5 +1,5 @@
-import {Vent} from 'meteor/cultofcoders:redis-oplog';
-import {Meteor} from 'meteor/meteor';
+import { Vent } from 'meteor/cultofcoders:redis-oplog';
+import { Meteor } from 'meteor/meteor';
Vent.publish({
'threadMessage'({channel, shouldReturn = true}) {
@@ -21,4 +21,4 @@ Meteor.methods({
Vent.emit(channel, object)
}
}
-});
\ No newline at end of file
+});
diff --git a/testing/vent/client.js b/testing/vent/client.js
index c2e150f9..9e2575f8 100644
--- a/testing/vent/client.js
+++ b/testing/vent/client.js
@@ -1,10 +1,9 @@
import { assert } from 'chai';
-import {waitForHandleToBeReady, callWithPromise} from '../lib/sync_utils';
-import {Random} from 'meteor/random';
-import {Vent} from 'meteor/cultofcoders:redis-oplog';
+import { Random } from 'meteor/random';
+import { Vent } from 'meteor/cultofcoders:redis-oplog';
describe('Vent', function () {
- it('Should receive the event accordingly', async function (done) {
+ it('Should receive the event accordingly', function (done) {
const threadId = Random.id();
const channel = `threads::${threadId}::new_message`;
@@ -21,18 +20,18 @@ describe('Vent', function () {
Meteor.call('vent_emit', {
channel,
- object: {text: 'Hello!'}
+ object: { text: 'Hello!' }
})
});
- it('Should be able to work with 2 different listeners to the same endpoint', async function (done) {
+ it('Should be able to work with 2 different listeners to the same endpoint', function (done) {
const threadId = Random.id();
const channel = `threads::${threadId}::new_message`;
let inHandle1 = false;
let inHandle2 = false;
- const handle1 = Vent.subscribe('threadMessage', {channel});
+ const handle1 = Vent.subscribe('threadMessage', { channel });
handle1.listen(function (message) {
inHandle1 = true;
@@ -44,7 +43,7 @@ describe('Vent', function () {
}
});
- const handle2 = Vent.subscribe('threadMessage', {channel});
+ const handle2 = Vent.subscribe('threadMessage', { channel });
handle2.listen(function (message) {
inHandle2 = true;
@@ -58,12 +57,12 @@ describe('Vent', function () {
Meteor.call('vent_emit', {
channel,
- object: {text: 'Hello!'}
+ object: { text: 'Hello!' }
})
});
- it('Should handle event bombarding and not losing anything along the way', async function (done) {
+ it('Should handle event bombarding and not losing anything along the way', function (done) {
const threadId = Random.id();
const channel = `threads::${threadId}::new_message`;
@@ -82,13 +81,13 @@ describe('Vent', function () {
Meteor.call('vent_emit', {
channel,
- object: {text: 'Hello!'},
+ object: { text: 'Hello!' },
times: 100
})
});
- it('Should not receive the event if handler is stopped', async function (done) {
+ it('Should not receive the event if handler is stopped', function (done) {
const threadId = Random.id();
const channel = `threads::${threadId}::new_message`;
@@ -104,11 +103,11 @@ describe('Vent', function () {
Meteor.call('vent_emit', {
channel,
- object: {text: 'Hello!'}
+ object: { text: 'Hello!' }
});
setTimeout(function () {
done();
}, 200);
});
-});
\ No newline at end of file
+});