-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocks.ts
90 lines (87 loc) · 2.38 KB
/
mocks.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
83
84
85
86
87
88
89
90
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Client, type Payload, type UploadProgress } from 'node-appwrite'
import type { AppwriteContext } from './src/types'
export const mockClient: Client = {
setEndpoint: (_endpoint: string) => mockClient,
setProject: (_projectId: string) => mockClient,
setJWT: (_jwt: string) => mockClient,
setSelfSigned: (_status?: boolean): Client => mockClient,
setKey: (_key: string): Client => mockClient,
setLocale: (_locale: string): Client => mockClient,
setSession: (_session: string): Client => mockClient,
setForwardedUserAgent: (_forwardeduseragent: string): Client => mockClient,
config: {
endpoint: '',
selfSigned: false,
project: '',
key: '',
jwt: '',
locale: '',
session: '',
forwardeduseragent: '',
},
headers: {},
addHeader: (_header: string, _value: string): Client => mockClient,
prepareRequest: (
_method: string,
_url: URL,
_headers?: { [key: string]: string },
_params?: Payload,
): { uri: string; options: RequestInit } => ({} as any),
chunkedUpload: (
_method: string,
_url: URL,
_headers: { [key: string]: string } | undefined,
_originalPayload: Payload | undefined,
_onProgress: (progress: UploadProgress) => void,
): Promise<any> => Promise.resolve({}),
redirect: (
_method: string,
_url: URL,
_headers?: { [key: string]: string },
_params?: Payload,
): Promise<string> => Promise.resolve(''),
call: (
_method: string,
_url: URL,
_headers?: { [key: string]: string },
_params?: Payload,
_responseType?: string,
): Promise<any> => Promise.resolve({}),
}
export const mockContext: AppwriteContext = {
req: {
bodyRaw: '',
body: '{}',
headers: {},
scheme: 'http',
method: 'GET',
url: 'http://localhost:3000',
host: 'localhost',
port: 3000,
path: '/',
queryString: '',
query: {},
},
res: {
json: (body: Record<string, any>) => {
console.log(body)
return body
},
empty: () => {
console.log('empty')
return ''
},
redirect: (url: string, status?: number) => console.log(url, status),
send: (body: string, status?: number, headers?: Record<string, string>) => {
console.log(body, status, headers)
return {
body,
status,
headers,
}
},
},
log: console.log,
error: console.error,
}