mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
add tests of behaviors to perserve from 2.x about collection operations and persistence
This commit is contained in:
@@ -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();
|
||||
},
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user