All tests passing... but do not be fooled

This commit is contained in:
ThaumRystra
2023-09-28 21:16:16 +02:00
parent 09c66aff0b
commit 97790264d3
3 changed files with 30 additions and 14 deletions

View File

@@ -1,3 +1,3 @@
const SCHEMA_VERSION = 2;
const SCHEMA_VERSION = 3;
export default SCHEMA_VERSION;

View File

@@ -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;

View File

@@ -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'
}
}