Send Zotero-Schema-Version header with API requests

Set to the current global schema version
This commit is contained in:
Dan Stillman 2020-09-08 04:12:07 -04:00
parent e133aab530
commit 99b959285e
3 changed files with 28 additions and 0 deletions

View file

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

View file

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

View file

@ -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) {