Skip to content

Commit

Permalink
Merge remote-tracking branch 'noctux/feature-attachment-urls' into at…
Browse files Browse the repository at this point in the history
…tachments
  • Loading branch information
wetneb committed Dec 5, 2019
2 parents a056f76 + 943a543 commit 53ab395
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ Zotero.Utilities.itemToAPIJSON = function(item) {
Zotero.debug("itemToAPIJSON: Discarded attachment: not an URL");
continue;
}
newItems.push({
var apiItem = {
itemType: "attachment",
parentItem: newItem.key,
title: attachment.title.toString(),
mimeType: attachment.mimeType.toString(),
url: attachment.url.toString(),
});
};
if (attachment.title) { // Optional field member, not all attachments have a title
apiItem['title'] = attachment.title.toString();
}
newItems.push(apiItem);
}
} else if((fieldID = Zotero.ItemFields.getID(field))) {
// if content is not a string, either stringify it or delete it
Expand Down
12 changes: 10 additions & 2 deletions test/search_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ describe("/search", function () {
assert.equal(response.statusCode, 200);
var json = response.body;

assert.lengthOf(json, 1);
assert.lengthOf(json, 2);
assert.equal(json[0].itemType, 'journalArticle');
assert.equal(json[0].title, articleTitle1);
// This item contains an attachment (URL)
assert.equal(json[1].itemType, 'attachment');
assert.equal(json[1].parentItem, json[0].key);
assert.equal(json[1].mimeType, 'text/html');
});

it("should translate a PMID with 'pmid:' prefix", async function () {
Expand All @@ -133,8 +137,12 @@ describe("/search", function () {
assert.equal(response.statusCode, 200);
var json = response.body;

assert.lengthOf(json, 1);
assert.lengthOf(json, 2);
assert.equal(json[0].itemType, 'journalArticle');
assert.equal(json[0].title, articleTitle1);
// This item contains an attachment (URL)
assert.equal(json[1].itemType, 'attachment');
assert.equal(json[1].parentItem, json[0].key);
assert.equal(json[1].mimeType, 'text/html');
});
});
28 changes: 22 additions & 6 deletions test/web_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ describe("/web", function () {
.send(url);
assert.equal(response.statusCode, 200);
var json = response.body;

assert.lengthOf(json, 1);
assert.lengthOf(json, 2);
assert.equal(json[0].itemType, 'journalArticle');
assert.equal(json[0].title, 'Title');
// This item contains an snapshot
assert.equal(json[1].itemType, 'attachment');
assert.equal(json[1].parentItem, json[0].key);
assert.equal(json[1].mimeType, 'text/html');
assert.equal(json[1].url, url);
});


Expand All @@ -50,9 +54,11 @@ describe("/web", function () {
.send(json);
assert.equal(response.statusCode, 200);
json = response.body;
assert.lengthOf(json, 2);
assert.lengthOf(json, 3);
assert.equal(json[0].title, 'A');
assert.equal(json[1].title, 'C');
assert.equal(json[1].parentItem, json[0].key);
assert.equal(json[1].url, url);
assert.equal(json[2].title, 'C');
});


Expand All @@ -66,10 +72,15 @@ describe("/web", function () {
assert.equal(response.statusCode, 200);
var json = response.body;

assert.lengthOf(json, 1);
assert.lengthOf(json, 2);
assert.equal(json[0].itemType, 'journalArticle');
assert.equal(json[0].title, 'Title');
assert.equal(json[0].url, finalURL);
// This item contains an snapshot
assert.equal(json[1].itemType, 'attachment');
assert.equal(json[1].parentItem, json[0].key);
assert.equal(json[1].mimeType, 'text/html');
assert.equal(json[1].url, finalURL);
});


Expand Down Expand Up @@ -110,9 +121,14 @@ describe("/web", function () {
assert.equal(response.statusCode, 200);
var json = response.body;

assert.lengthOf(json, 1);
assert.lengthOf(json, 2);
assert.equal(json[0].itemType, 'journalArticle');
assert.equal(json[0].title, 'Titre');
// This item contains an snapshot
assert.equal(json[1].itemType, 'attachment');
assert.equal(json[1].parentItem, json[0].key);
assert.equal(json[1].mimeType, 'text/html');
assert.equal(json[1].url, url);
});

it("should reject non-HTML/XML upstream content types", async function () {
Expand Down

0 comments on commit 53ab395

Please sign in to comment.