From c2ad4ceb0a1f18faf4d2cad48d0c39c1ba10893b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 30 Oct 2015 19:06:29 -0400 Subject: [PATCH] Output 'deleted' as 1 instead of true in item JSON Good idea? Not sure, but that's what the API does. --- chrome/content/zotero/xpcom/data/item.js | 2 +- test/tests/itemTest.js | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index b5565ac355..f3d1b3a88b 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3934,7 +3934,7 @@ Zotero.Item.prototype.toJSON = Zotero.Promise.coroutine(function* (options = {}) // Deleted let deleted = this.deleted; if (deleted || mode == 'full') { - obj.deleted = deleted; + obj.deleted = deleted ? 1 : 0; } obj.dateAdded = Zotero.Date.sqlToISO8601(this.dateAdded); diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index 0981e93a07..74b1346959 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -859,6 +859,20 @@ describe("Zotero.Item", function () { assert.isUndefined(json.date); assert.isUndefined(json.numPages); }) + + it("should output 'deleted' as 1", function* () { + var itemType = "book"; + var title = "Test"; + + var item = new Zotero.Item(itemType); + item.setField("title", title); + item.deleted = true; + var id = yield item.saveTx(); + item = yield Zotero.Items.getAsync(id); + var json = yield item.toJSON(); + + assert.strictEqual(json.deleted, 1); + }) }) describe("'full' mode", function () { @@ -931,7 +945,7 @@ describe("Zotero.Item", function () { patchBase: patchBase }) assert.isUndefined(json.title); - assert.isTrue(json.deleted); + assert.strictEqual(json.deleted, 1); }) })