Skip to content

Commit fe74d55

Browse files
committed
small fixes
1 parent 9fed5e7 commit fe74d55

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/axios.js renamed to src/fetcher-utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ const instance = Axios.create({
77
"User-Agent": "Codeforces Readme Stats",
88
},
99
});
10+
1011
export const api = setupCache(instance);
12+
export const last_rating_cache = new Map();
13+
export const last_stats_cache = new Map();

src/fetcher.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { capitalize } from "@/common.js";
2-
import { api } from "@/axios.js";
3-
4-
const last_rating_cache = new Map();
5-
const last_stats_cache = new Map();
2+
import { api, last_rating_cache, last_stats_cache } from "@/fetcher-utils.js";
63

74
function fetch_error_handler(fetch, username, last_cache) {
85
return new Promise((resolve, reject) => {

test/badge.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { jest } from "@jest/globals";
22
import { CONSTANTS, COLORS, clamp_value } from "@/common.js";
33

4-
jest.unstable_mockModule("@/axios.js", () => {
4+
jest.unstable_mockModule("@/fetcher-utils", () => {
55
return {
66
api: {
77
get: jest.fn(),
88
},
9+
last_rating_cache: {set: jest.fn(), get: jest.fn()},
10+
last_stats_cache: {set: jest.fn(), get: jest.fn()},
911
};
1012
});
1113

12-
const { api } = await import("@/axios.js");
14+
const { api, last_rating_cache } = await import("@/fetcher-utils.js");
1315
const handler = (await import("@/pages/api/badge.js")).default;
1416

1517
describe("badge handler", () => {
@@ -137,6 +139,7 @@ describe("badge handler", () => {
137139
status: 400,
138140
},
139141
});
142+
last_rating_cache.get = () => undefined;
140143

141144
await handler(req, res);
142145

test/card.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import { jest } from "@jest/globals";
22
import { CONSTANTS, COLORS, clamp_value } from "@/common.js";
33
import {user} from "./test-data.js";
44

5-
jest.unstable_mockModule("@/axios.js", () => {
5+
jest.unstable_mockModule("@/fetcher-utils", () => {
66
return {
77
api: {
8-
get: jest.fn(),
8+
get: jest.fn()
99
},
10+
last_rating_cache: {set: jest.fn(), get: jest.fn()},
11+
last_stats_cache: {set: jest.fn(), get: jest.fn()},
1012
};
1113
});
1214

13-
const { api } = await import("@/axios.js");
15+
const { api, last_stats_cache } = await import("@/fetcher-utils.js");
1416
const handler = (await import("@/pages/api/card.js")).default;
1517

1618
describe("card handler", () => {
@@ -111,6 +113,7 @@ describe("card handler", () => {
111113
status: 400,
112114
},
113115
});
116+
last_stats_cache.get = () => undefined;
114117

115118
await handler(req, res);
116119

0 commit comments

Comments
 (0)