mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
fix minimongo - observe ordered
This commit is contained in:
@@ -3102,83 +3102,83 @@ Tinytest.addAsync('minimongo - modify', async test => {
|
||||
|
||||
// XXX test update() (selecting docs, multi, upsert..)
|
||||
|
||||
Tinytest.add('minimongo - observe ordered', test => {
|
||||
Tinytest.addAsync('minimongo - observe ordered', async test => {
|
||||
const operations = [];
|
||||
const cbs = log_callbacks(operations);
|
||||
let handle;
|
||||
|
||||
const c = new LocalCollection();
|
||||
handle = c.find({}, {sort: {a: 1}}).observe(cbs);
|
||||
handle = await c.find({}, {sort: {a: 1}}).observe(cbs);
|
||||
test.isTrue(handle.collection === c);
|
||||
|
||||
c.insert({_id: 'foo', a: 1});
|
||||
await c.insertAsync({_id: 'foo', a: 1});
|
||||
test.equal(operations.shift(), ['added', {a: 1}, 0, null]);
|
||||
c.update({a: 1}, {$set: {a: 2}});
|
||||
await c.updateAsync({a: 1}, {$set: {a: 2}});
|
||||
test.equal(operations.shift(), ['changed', {a: 2}, 0, {a: 1}]);
|
||||
c.insert({a: 10});
|
||||
await c.insertAsync({a: 10});
|
||||
test.equal(operations.shift(), ['added', {a: 10}, 1, null]);
|
||||
c.update({}, {$inc: {a: 1}}, {multi: true});
|
||||
await c.updateAsync({}, {$inc: {a: 1}}, {multi: true});
|
||||
test.equal(operations.shift(), ['changed', {a: 3}, 0, {a: 2}]);
|
||||
test.equal(operations.shift(), ['changed', {a: 11}, 1, {a: 10}]);
|
||||
c.update({a: 11}, {a: 1});
|
||||
await c.updateAsync({a: 11}, {a: 1});
|
||||
test.equal(operations.shift(), ['changed', {a: 1}, 1, {a: 11}]);
|
||||
test.equal(operations.shift(), ['moved', {a: 1}, 1, 0, 'foo']);
|
||||
c.remove({a: 2});
|
||||
await c.removeAsync({a: 2});
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.remove({a: 3});
|
||||
await c.removeAsync({a: 3});
|
||||
test.equal(operations.shift(), ['removed', 'foo', 1, {a: 3}]);
|
||||
|
||||
// test stop
|
||||
handle.stop();
|
||||
const idA2 = Random.id();
|
||||
c.insert({_id: idA2, a: 2});
|
||||
await c.insertAsync({_id: idA2, a: 2});
|
||||
test.equal(operations.shift(), undefined);
|
||||
|
||||
// test initial inserts (and backwards sort)
|
||||
handle = c.find({}, {sort: {a: -1}}).observe(cbs);
|
||||
handle = await c.find({}, {sort: {a: -1}}).observe(cbs);
|
||||
test.equal(operations.shift(), ['added', {a: 2}, 0, null]);
|
||||
test.equal(operations.shift(), ['added', {a: 1}, 1, null]);
|
||||
handle.stop();
|
||||
|
||||
// test _suppress_initial
|
||||
handle = c.find({}, {sort: {a: -1}}).observe(Object.assign({
|
||||
handle = await c.find({}, {sort: {a: -1}}).observe(Object.assign({
|
||||
_suppress_initial: true}, cbs));
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.insert({a: 100});
|
||||
await c.insertAsync({a: 100});
|
||||
test.equal(operations.shift(), ['added', {a: 100}, 0, idA2]);
|
||||
handle.stop();
|
||||
|
||||
// test skip and limit.
|
||||
c.remove({});
|
||||
handle = c.find({}, {sort: {a: 1}, skip: 1, limit: 2}).observe(cbs);
|
||||
await c.removeAsync({});
|
||||
handle = await c.find({}, {sort: {a: 1}, skip: 1, limit: 2}).observe(cbs);
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.insert({a: 1});
|
||||
await c.insertAsync({a: 1});
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.insert({_id: 'foo', a: 2});
|
||||
await c.insertAsync({_id: 'foo', a: 2});
|
||||
test.equal(operations.shift(), ['added', {a: 2}, 0, null]);
|
||||
c.insert({a: 3});
|
||||
await c.insertAsync({a: 3});
|
||||
test.equal(operations.shift(), ['added', {a: 3}, 1, null]);
|
||||
c.insert({a: 4});
|
||||
await c.insertAsync({a: 4});
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.update({a: 1}, {a: 0});
|
||||
await c.updateAsync({a: 1}, {a: 0});
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.update({a: 0}, {a: 5});
|
||||
await c.updateAsync({a: 0}, {a: 5});
|
||||
test.equal(operations.shift(), ['removed', 'foo', 0, {a: 2}]);
|
||||
test.equal(operations.shift(), ['added', {a: 4}, 1, null]);
|
||||
c.update({a: 3}, {a: 3.5});
|
||||
await c.updateAsync({a: 3}, {a: 3.5});
|
||||
test.equal(operations.shift(), ['changed', {a: 3.5}, 0, {a: 3}]);
|
||||
handle.stop();
|
||||
|
||||
// test observe limit with pre-existing docs
|
||||
c.remove({});
|
||||
c.insert({a: 1});
|
||||
c.insert({_id: 'two', a: 2});
|
||||
c.insert({a: 3});
|
||||
handle = c.find({}, {sort: {a: 1}, limit: 2}).observe(cbs);
|
||||
await c.removeAsync({});
|
||||
await c.insertAsync({a: 1});
|
||||
await c.insertAsync({_id: 'two', a: 2});
|
||||
await c.insertAsync({a: 3});
|
||||
handle = await c.find({}, {sort: {a: 1}, limit: 2}).observe(cbs);
|
||||
test.equal(operations.shift(), ['added', {a: 1}, 0, null]);
|
||||
test.equal(operations.shift(), ['added', {a: 2}, 1, null]);
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.remove({a: 2});
|
||||
await c.removeAsync({a: 2});
|
||||
test.equal(operations.shift(), ['removed', 'two', 1, {a: 2}]);
|
||||
test.equal(operations.shift(), ['added', {a: 3}, 1, null]);
|
||||
test.equal(operations.shift(), undefined);
|
||||
@@ -3186,23 +3186,23 @@ Tinytest.add('minimongo - observe ordered', test => {
|
||||
|
||||
// test _no_indices
|
||||
|
||||
c.remove({});
|
||||
handle = c.find({}, {sort: {a: 1}}).observe(Object.assign(cbs, {_no_indices: true}));
|
||||
c.insert({_id: 'foo', a: 1});
|
||||
await c.removeAsync({});
|
||||
handle = await c.find({}, {sort: {a: 1}}).observe(Object.assign(cbs, {_no_indices: true}));
|
||||
await c.insertAsync({_id: 'foo', a: 1});
|
||||
test.equal(operations.shift(), ['added', {a: 1}, -1, null]);
|
||||
c.update({a: 1}, {$set: {a: 2}});
|
||||
await c.updateAsync({a: 1}, {$set: {a: 2}});
|
||||
test.equal(operations.shift(), ['changed', {a: 2}, -1, {a: 1}]);
|
||||
c.insert({a: 10});
|
||||
await c.insertAsync({a: 10});
|
||||
test.equal(operations.shift(), ['added', {a: 10}, -1, null]);
|
||||
c.update({}, {$inc: {a: 1}}, {multi: true});
|
||||
await c.updateAsync({}, {$inc: {a: 1}}, {multi: true});
|
||||
test.equal(operations.shift(), ['changed', {a: 3}, -1, {a: 2}]);
|
||||
test.equal(operations.shift(), ['changed', {a: 11}, -1, {a: 10}]);
|
||||
c.update({a: 11}, {a: 1});
|
||||
await c.updateAsync({a: 11}, {a: 1});
|
||||
test.equal(operations.shift(), ['changed', {a: 1}, -1, {a: 11}]);
|
||||
test.equal(operations.shift(), ['moved', {a: 1}, -1, -1, 'foo']);
|
||||
c.remove({a: 2});
|
||||
await c.removeAsync({a: 2});
|
||||
test.equal(operations.shift(), undefined);
|
||||
c.remove({a: 3});
|
||||
await c.removeAsync({a: 3});
|
||||
test.equal(operations.shift(), ['removed', 'foo', -1, {a: 3}]);
|
||||
handle.stop();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user