返回 AiToEarn
agent.ts
1 import * as supertest from 'supertest';
2 import { INestApplication } from '@nestjs/common';
3
4 export class Agent {
5 private static _app: INestApplication;
6
7 private static _agent: supertest.Agent;
8
9 public static app(): INestApplication {
10 return Agent._app;
11 }
12
13 public static async initialize(app: INestApplication): Promise<void> {
14 Agent._app = app;
15
16 const agent = supertest.agent(Agent._app.getHttpServer());
17 Agent._agent = agent;
18 }
19
20 public static get() {
21 return Agent._agent;
22 }
23
24 public static login(token: string) {
25 this._agent.set('Authorization', `Bearer ${token}`);
26 }
27 }
28
28 lines TYPESCRIPT