MCPcopy Create free account
hub / github.com/Tatamo/atcoder-cli / TestSession

Class TestSession

tests/utils/session.ts:12–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10 * Mocked Session whose response can be predefined.
11 */
12export class TestSession implements SessionInterface {
13 private getMockResponses: Map<string, MockResponse> = new Map();
14 private postMockResponses: Map<string, MockResponse> = new Map();
15
16 async get(url: string, _options?: AxiosRequestConfig): Promise<SessionResponseInterface> {
17 const responseObj = this.getMockResponses.get(url);
18 if (responseObj === undefined) {
19 throw new Error(`TestSession: network error to GET ${url}`);
20 }
21 return {
22 headers: {},
23 ...responseObj,
24 saveSession: async ()=>{}
25 };
26 }
27 async post(url: string, _data?: any, options?: AxiosRequestConfig): Promise<SessionResponseInterface> {
28 const responseObj = this.postMockResponses.get(url);
29 if (responseObj === undefined) {
30 throw new Error(`TestSession: network error to POST ${url}`);
31 }
32 return {
33 headers: {},
34 ...responseObj,
35 saveSession: async ()=>{}
36 };
37 }
38 transaction<R>(callback: ()=> Promise<R>): Promise<R> {
39 return callback();
40 }
41 async removeSession(): Promise<void> {
42 }
43
44 // testing methods
45 addGetMockResponse(url: string, response: MockResponse): void {
46 this.getMockResponses.set(url, response);
47 }
48 addPostMockResponse(url: string, response: MockResponse): void {
49 this.postMockResponses.set(url, response);
50 }
51}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected