-
Notifications
You must be signed in to change notification settings - Fork 3
/
zoteroapi.spec.lua
121 lines (95 loc) · 3.58 KB
/
zoteroapi.spec.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
describe("Zotero API Client", function()
local orig_path = package.path
local API_KEY = os.getenv("ZOTERO_API_KEY")
local USER_ID = os.getenv("ZOTERO_USER_ID")
assert.truthy(API_KEY)
assert.truthy(USER_ID)
package.path = "plugins/zotero.koplugin/?.lua;" .. package.path
require("commonrequire")
local JSON = require("json")
local ZoteroAPI = require("zoteroapi")
package.path = orig_path
ZoteroAPI.init("/tmp/zoteroplugin")
ZoteroAPI.setAPIKey(API_KEY)
ZoteroAPI.setUserID(USER_ID)
local headers = {
["Zotero-API-Key"] = API_KEY,
["Zotero-API-Version"] = "3"
}
--it("can tell the size of collections", function()
-- local r, e = ZoteroAPI.fetchCollectionSize(
-- ("https://api.zotero.org/users/%s/items"):format(USER_ID), headers
-- )
-- print(e,r)
-- assert.is_nil(e)
-- assert.is_true(r >= 0)
-- print("Collection size: ", r)
--end)
--it("can fetch a paginated collection", function()
-- local items_url = ("https://api.zotero.org/users/%s/items?since=%s"):format(USER_ID, 0)
-- local r, e
-- local collection_size = ZoteroAPI.fetchCollectionSize(items_url, headers)
-- local r, e = ZoteroAPI.fetchCollectionPaginated(items_url, headers)
-- assert.is_nil(e)
-- assert.is_equal(collection_size, #r)
--end)
--it("should be able to sync items", function()
-- local e = ZoteroAPI.syncAllItems()
-- assert.is_nil(e)
--end)
--it("can download files", function()
-- local r, e = ZoteroAPI.downloadAndGetPath("9E9TBDVH")
-- assert.is_nil(e)
--end)
--it("can round floating point numbers", function()
-- local f = ZoteroAPI.cutDecimalPlaces
-- assert.is_equal(f(math.pi, 4), 3.1415)
-- assert.is_equal(f(10, 0), 10)
-- assert.is_equal(f(10.12341234, 0), 10)
-- assert.is_equal(f(10, 4), 10)
--end)
--it("can convert bounding boxes", function()
-- local r = ZoteroAPI.bboxFromZotero({
-- [1] = 123.63,
-- [2] = 593.859,
-- [3] = 176.164,
-- [4] = 604.895
-- })
-- print(JSON.encode(r))
-- assert.is_true(
-- ZoteroAPI.bboxEqual(r, {
-- ["x"] = 123.63,
-- ["y"] = 593.859,
-- ["w"] = 52.534,
-- ["h"] = 11.0351
-- }, 10^-3))
--end)
--it("can show a list of entries", function()
-- local rootEntries = ZoteroAPI.displayCollection()
-- assert.is_true(#rootEntries > 0)
-- assert.is_not_nil(rootEntries[1].name)
-- assert.is_not_nil(rootEntries[1].key)
-- local entries = ZoteroAPI.displayCollection("J6HRKTMY")
-- assert.is_true(#entries > 0)
-- assert.is_not_nil(entries[1].name)
-- assert.is_not_nil(entries[1].key)
--end)
--it("can search for entries", function()
-- local results = ZoteroAPI.displaySearchResults("sybil")
-- assert.is_true(#results == 1)
-- assert.is_not_nil(results[1].name)
-- assert.is_not_nil(results[1].key)
-- assert.is_nil(results[1].collection)
--end)
--it("can correctly format timestamps #time", function()
-- local r1 = ZoteroAPI.addTimezone("2022-09-22 18:09:12")
-- assert.is_equal("2022-09-22T16:09:12Z", r1)
--end)
--it("can read the correct version number", function()
-- local nr = ZoteroAPI.getLibraryVersion()
-- assert.is_equal(nr, "1147")
--end)
it("can sync annotations", function()
ZoteroAPI.syncAnnotations("H3XITXUG")
end)
end)