-
Notifications
You must be signed in to change notification settings - Fork 20
/
CommonMastodonApi.test.js
71 lines (60 loc) · 2.4 KB
/
CommonMastodonApi.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
import "https://unpkg.com/[email protected]/mocha.js"; /* globals mocha */
import "https://unpkg.com/[email protected]/chai.js"; /* globals chai */
import "https://unpkg.com/[email protected]/pkg/sinon.js"; /* globals sinon */
import * as MastodonApi from "/common/modules/MastodonApi.js";
describe("common module: MastodonApi", function () {
describe("getTootStatus()", function () {
afterEach(function() {
sinon.restore();
});
it("correctly queries Mastodon API", async function () {
const fakeResult = {
id: 8923749723,
url: "https://mastodon.social/whatever/URL",
array: [
{
one: "http://ostatus.org/",
two: "https://mastodon.social/",
three: 5756
}
],
subobject: {
okayDeep: 6768,
string: "hjkhkjhj"
}
}
const windowMock = sinon.mock(window);
windowMock.expects("fetch")
.once()
.withArgs(new URL("https://mastodon.social/api/v1/statuses/743432936282"))
.resolves(new Response(JSON.stringify(fakeResult)));
await MastodonApi.getTootStatus("mastodon.social", 743432936282);
windowMock.verify();
});
it("correctly returns JSON data", async function () {
const fakeResult = {
id: 8923749723,
url: "https://mastodon.social/whatever/URL",
array: [
{
one: "http://ostatus.org/",
two: "https://mastodon.social/",
three: 5756
}
],
subobject: {
okayDeep: 6768,
string: "hjkhkjhj"
}
}
const windowMock = sinon.mock(window);
windowMock.expects("fetch")
.once()
.withArgs(new URL("https://mastodon.social/api/v1/statuses/743432936282"))
.resolves(new Response(JSON.stringify(fakeResult)));
const returnData = await MastodonApi.getTootStatus("mastodon.social", 743432936282);
chai.assert.deepEqual(returnData, fakeResult);
windowMock.verify();
});
});
});