diff --git a/chrome/content/zotero/xpcom/sync/syncAPIClient.js b/chrome/content/zotero/xpcom/sync/syncAPIClient.js index 5538dc9526..1a9a822715 100644 --- a/chrome/content/zotero/xpcom/sync/syncAPIClient.js +++ b/chrome/content/zotero/xpcom/sync/syncAPIClient.js @@ -35,6 +35,7 @@ Zotero.Sync.APIClient = function (options) { this.baseURL = options.baseURL; this.apiVersion = options.apiVersion; this.apiKey = options.apiKey; + this.schemaVersion = options.schemaVersion || Zotero.Schema.globalSchemaVersion; this.caller = options.caller; this.debugUploadPolicy = Zotero.Prefs.get('sync.debugUploadPolicy'); this.cancellerReceiver = options.cancellerReceiver; @@ -616,6 +617,7 @@ Zotero.Sync.APIClient.prototype = { if (this.apiKey) { newHeaders["Zotero-API-Key"] = this.apiKey; } + newHeaders["Zotero-Schema-Version"] = this.schemaVersion; return newHeaders; }, diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 61d97e85b6..046f9a9f4b 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -95,6 +95,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { return new Zotero.Sync.APIClient({ baseURL: this.baseURL, apiVersion: this.apiVersion, + schemaVersion: this.globalSchemaVersion, apiKey: options.apiKey, caller: this.caller, cancellerReceiver: _cancellerReceiver, diff --git a/test/tests/syncAPIClientTest.js b/test/tests/syncAPIClientTest.js index 35867158d5..481a5d9951 100644 --- a/test/tests/syncAPIClientTest.js +++ b/test/tests/syncAPIClientTest.js @@ -43,6 +43,31 @@ describe("Zotero.Sync.APIClient", function () { Zotero.HTTP.mock = null; }) + + describe("#makeRequest()", function () { + after(function () { + sinon.restore(); + }); + + it("should send Zotero-Schema-Version", async function () { + server.respond(function (req) { + if (req.method == "GET" && req.url == baseURL + "test-schema-version") { + assert.propertyVal( + req.requestHeaders, + 'Zotero-Schema-Version', + Zotero.Schema.globalSchemaVersion.toString() + ); + + req.respond(200, {}, ""); + } + }); + var spy = sinon.spy(Zotero.HTTP, "request"); + await client.makeRequest("GET", baseURL + "test-schema-version"); + assert.isTrue(spy.calledOnce); + }); + }); + + describe("#getGroups()", function () { it("should automatically fetch multiple pages of results", function* () { function groupJSON(groupID) {