Add tests for HTTP integration endpoints
This commit is contained in:
parent
f829d7c43e
commit
338afc2b80
2 changed files with 115 additions and 0 deletions
81
test/tests/server_connectorIntegrationTest.js
Normal file
81
test/tests/server_connectorIntegrationTest.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
"use strict";
|
||||
|
||||
describe("Connector HTTP Integration Server", function () {
|
||||
var serverURL;
|
||||
|
||||
before(function* () {
|
||||
this.timeout(20000);
|
||||
Zotero.Prefs.set("httpServer.enabled", true);
|
||||
yield resetDB({
|
||||
thisArg: this,
|
||||
skipBundledFiles: true
|
||||
});
|
||||
|
||||
const serverPort = Zotero.Prefs.get('httpServer.port');
|
||||
serverURL = `http://127.0.0.1:${serverPort}/connector/document`;
|
||||
});
|
||||
|
||||
describe('/connector/document/execCommand', function () {
|
||||
it('should set HTTPIntegrationClient.inProgress=true and respond with a plugin command', async function () {
|
||||
let stub = sinon.stub(Zotero.Integration, 'execCommand');
|
||||
try {
|
||||
stub.callsFake(() => {
|
||||
let app = new Zotero.HTTPIntegrationClient.Application();
|
||||
app.getActiveDocument();
|
||||
});
|
||||
assert.isNotTrue(Zotero.HTTPIntegrationClient.inProgress);
|
||||
|
||||
let response = await Zotero.HTTP.request(
|
||||
'POST',
|
||||
`${serverURL}/execCommand`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
command: "addEditCitation",
|
||||
docId: "zoteroTestDoc",
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
assert.isTrue(Zotero.HTTPIntegrationClient.inProgress);
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal(JSON.parse(response.response).command, 'Application.getActiveDocument');
|
||||
}
|
||||
finally {
|
||||
stub.restore();
|
||||
Zotero.HTTPIntegrationClient.inProgress = false;
|
||||
Zotero.Integration.currentDoc = Zotero.Integration.currentSession = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('/connector/document/respond', function () {
|
||||
it('should pass along the request body via HTTPIntegrationClient', async function () {
|
||||
try {
|
||||
Zotero.HTTPIntegrationClient.deferredResponse = new Zotero.Promise.defer();
|
||||
|
||||
let postBody = { outputFormat: 'html' };
|
||||
Zotero.HTTP.request(
|
||||
'POST',
|
||||
`${serverURL}/respond`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(postBody),
|
||||
},
|
||||
);
|
||||
|
||||
let receivedBody = await Zotero.HTTPIntegrationClient.deferredResponse.promise;
|
||||
|
||||
assert.deepEqual(postBody, receivedBody);
|
||||
}
|
||||
finally {
|
||||
Zotero.HTTPIntegrationClient.inProgress = false;
|
||||
Zotero.Integration.currentDoc = Zotero.Integration.currentSession = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
34
test/tests/server_integrationTest.js
Normal file
34
test/tests/server_integrationTest.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
|
||||
describe("MacOS Integration Server", function () {
|
||||
var serverURL;
|
||||
|
||||
before(function* () {
|
||||
this.timeout(20000);
|
||||
Zotero.Prefs.set("httpServer.enabled", true);
|
||||
yield resetDB({
|
||||
thisArg: this,
|
||||
skipBundledFiles: true
|
||||
});
|
||||
|
||||
const serverPort = Zotero.Prefs.get('httpServer.port');
|
||||
serverURL = `http://127.0.0.1:${serverPort}/integration`;
|
||||
});
|
||||
|
||||
describe('/integration/macWordCommand', function () {
|
||||
it('should call Integration.execCommand with passed parameters', async function () {
|
||||
let stub = sinon.stub(Zotero.Integration, 'execCommand');
|
||||
try {
|
||||
await Zotero.HTTP.request(
|
||||
'GET',
|
||||
`${serverURL}/macWordCommand?agent=httpTest&command=httpTestCommand&document=docName&templateVersion=-1`,
|
||||
);
|
||||
|
||||
assert.isTrue(stub.calledOnce);
|
||||
assert.isTrue(stub.firstCall.calledWithExactly('httpTest', 'httpTestCommand', 'docName', '-1'));
|
||||
} finally {
|
||||
stub.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue