Default to first translator for /connector/savePage if not provided
This commit is contained in:
parent
bb0fa73899
commit
01df8f59e5
3 changed files with 70 additions and 2 deletions
|
@ -201,6 +201,7 @@ Zotero.Server.Connector.Detect.prototype = {
|
|||
* uri - The URI of the page to be saved
|
||||
* html - document.innerHTML or equivalent
|
||||
* cookie - document.cookie or equivalent
|
||||
* translatorID [optional] - a translator ID as returned by /connector/detect
|
||||
*
|
||||
* Returns:
|
||||
* If a single item, sends response code 201 with item in body.
|
||||
|
@ -297,8 +298,11 @@ Zotero.Server.Connector.SavePage.prototype = {
|
|||
}
|
||||
});
|
||||
|
||||
// set translator and translate
|
||||
translate.setTranslator(this._parsedPostData.translatorID);
|
||||
if (this._parsedPostData.translatorID) {
|
||||
translate.setTranslator(this._parsedPostData.translatorID);
|
||||
} else {
|
||||
translate.setTranslator(translators[0]);
|
||||
}
|
||||
translate.translate(libraryID);
|
||||
}
|
||||
}
|
||||
|
|
12
test/tests/data/coins.html
Normal file
12
test/tests/data/coins.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Test Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<span class='Z3988' title='url_ver=Z39.88-2004&ctx_ver=Z39.88-2004&rfr_id=info%3Asid%2Fzotero.org%3A2&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rft.type=blogPost&rft.title=Test%20Page&rft.identifier=https%3A%2F%2Fexample.com%2Ftest&rft.aulast=Zotero&rft.au=Zotero&rft.date=2017-02-21'></span>
|
||||
<p>This is a test page</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -390,6 +390,58 @@ describe("Connector Server", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("/connector/savePage", function() {
|
||||
// TEMP: Wait for indexing to complete, which happens after a 1-second delay, after a 201 has
|
||||
// been returned to the connector. Would be better to make sure indexing has completed.
|
||||
afterEach(function* () {
|
||||
yield Zotero.Promise.delay(1050);
|
||||
});
|
||||
|
||||
it("should return 500 if no translator available for page", function* () {
|
||||
var xmlhttp = yield Zotero.HTTP.request(
|
||||
'POST',
|
||||
connectorServerPath + "/connector/savePage",
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
uri: "http://example.com",
|
||||
html: "<html><head><title>Title</title><body>Body</body></html>"
|
||||
}),
|
||||
successCodes: false
|
||||
}
|
||||
);
|
||||
assert.equal(xmlhttp.status, 500);
|
||||
});
|
||||
|
||||
it("should translate a page if translators are available", function* () {
|
||||
var html = Zotero.File.getContentsFromURL(getTestDataUrl('coins.html'));
|
||||
var promise = waitForItemEvent('add');
|
||||
var xmlhttp = yield Zotero.HTTP.request(
|
||||
'POST',
|
||||
connectorServerPath + "/connector/savePage",
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
uri: "https://example.com/test",
|
||||
html
|
||||
}),
|
||||
successCodes: false
|
||||
}
|
||||
);
|
||||
|
||||
let ids = yield promise;
|
||||
var item = Zotero.Items.get(ids[0]);
|
||||
var title = "Test Page";
|
||||
assert.equal(JSON.parse(xmlhttp.responseText).items[0].title, title);
|
||||
assert.equal(item.getField('title'), title);
|
||||
assert.equal(xmlhttp.status, 201);
|
||||
});
|
||||
});
|
||||
|
||||
describe('/connector/installStyle', function() {
|
||||
var endpoint;
|
||||
|
||||
|
|
Loading…
Reference in a new issue