File tree Expand file tree Collapse file tree 4 files changed +15
-9
lines changed Expand file tree Collapse file tree 4 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -7,4 +7,7 @@ const instance = Axios.create({
7
7
"User-Agent" : "Codeforces Readme Stats" ,
8
8
} ,
9
9
} ) ;
10
+
10
11
export const api = setupCache ( instance ) ;
12
+ export const last_rating_cache = new Map ( ) ;
13
+ export const last_stats_cache = new Map ( ) ;
Original file line number Diff line number Diff line change 1
1
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" ;
6
3
7
4
function fetch_error_handler ( fetch , username , last_cache ) {
8
5
return new Promise ( ( resolve , reject ) => {
Original file line number Diff line number Diff line change 1
1
import { jest } from "@jest/globals" ;
2
2
import { CONSTANTS , COLORS , clamp_value } from "@/common.js" ;
3
3
4
- jest . unstable_mockModule ( "@/axios.js " , ( ) => {
4
+ jest . unstable_mockModule ( "@/fetcher-utils " , ( ) => {
5
5
return {
6
6
api : {
7
7
get : jest . fn ( ) ,
8
8
} ,
9
+ last_rating_cache : { set : jest . fn ( ) , get : jest . fn ( ) } ,
10
+ last_stats_cache : { set : jest . fn ( ) , get : jest . fn ( ) } ,
9
11
} ;
10
12
} ) ;
11
13
12
- const { api } = await import ( "@/axios .js" ) ;
14
+ const { api, last_rating_cache } = await import ( "@/fetcher-utils .js" ) ;
13
15
const handler = ( await import ( "@/pages/api/badge.js" ) ) . default ;
14
16
15
17
describe ( "badge handler" , ( ) => {
@@ -137,6 +139,7 @@ describe("badge handler", () => {
137
139
status : 400 ,
138
140
} ,
139
141
} ) ;
142
+ last_rating_cache . get = ( ) => undefined ;
140
143
141
144
await handler ( req , res ) ;
142
145
Original file line number Diff line number Diff line change @@ -2,15 +2,17 @@ import { jest } from "@jest/globals";
2
2
import { CONSTANTS , COLORS , clamp_value } from "@/common.js" ;
3
3
import { user } from "./test-data.js" ;
4
4
5
- jest . unstable_mockModule ( "@/axios.js " , ( ) => {
5
+ jest . unstable_mockModule ( "@/fetcher-utils " , ( ) => {
6
6
return {
7
7
api : {
8
- get : jest . fn ( ) ,
8
+ get : jest . fn ( )
9
9
} ,
10
+ last_rating_cache : { set : jest . fn ( ) , get : jest . fn ( ) } ,
11
+ last_stats_cache : { set : jest . fn ( ) , get : jest . fn ( ) } ,
10
12
} ;
11
13
} ) ;
12
14
13
- const { api } = await import ( "@/axios .js" ) ;
15
+ const { api, last_stats_cache } = await import ( "@/fetcher-utils .js" ) ;
14
16
const handler = ( await import ( "@/pages/api/card.js" ) ) . default ;
15
17
16
18
describe ( "card handler" , ( ) => {
@@ -111,6 +113,7 @@ describe("card handler", () => {
111
113
status : 400 ,
112
114
} ,
113
115
} ) ;
116
+ last_stats_cache . get = ( ) => undefined ;
114
117
115
118
await handler ( req , res ) ;
116
119
You can’t perform that action at this time.
0 commit comments