From 97790264d3b1c1c3ae4a0ee699d634f9b82dbdc1 Mon Sep 17 00:00:00 2001 From: ThaumRystra <9525416+ThaumRystra@users.noreply.github.com> Date: Thu, 28 Sep 2023 21:16:16 +0200 Subject: [PATCH] All tests passing... but do not be fooled --- app/imports/constants/SCHEMA_VERSION.js | 2 +- app/imports/migrations/server/dbv2/dbv2.js | 2 +- .../migrations/server/dbv2/dbv2.test.js | 40 +++++++++++++------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/imports/constants/SCHEMA_VERSION.js b/app/imports/constants/SCHEMA_VERSION.js index 829e4147..27ac1a5d 100644 --- a/app/imports/constants/SCHEMA_VERSION.js +++ b/app/imports/constants/SCHEMA_VERSION.js @@ -1,3 +1,3 @@ -const SCHEMA_VERSION = 2; +const SCHEMA_VERSION = 3; export default SCHEMA_VERSION; diff --git a/app/imports/migrations/server/dbv2/dbv2.js b/app/imports/migrations/server/dbv2/dbv2.js index 768db6d7..6b703954 100644 --- a/app/imports/migrations/server/dbv2/dbv2.js +++ b/app/imports/migrations/server/dbv2/dbv2.js @@ -64,7 +64,7 @@ export function migratePropUp(prop, collection) { } // If there are tags, copy them to libraryTags and set findable flags - if (Array.isArray(prop.tags) && prop.tags.length && collection === LibraryNodes) { + if (Array.isArray(prop.tags) && prop.tags.length && collection?._name === 'libraryNodes') { update = update || { $set: {} }; update.$set.libraryTags = prop.tags; update.$set.fillSlots = true; diff --git a/app/imports/migrations/server/dbv2/dbv2.test.js b/app/imports/migrations/server/dbv2/dbv2.test.js index 642f4c2f..8248834f 100644 --- a/app/imports/migrations/server/dbv2/dbv2.test.js +++ b/app/imports/migrations/server/dbv2/dbv2.test.js @@ -90,6 +90,7 @@ const expectedSlotFillerUpdate = { 'fillSlots': true, 'searchable': true, 'slotFillImage': 'https://url.to.pic', + 'type': 'folder' }, $unset: { picture: 1, @@ -127,32 +128,32 @@ const expectedDownMergeUpdate = { describe('dbv2 Migrate library nodes', function () { it('Migrates attacks up', function () { - const bulk = stubBulk(); - migratePropUp(bulk, exampleAttack); - const { query, update } = bulk.result(); + const collection = stubCollection(); + migratePropUp(exampleAttack, collection); + const { query, update } = collection.result(); assert.deepEqual(query, { _id: 'vw23EnJwBRcXEJg7i' }, 'The query should match the id of the given prop'); assert.deepEqual(update, expectedAttackUpdate, 'The update should match the expected update'); }); it('Migrates props without tags up', function () { - const bulk = stubBulk(); - migratePropUp(bulk, emptyFolderExample); - const { query, update, timesFind, timesUpdate } = bulk.result(); + const collection = stubCollection(); + migratePropUp(emptyFolderExample, collection); + const { query, update, timesFind, timesUpdate } = collection.result(); assert.isUndefined(query, 'There should be no query on a prop with no tags'); assert.equal(timesFind, 0, 'Find should be called zero times on a prop with no tags'); assert.isUndefined(update, 'There should be no update on a prop with no tags'); assert.equal(timesUpdate, 0, 'Update should be called zero times on a prop with no tags'); }); it('Migrates slot fillers up', function () { - const bulk = stubBulk(); - migratePropUp(bulk, exampleSlotFiller); - const { query, update } = bulk.result(); + const collection = stubCollection(); + migratePropUp(exampleSlotFiller, collection); + const { query, update } = collection.result(); assert.deepEqual(query, { _id: 'DXPYsHKF6888h3hZs' }, 'The query should match the id of the given prop'); assert.deepEqual(update, expectedSlotFillerUpdate, 'The update should match the expected update'); }); it('Merges tags when down migrating', function () { - const bulk = stubBulk(); - migratePropDown(bulk, DownMergeExample); - const { query, update } = bulk.result(); + const collection = stubCollection(); + migratePropDown(DownMergeExample, collection); + const { query, update } = collection.result(); assert.deepEqual(query, { _id: 'DXPYsHKF6W8Hh3hZs' }, 'The query should match the id of the given prop'); assert.deepEqual(update, expectedDownMergeUpdate, 'The update should match the expected update'); }); @@ -176,4 +177,19 @@ function stubBulk() { return { query, update, timesFind, timesUpdate } } } +} + +function stubCollection() { + let query, update, timesFind = 0, timesUpdate = 0; + return { + update(inputQuery, inputUpdate) { + query = inputQuery; + timesUpdate += 1; + update = inputUpdate; + }, + result() { + return { query, update, timesFind, timesUpdate } + }, + _name: 'libraryNodes' + } } \ No newline at end of file