From d8d07362baae4f668922fb008fc1d2197c67c307 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 17 Mar 2020 10:37:16 -0400 Subject: [PATCH] Add additional test for creator migration from Extra --- test/tests/schemaTest.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/tests/schemaTest.js b/test/tests/schemaTest.js index 728ecb1118..d1ee64ed1f 100644 --- a/test/tests/schemaTest.js +++ b/test/tests/schemaTest.js @@ -75,7 +75,7 @@ describe("Zotero.Schema", function() { assert.isFalse(item.synced); }); - it("should migrate creator", async function () { + it("should migrate valid creator", async function () { var item = await createDataObject('item', { itemType: 'book' }); item.setCreators([ { @@ -112,6 +112,40 @@ describe("Zotero.Schema", function() { assert.isFalse(item.synced); }); + it("shouldn't migrate creator not valid for item type", async function () { + var item = await createDataObject('item', { itemType: 'book' }); + item.setCreators([ + { + firstName: 'Abc', + lastName: 'Def', + creatorType: 'author', + fieldMode: 0 + } + ]); + item.setField('extra', 'container-author: Last || First\nFoo: Bar'); + item.synced = true; + await item.saveTx(); + + schema.version++; + schema.itemTypes.find(x => x.itemType == 'book').fields.splice(0, 1, { field: 'fooBar' }) + var newLocales = {}; + Object.keys(schema.locales).forEach((locale) => { + var o = schema.locales[locale]; + o.fields.fooBar = 'Foo Bar'; + newLocales[locale] = o; + }); + await Zotero.Schema._updateGlobalSchemaForTest(schema); + await Zotero.Schema.migrateExtraFields(); + + var creators = item.getCreators(); + assert.lengthOf(creators, 1); + assert.propertyVal(creators[0], 'firstName', 'Abc'); + assert.propertyVal(creators[0], 'lastName', 'Def'); + assert.propertyVal(creators[0], 'creatorTypeID', Zotero.CreatorTypes.getID('author')); + assert.equal(item.getField('extra'), 'container-author: Last || First\nFoo: Bar'); + assert.isTrue(item.synced); + }); + it("shouldn't migrate fields in read-only library", async function () { var library = await createGroup({ editable: false, filesEditable: false }); var item = createUnsavedDataObject('item', { libraryID: library.libraryID, itemType: 'book' });