Send Zotero-Schema-Version header with API requests
Set to the current global schema version
This commit is contained in:
parent
e133aab530
commit
99b959285e
3 changed files with 28 additions and 0 deletions
|
@ -35,6 +35,7 @@ Zotero.Sync.APIClient = function (options) {
|
||||||
this.baseURL = options.baseURL;
|
this.baseURL = options.baseURL;
|
||||||
this.apiVersion = options.apiVersion;
|
this.apiVersion = options.apiVersion;
|
||||||
this.apiKey = options.apiKey;
|
this.apiKey = options.apiKey;
|
||||||
|
this.schemaVersion = options.schemaVersion || Zotero.Schema.globalSchemaVersion;
|
||||||
this.caller = options.caller;
|
this.caller = options.caller;
|
||||||
this.debugUploadPolicy = Zotero.Prefs.get('sync.debugUploadPolicy');
|
this.debugUploadPolicy = Zotero.Prefs.get('sync.debugUploadPolicy');
|
||||||
this.cancellerReceiver = options.cancellerReceiver;
|
this.cancellerReceiver = options.cancellerReceiver;
|
||||||
|
@ -616,6 +617,7 @@ Zotero.Sync.APIClient.prototype = {
|
||||||
if (this.apiKey) {
|
if (this.apiKey) {
|
||||||
newHeaders["Zotero-API-Key"] = this.apiKey;
|
newHeaders["Zotero-API-Key"] = this.apiKey;
|
||||||
}
|
}
|
||||||
|
newHeaders["Zotero-Schema-Version"] = this.schemaVersion;
|
||||||
return newHeaders;
|
return newHeaders;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
||||||
return new Zotero.Sync.APIClient({
|
return new Zotero.Sync.APIClient({
|
||||||
baseURL: this.baseURL,
|
baseURL: this.baseURL,
|
||||||
apiVersion: this.apiVersion,
|
apiVersion: this.apiVersion,
|
||||||
|
schemaVersion: this.globalSchemaVersion,
|
||||||
apiKey: options.apiKey,
|
apiKey: options.apiKey,
|
||||||
caller: this.caller,
|
caller: this.caller,
|
||||||
cancellerReceiver: _cancellerReceiver,
|
cancellerReceiver: _cancellerReceiver,
|
||||||
|
|
|
@ -43,6 +43,31 @@ describe("Zotero.Sync.APIClient", function () {
|
||||||
Zotero.HTTP.mock = null;
|
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 () {
|
describe("#getGroups()", function () {
|
||||||
it("should automatically fetch multiple pages of results", function* () {
|
it("should automatically fetch multiple pages of results", function* () {
|
||||||
function groupJSON(groupID) {
|
function groupJSON(groupID) {
|
||||||
|
|
Loading…
Reference in a new issue