-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.interface.ts
82 lines (69 loc) · 1.35 KB
/
api.interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type { DomainServices } from '@domain/index.js';
import type * as http from 'http';
/**
* API interface
*/
export default interface Api {
/**
* Initializes http server
* @param domainServices - instances of domain services
*/
init(domainServices: DomainServices): Promise<void>;
/**
* Runs API module
*/
run(): Promise<void>;
/**
* Makes fake request to API.
* Used for API testing
* @param params - request params
*/
fakeRequest(params: RequestParams): Promise<Response | undefined>;
}
/**
* Fake request params
*/
export interface RequestParams {
/**
* Request method
*/
method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH';
/**
* Request url
*/
url: string;
/**
* Request headers
*/
headers?: http.IncomingHttpHeaders | http.OutgoingHttpHeaders;
/**
* Request body
*/
body?: string | object | Buffer | NodeJS.ReadableStream;
/**
* Request cookies
*/
cookies?: { [k: string]: string };
}
/**
* Fake request response structure
*/
export interface Response {
/**
* Response status code
*/
statusCode: number;
/**
* Response body
*/
body: string;
/**
* Response headers
*/
headers: http.OutgoingHttpHeaders;
/**
* Converts body to json
*/
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
json: <T = any>() => T;
}