This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.test.js
53 lines (46 loc) · 1.6 KB
/
index.test.js
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
/* jshint expr:true */
import drive from "./index.js";
const https = jest.genMockFromModule("https");
const delay = time => new Promise(done => setTimeout(done, time));
// Testing that we are able to load the library
describe("drive-db", function() {
it("returns a table", async () => {
const db = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
expect(Array.isArray(db)).toBe(true);
expect(db.length).toBe(6);
expect(db[0]).toEqual({
id: "1",
firstname: "John",
lastname: "Smith",
age: "34",
city: "San Francisco",
country: "USA",
timestamp: "12/10/2010"
});
});
it("requires a sheet", async () => {
await expect(drive()).rejects.toEqual(
new Error("Need a Google Drive sheet id to load")
);
});
it("throws with a wrong sheet id", async () => {
await expect(drive("abc")).rejects.toEqual(
new Error(
"Error 400 retrieving https://spreadsheets.google.com/feeds/list/abc/default/public/values?alt=json"
)
);
});
it("can work with old cache", async () => {
const db = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
expect(Array.isArray(db)).toBe(true);
expect(db.length).toBe(6);
const db2 = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
});
it("can work with expired cache", async () => {
const db = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
expect(Array.isArray(db)).toBe(true);
expect(db.length).toBe(6);
await delay(1000);
const db2 = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
});
});