diff --git a/test/tests/data/mendeleyMock/group-annotations.json b/test/tests/data/mendeleyMock/group-annotations.json new file mode 100644 index 0000000000..0037c95610 --- /dev/null +++ b/test/tests/data/mendeleyMock/group-annotations.json @@ -0,0 +1,68 @@ +[ + { + "id": "656fd591-451a-4bb0-8d5f-30c36c135fc9", + "type": "sticky_note", + "color": + { + "r": 211, + "g": 194, + "b": 255 + }, + "profile_id": "8dbf0832-8723-4c48-b532-20c0b7f6e01a", + "positions": + [ + { + "top_left": + { + "x": 232.5055339011597, + "y": 744.3609065973726 + }, + "bottom_right": + { + "x": 232.5055339011597, + "y": 744.3609065973726 + }, + "page": 1 + } + ], + "text": "note by me", + "created": "2021-04-22T12:09:51.125Z", + "last_modified": "2021-04-22T12:09:51.125Z", + "privacy_level": "group", + "filehash": "cc22c6611277df346ff8dc7386ba3880b2bafa15", + "document_id": "15edb87e-8526-4e27-af5e-03ada85e447a" + }, + { + "id": "c781467c-31eb-4522-8676-489aea8975e9", + "type": "sticky_note", + "color": + { + "r": 255, + "g": 245, + "b": 173 + }, + "profile_id": "1beef079-1488-3b20-ba55-12b1ae854506", + "positions": + [ + { + "top_left": + { + "x": 167.22474856840384, + "y": 678.5074827967856 + }, + "bottom_right": + { + "x": 167.22474856840384, + "y": 678.5074827967856 + }, + "page": 1 + } + ], + "text": "note by other", + "created": "2021-04-22T12:03:07.293Z", + "last_modified": "2021-04-27T08:51:05.373Z", + "privacy_level": "group", + "filehash": "cc22c6611277df346ff8dc7386ba3880b2bafa15", + "document_id": "15edb87e-8526-4e27-af5e-03ada85e447a" + } +] \ No newline at end of file diff --git a/test/tests/data/mendeleyMock/groups.json b/test/tests/data/mendeleyMock/groups.json new file mode 100644 index 0000000000..7cbbb88fbf --- /dev/null +++ b/test/tests/data/mendeleyMock/groups.json @@ -0,0 +1,74 @@ +[ + { + "name": "group 1", + "description": "group 1 is owned by me", + "disciplines": + [], + "tags": + [], + "photo": + { + "standard": "", + "square": "" + }, + "id": "ec66aee6-455c-300c-b601-ba4d6a34a95e", + "created": "2021-04-22T11:41:43.000Z", + "owning_profile_id": "97d3193e-2d2a-4700-abd6-d82335ef551d", + "link": "", + "role": "owner", + "access_level": "private", + "used_space": 1234, + "member_count": 3, + "member_limit": 25, + "url_slug": "", + "pending_invitation_count": 0 + }, + { + "name": "group 2", + "description": "group 2 is also owned by me", + "disciplines": + [], + "tags": + [], + "photo": + { + "standard": "", + "square": "" + }, + "id": "cc697d28-054c-37d2-afa3-74fa4cf8a727", + "created": "2021-04-22T13:40:54.000Z", + "owning_profile_id": "97d3193e-2d2a-4700-abd6-d82335ef551d", + "link": "", + "role": "owner", + "access_level": "private", + "used_space": 0, + "member_count": 1, + "member_limit": 25, + "url_slug": "", + "pending_invitation_count": 0 + }, + { + "name": "group 3", + "description": "group 3 is owned by someone else", + "disciplines": + [], + "tags": + [], + "photo": + { + "standard": "", + "square": "" + }, + "id": "6a15e9d6-c7e6-3716-8834-7a67d6f5f91f", + "created": "2021-04-22T13:38:17.000Z", + "owning_profile_id": "18b8c872-0e57-36e2-912a-40325fe8c542", + "link": "", + "role": "normal", + "access_level": "private", + "used_space": 0, + "member_count": 2, + "member_limit": 25, + "url_slug": "", + "pending_invitation_count": 0 + } +] \ No newline at end of file diff --git a/test/tests/data/mendeleyMock/user.json b/test/tests/data/mendeleyMock/user.json index e0d488b85f..881bf9c54c 100644 --- a/test/tests/data/mendeleyMock/user.json +++ b/test/tests/data/mendeleyMock/user.json @@ -12,7 +12,7 @@ "display_name": "some name", "email": "zotero@zotero.com", "first_name": "some", - "id": "97d3193e-2d2a-4700-abd6-d82335ef551d", + "id": "8dbf0832-8723-4c48-b532-20c0b7f6e01a", "last_name": "name", "marketing": true, "member_type": "free", diff --git a/test/tests/mendeleyImportTest.js b/test/tests/mendeleyImportTest.js index dd6e9b9777..796a34cd2e 100644 --- a/test/tests/mendeleyImportTest.js +++ b/test/tests/mendeleyImportTest.js @@ -88,7 +88,9 @@ describe('Zotero_Import_Mendeley', function () { url: `groups/v2?type=all&limit=500`, status: 200, headers: {}, - json: [] + json: JSON.parse( + await Zotero.File.getContentsFromURLAsync('resource://zotero-unit-tests/data/mendeleyMock/groups.json') + ) }); setHTTPResponse(server, 'https://api.mendeley.com/', { @@ -100,6 +102,29 @@ describe('Zotero_Import_Mendeley', function () { }, text: '' }); + + setHTTPResponse(server, 'https://api.mendeley.com/', { + method: 'GET', + url: `annotations?group_id=ec66aee6-455c-300c-b601-ba4d6a34a95e&limit=200`, + status: 200, + json: JSON.parse( + await Zotero.File.getContentsFromURLAsync('resource://zotero-unit-tests/data/mendeleyMock/group-annotations.json') + ) + }); + + setHTTPResponse(server, 'https://api.mendeley.com/', { + method: 'GET', + url: `annotations?group_id=cc697d28-054c-37d2-afa3-74fa4cf8a727&limit=200`, + status: 200, + json: [] + }); + + setHTTPResponse(server, 'https://api.mendeley.com/', { + method: 'GET', + url: `annotations?group_id=6a15e9d6-c7e6-3716-8834-7a67d6f5f91f&limit=200`, + status: 200, + json: [] + }); }); afterEach(() => { @@ -107,7 +132,7 @@ describe('Zotero_Import_Mendeley', function () { }); describe('#import', () => { - it("should import items & collections", async () => { + it("should import collections, items, attachments & annotations", async () => { await importer.translate({ libraryID: Zotero.Libraries.userLibraryID, collections: null, @@ -156,7 +181,12 @@ describe('Zotero_Import_Mendeley', function () { assert.lengthOf(withpdf.getAttachments(), 1); assert.equal(pdf.parentID, withpdf.id); const annotations = await pdf.getAnnotations(); - assert.equal(annotations.length, 4); + assert.equal(annotations.length, 5); + assert.isTrue(annotations.some(a => a.annotationComment === 'blue note 2')); + assert.isTrue(annotations.some(a => a.annotationComment === 'orange note1')); + assert.isTrue(annotations.some(a => a.annotationComment === 'note by me')); + assert.isFalse(annotations.some(a => a.annotationComment === 'note by other')); + assert.isFalse(annotations.some(a => a.annotationComment === 'mismatched note')); // collection const parentCollection = await Zotero.Collections.getAsync(