forked from anuraghazra/github-readme-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchWakatime.test.js
215 lines (208 loc) · 5.68 KB
/
fetchWakatime.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
require("@testing-library/jest-dom");
const axios = require("axios");
const MockAdapter = require("axios-mock-adapter");
const { fetchLast7Days } = require("../src/fetchers/wakatime-fetcher");
const mock = new MockAdapter(axios);
afterEach(() => {
mock.reset();
});
const wakaTimeData = {
data: {
categories: [
{
digital: "22:40",
hours: 22,
minutes: 40,
name: "Coding",
percent: 100,
text: "22 hrs 40 mins",
total_seconds: 81643.570077,
},
],
daily_average: 16095,
daily_average_including_other_language: 16329,
days_including_holidays: 7,
days_minus_holidays: 5,
editors: [
{
digital: "22:40",
hours: 22,
minutes: 40,
name: "VS Code",
percent: 100,
text: "22 hrs 40 mins",
total_seconds: 81643.570077,
},
],
holidays: 2,
human_readable_daily_average: "4 hrs 28 mins",
human_readable_daily_average_including_other_language: "4 hrs 32 mins",
human_readable_total: "22 hrs 21 mins",
human_readable_total_including_other_language: "22 hrs 40 mins",
id: "random hash",
is_already_updating: false,
is_coding_activity_visible: true,
is_including_today: false,
is_other_usage_visible: true,
is_stuck: false,
is_up_to_date: true,
languages: [
{
digital: "0:19",
hours: 0,
minutes: 19,
name: "Other",
percent: 1.43,
text: "19 mins",
total_seconds: 1170.434361,
},
{
digital: "0:01",
hours: 0,
minutes: 1,
name: "TypeScript",
percent: 0.1,
text: "1 min",
total_seconds: 83.293809,
},
{
digital: "0:00",
hours: 0,
minutes: 0,
name: "YAML",
percent: 0.07,
text: "0 secs",
total_seconds: 54.975151,
},
],
operating_systems: [
{
digital: "22:40",
hours: 22,
minutes: 40,
name: "Mac",
percent: 100,
text: "22 hrs 40 mins",
total_seconds: 81643.570077,
},
],
percent_calculated: 100,
range: "last_7_days",
status: "ok",
timeout: 15,
total_seconds: 80473.135716,
total_seconds_including_other_language: 81643.570077,
user_id: "random hash",
username: "anuraghazra",
writes_only: false,
},
};
describe("Wakatime fetcher", () => {
it("should fetch correct wakatime data", async () => {
const username = "anuraghazra";
mock
.onGet(
`https://wakatime.com/api/v1/users/${username}/stats/last_7_days?is_including_today=true`,
)
.reply(200, wakaTimeData);
const repo = await fetchLast7Days({ username });
expect(repo).toMatchInlineSnapshot(`
Object {
"categories": Array [
Object {
"digital": "22:40",
"hours": 22,
"minutes": 40,
"name": "Coding",
"percent": 100,
"text": "22 hrs 40 mins",
"total_seconds": 81643.570077,
},
],
"daily_average": 16095,
"daily_average_including_other_language": 16329,
"days_including_holidays": 7,
"days_minus_holidays": 5,
"editors": Array [
Object {
"digital": "22:40",
"hours": 22,
"minutes": 40,
"name": "VS Code",
"percent": 100,
"text": "22 hrs 40 mins",
"total_seconds": 81643.570077,
},
],
"holidays": 2,
"human_readable_daily_average": "4 hrs 28 mins",
"human_readable_daily_average_including_other_language": "4 hrs 32 mins",
"human_readable_total": "22 hrs 21 mins",
"human_readable_total_including_other_language": "22 hrs 40 mins",
"id": "random hash",
"is_already_updating": false,
"is_coding_activity_visible": true,
"is_including_today": false,
"is_other_usage_visible": true,
"is_stuck": false,
"is_up_to_date": true,
"languages": Array [
Object {
"digital": "0:19",
"hours": 0,
"minutes": 19,
"name": "Other",
"percent": 1.43,
"text": "19 mins",
"total_seconds": 1170.434361,
},
Object {
"digital": "0:01",
"hours": 0,
"minutes": 1,
"name": "TypeScript",
"percent": 0.1,
"text": "1 min",
"total_seconds": 83.293809,
},
Object {
"digital": "0:00",
"hours": 0,
"minutes": 0,
"name": "YAML",
"percent": 0.07,
"text": "0 secs",
"total_seconds": 54.975151,
},
],
"operating_systems": Array [
Object {
"digital": "22:40",
"hours": 22,
"minutes": 40,
"name": "Mac",
"percent": 100,
"text": "22 hrs 40 mins",
"total_seconds": 81643.570077,
},
],
"percent_calculated": 100,
"range": "last_7_days",
"status": "ok",
"timeout": 15,
"total_seconds": 80473.135716,
"total_seconds_including_other_language": 81643.570077,
"user_id": "random hash",
"username": "anuraghazra",
"writes_only": false,
}
`);
});
it("should throw error", async () => {
mock.onGet(/\/https:\/\/wakatime\.com\/api/).reply(404, wakaTimeData);
await expect(fetchLast7Days("noone")).rejects.toThrow(
"Wakatime user not found, make sure you have a wakatime profile",
);
});
});
module.exports = { wakaTimeData };