2022-09-24 16:20:54 +08:00
|
|
|
import "@testing-library/jest-dom";
|
2022-09-24 20:10:06 +08:00
|
|
|
import { calculateRank } from "../src/calculateRank.js";
|
2020-07-13 22:11:47 +08:00
|
|
|
|
|
|
|
describe("Test calculateRank", () => {
|
2023-06-12 20:38:07 +08:00
|
|
|
it("new user gets C rank", () => {
|
2020-07-13 22:11:47 +08:00
|
|
|
expect(
|
|
|
|
calculateRank({
|
2023-05-26 21:39:35 +08:00
|
|
|
all_commits: false,
|
|
|
|
commits: 0,
|
|
|
|
prs: 0,
|
|
|
|
issues: 0,
|
|
|
|
repos: 0,
|
|
|
|
stars: 0,
|
|
|
|
followers: 0,
|
|
|
|
}),
|
2023-06-12 20:38:07 +08:00
|
|
|
).toStrictEqual({ level: "C", percentile: 100 });
|
2023-05-26 21:39:35 +08:00
|
|
|
});
|
|
|
|
|
2023-06-12 20:38:07 +08:00
|
|
|
it("beginner user gets B- rank", () => {
|
|
|
|
expect(
|
|
|
|
calculateRank({
|
|
|
|
all_commits: false,
|
|
|
|
commits: 125,
|
|
|
|
prs: 25,
|
|
|
|
issues: 10,
|
|
|
|
repos: 0,
|
|
|
|
stars: 25,
|
|
|
|
followers: 5,
|
|
|
|
}),
|
|
|
|
).toStrictEqual({ level: "B-", percentile: 69.333868386557 });
|
|
|
|
});
|
|
|
|
|
|
|
|
it("median user gets B+ rank", () => {
|
2023-05-26 21:39:35 +08:00
|
|
|
expect(
|
|
|
|
calculateRank({
|
|
|
|
all_commits: false,
|
|
|
|
commits: 250,
|
|
|
|
prs: 50,
|
|
|
|
issues: 25,
|
|
|
|
repos: 0,
|
2023-06-12 20:38:07 +08:00
|
|
|
stars: 50,
|
|
|
|
followers: 10,
|
2023-05-26 21:39:35 +08:00
|
|
|
}),
|
2023-06-12 20:38:07 +08:00
|
|
|
).toStrictEqual({ level: "B+", percentile: 50 });
|
2023-05-26 21:39:35 +08:00
|
|
|
});
|
|
|
|
|
2023-06-12 20:38:07 +08:00
|
|
|
it("average user gets B+ rank (include_all_commits)", () => {
|
2023-05-26 21:39:35 +08:00
|
|
|
expect(
|
|
|
|
calculateRank({
|
|
|
|
all_commits: true,
|
|
|
|
commits: 1000,
|
|
|
|
prs: 50,
|
|
|
|
issues: 25,
|
|
|
|
repos: 0,
|
2023-06-12 20:38:07 +08:00
|
|
|
stars: 50,
|
|
|
|
followers: 10,
|
2023-05-26 21:39:35 +08:00
|
|
|
}),
|
2023-06-12 20:38:07 +08:00
|
|
|
).toStrictEqual({ level: "B+", percentile: 50 });
|
2023-05-26 21:39:35 +08:00
|
|
|
});
|
|
|
|
|
2023-06-12 20:38:07 +08:00
|
|
|
it("advanced user gets A rank", () => {
|
2023-05-26 21:39:35 +08:00
|
|
|
expect(
|
|
|
|
calculateRank({
|
|
|
|
all_commits: false,
|
|
|
|
commits: 500,
|
|
|
|
prs: 100,
|
|
|
|
issues: 50,
|
|
|
|
repos: 0,
|
2023-06-12 20:38:07 +08:00
|
|
|
stars: 200,
|
|
|
|
followers: 40,
|
2023-05-26 21:39:35 +08:00
|
|
|
}),
|
2023-06-12 20:38:07 +08:00
|
|
|
).toStrictEqual({ level: "A", percentile: 22.72727272727273 });
|
2023-05-26 21:39:35 +08:00
|
|
|
});
|
|
|
|
|
2023-06-12 20:38:07 +08:00
|
|
|
it("expert user gets A+ rank", () => {
|
2023-05-26 21:39:35 +08:00
|
|
|
expect(
|
|
|
|
calculateRank({
|
|
|
|
all_commits: false,
|
|
|
|
commits: 1000,
|
|
|
|
prs: 200,
|
|
|
|
issues: 100,
|
|
|
|
repos: 0,
|
2023-06-12 20:38:07 +08:00
|
|
|
stars: 800,
|
|
|
|
followers: 160,
|
2020-09-25 00:08:14 +08:00
|
|
|
}),
|
2023-06-12 20:38:07 +08:00
|
|
|
).toStrictEqual({ level: "A+", percentile: 6.082887700534744 });
|
2023-05-26 21:39:35 +08:00
|
|
|
});
|
|
|
|
|
2023-06-12 20:38:07 +08:00
|
|
|
it("sindresorhus gets S rank", () => {
|
2023-05-26 21:39:35 +08:00
|
|
|
expect(
|
|
|
|
calculateRank({
|
|
|
|
all_commits: false,
|
2023-06-12 20:38:07 +08:00
|
|
|
commits: 1300,
|
|
|
|
prs: 1500,
|
|
|
|
issues: 4500,
|
2023-05-26 21:39:35 +08:00
|
|
|
repos: 0,
|
2023-06-12 20:38:07 +08:00
|
|
|
stars: 600000,
|
|
|
|
followers: 50000,
|
2023-05-26 21:39:35 +08:00
|
|
|
}),
|
2023-06-12 20:38:07 +08:00
|
|
|
).toStrictEqual({ level: "S", percentile: 0.49947889605312934 });
|
2020-07-13 22:11:47 +08:00
|
|
|
});
|
|
|
|
});
|