From f67d5045135c71c8246994fb7b0fa456dd032ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Tue, 5 Mar 2024 12:59:17 +0100 Subject: [PATCH] add tests of behaviors to perserve from 2.x about collection operations and persistence --- packages/mongo/mongo_livedata_tests.js | 89 ++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/packages/mongo/mongo_livedata_tests.js b/packages/mongo/mongo_livedata_tests.js index c566a7b6e8..1aa31832ee 100644 --- a/packages/mongo/mongo_livedata_tests.js +++ b/packages/mongo/mongo_livedata_tests.js @@ -4302,3 +4302,92 @@ Tinytest.addAsync('mongo-livedata - maintained isomorphism on collection operati test.equal(items, []); }); + +testAsyncMulti('mongo-livedata - collection operations data persistence', [ + async function (test) { + const Collection = new Mongo.Collection( + `remoteop_persistence${test.runId()}`, + ); + + // Using remote collection + await Collection.insertAsync({ _id: 'a' }); + await Collection.insertAsync({ _id: 'b' }); + + let items = await Collection.find().fetchAsync(); + let itemIds = items.map(_item => _item._id); + + test.equal(itemIds, ['a', 'b']); + + if (Meteor.isClient) { + return new Promise(resolve => { + setTimeout(async () => { + items = await Collection.find().fetchAsync(); + itemIds = items.map(_item => _item._id); + test.equal(itemIds, []); // data IS NOT persisted + resolve(); + }, 100); + }); + } + + return Promise.resolve(); + }, + async function (test) { + const Collection = new Mongo.Collection( + `methodop_persistence${test.runId()}`, + ); + // Using methods + Meteor.methods({ + [`insertMethodPersistence${test.runId()}`]: async () => { + await Collection.insertAsync({ _id: 'a' }); + await Collection.insertAsync({ _id: 'b' }); + }, + }); + + await Meteor.callAsync(`insertMethodPersistence${test.runId()}`); + + let items = await Collection.find().fetchAsync(); + let itemIds = items.map(_item => _item._id); + + test.equal(itemIds, ['a', 'b']); + + if (Meteor.isClient) { + return new Promise(resolve => { + setTimeout(async () => { + items = await Collection.find().fetchAsync(); + itemIds = items.map(_item => _item._id); + test.equal(itemIds, []); // data IS NOT persisted + resolve(); + }, 100); + }); + } + + return Promise.resolve(); + }, + async function (test) { + const Collection = new Mongo.Collection( + `localop_persistence${test.runId()}`, + ); + + // Using local collection + await Collection._collection.insertAsync({ _id: 'a' }); + await Collection._collection.insertAsync({ _id: 'b' }); + + let items = await Collection.find().fetchAsync(); + let itemIds = items.map(_item => _item._id); + + test.equal(itemIds, ['a', 'b']); + + if (Meteor.isClient) { + return new Promise(resolve => { + setTimeout(async () => { + items = await Collection.find().fetchAsync(); + itemIds = items.map(_item => _item._id); + test.equal(itemIds, ['a', 'b']); // data is persisted + resolve(); + }, 100); + }); + } + + return Promise.resolve(); + }, +]);