-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
73 lines (53 loc) · 1.75 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//TODO: improve these tests
const assert = require("assert");
const Client = require("./index");
const client = new Client("not an id");
const defaultData = {
[Math.random()]: Math.random(),
[Math.random()]: Math.random()
};
const otherData = {
[Math.random()]: Math.random(),
[Math.random()]: Math.random()
};
(async function tests() {
console.log("Running tests...");
//Constuctor accepts ID
assert(client.blobID === "not an id");
//Can create blob, and sets the blobID to the id of created blob
const defaultBlobID = await client.createBlob(defaultData);
assert(defaultBlobID && (client.blobID === defaultBlobID));
//blobID is not set
const otherBlobID = await client.createBlob(otherData, false);
assert(client.blobID === defaultBlobID);
//Can get data
const otherFetchedData = await client.getBlob(otherBlobID);
assert.deepStrictEqual(otherFetchedData, otherData);
//Uses default ID
const defaultFetchedData = await client.getBlob();
assert.deepStrictEqual(defaultFetchedData, defaultData);
//Updates data
defaultData.updatedVal = true;
otherData.updatedVal = true;
const otherUpdatedData = await client.updateBlob(otherData, otherBlobID);
assert.deepStrictEqual(otherUpdatedData, otherData);
assert.deepStrictEqual(
await client.getBlob(otherBlobID),
otherData
);
const defaultUpdatedData = await client.updateBlob(defaultData);
assert.deepStrictEqual(defaultUpdatedData, defaultData);
assert.deepStrictEqual(
await client.getBlob(),
defaultData
);
//Deletes data
await client.deleteBlob()
await client.deleteBlob(otherBlobID);
assert.rejects(client.getBlob());
assert.rejects(client.getBlob(otherBlobID));
//Can change ID
client.setID("Test ID");
assert(client.blobID === "Test ID");
console.log("Tests complete!");
})()