forked from anuraghazra/github-readme-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pull] master from anuraghazra:master (#65)
* refactor: fix typos in a comment (anuraghazra#3437) * Fix typos in a comment * Add a comma * infra: enable no-class-assign eslint rule (anuraghazra#3451) * infra: enable no-const-assign eslint rule (anuraghazra#3452) * infra: enable no-dupe-class-members eslint rule (anuraghazra#3456) * tests(wakatime-fetcher): fix brand casing (anuraghazra#3455) * tests: add basic wakatime endpoint test (anuraghazra#3454) --------- Co-authored-by: Wertzui123 <[email protected]> Co-authored-by: Alexandr Garbuzov <[email protected]>
- Loading branch information
1 parent
2ddcd9c
commit a2f2733
Showing
4 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { jest } from "@jest/globals"; | ||
import "@testing-library/jest-dom"; | ||
import axios from "axios"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
import wakatime from "../api/wakatime.js"; | ||
import { renderWakatimeCard } from "../src/cards/wakatime-card.js"; | ||
import { expect, it, describe, afterEach } from "@jest/globals"; | ||
|
||
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, | ||
}, | ||
}; | ||
|
||
const mock = new MockAdapter(axios); | ||
|
||
afterEach(() => { | ||
mock.reset(); | ||
}); | ||
|
||
describe("Test /api/wakatime", () => { | ||
it("should test the request", async () => { | ||
const username = "anuraghazra"; | ||
const req = { query: { username } }; | ||
const res = { setHeader: jest.fn(), send: jest.fn() }; | ||
mock | ||
.onGet( | ||
`https://wakatime.com/api/v1/users/${username}/stats?is_including_today=true`, | ||
) | ||
.reply(200, wakaTimeData); | ||
|
||
await wakatime(req, res); | ||
|
||
expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml"); | ||
expect(res.send).toBeCalledWith(renderWakatimeCard(wakaTimeData.data, {})); | ||
}); | ||
}); |
a2f2733
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
github-readme-stats – ./
github-readme-stats-git-master-seylu.vercel.app
github-readme-stats-seylu.vercel.app
github-readme-stats-theta-orpin.vercel.app