From bc3f469571a07f41b2afdb4ef7a0517f6cb4ce51 Mon Sep 17 00:00:00 2001 From: Leonardo Venturini Date: Wed, 23 Oct 2024 09:01:52 -0400 Subject: [PATCH] fix data population --- .../ddp-client/test/livedata_test_service.js | 63 ++++++++++--------- packages/tinytest/tinytest_server.js | 2 +- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/packages/ddp-client/test/livedata_test_service.js b/packages/ddp-client/test/livedata_test_service.js index bc6e31b2e1..56886ff384 100644 --- a/packages/ddp-client/test/livedata_test_service.js +++ b/packages/ddp-client/test/livedata_test_service.js @@ -334,38 +334,41 @@ if (Meteor.isServer) { One = new Mongo.Collection('collectionOne'); Two = new Mongo.Collection('collectionTwo'); -Meteor.startup(async () => { - if (Meteor.isServer) { - await One.removeAsync({}); - await One.insertAsync({ name: 'value1' }); - await One.insertAsync({ name: 'value2' }); +async function populateDatabase() { + await One.removeAsync({}); + await One.insertAsync({ name: 'value1' }); + await One.insertAsync({ name: 'value2' }); - await Two.removeAsync({}); - await Two.insertAsync({ name: 'value3' }); - await Two.insertAsync({ name: 'value4' }); - await Two.insertAsync({ name: 'value5' }); + await Two.removeAsync({}); + await Two.insertAsync({ name: 'value3' }); + await Two.insertAsync({ name: 'value4' }); + await Two.insertAsync({ name: 'value5' }); +} - Meteor.publish('multiPublish', function(options) { - // See below to see what options are accepted. - check(options, Object); - if (options.normal) { - return [One.find(), Two.find()]; - } else if (options.dup) { - // Suppress the log of the expected internal error. - Meteor._suppress_log(1); - return [ - One.find(), - One.find({ name: 'value2' }), // multiple cursors for one collection - error - Two.find(), - ]; - } else if (options.notCursor) { - // Suppress the log of the expected internal error. - Meteor._suppress_log(1); - return [One.find(), 'not a cursor', Two.find()]; - } else throw 'unexpected options'; - }); - } -}); +if (Meteor.isServer) { + Meteor.publish('multiPublish', async function (options) { + // See below to see what options are accepted. + check(options, Object); + + await populateDatabase(); + + if (options.normal) { + return [One.find(), Two.find()]; + } else if (options.dup) { + // Suppress the log of the expected internal error. + Meteor._suppress_log(1); + return [ + One.find(), + One.find({ name: 'value2' }), // multiple cursors for one collection - error + Two.find(), + ]; + } else if (options.notCursor) { + // Suppress the log of the expected internal error. + Meteor._suppress_log(1); + return [One.find(), 'not a cursor', Two.find()]; + } else throw 'unexpected options'; + }); +} /// Helper for "livedata - result by value" const resultByValueArrays = Object.create(null); diff --git a/packages/tinytest/tinytest_server.js b/packages/tinytest/tinytest_server.js index 22a781a4c5..4c514c1059 100644 --- a/packages/tinytest/tinytest_server.js +++ b/packages/tinytest/tinytest_server.js @@ -43,7 +43,7 @@ Meteor.methods({ const collections = await MongoInternals.defaultRemoteCollectionDriver().mongo.db.collections(); for (const collection of collections) { - await collection.drop(); + await collection.deleteMany({}); } this.unblock();