diff options
Diffstat (limited to 'server/tests/utils/requests')
-rw-r--r-- | server/tests/utils/requests/requests.ts | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index b6195089d..ebde692cd 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { buildAbsoluteFixturePath } from '../miscs/miscs' | 2 | import { buildAbsoluteFixturePath } from '../miscs/miscs' |
3 | import { isAbsolute, join } from 'path' | ||
3 | 4 | ||
4 | function makeGetRequest (options: { | 5 | function makeGetRequest (options: { |
5 | url: string, | 6 | url: string, |
@@ -45,7 +46,7 @@ function makeUploadRequest (options: { | |||
45 | url: string, | 46 | url: string, |
46 | method?: 'POST' | 'PUT', | 47 | method?: 'POST' | 'PUT', |
47 | path: string, | 48 | path: string, |
48 | token: string, | 49 | token?: string, |
49 | fields: { [ fieldName: string ]: any }, | 50 | fields: { [ fieldName: string ]: any }, |
50 | attaches: { [ attachName: string ]: any }, | 51 | attaches: { [ attachName: string ]: any }, |
51 | statusCodeExpected?: number | 52 | statusCodeExpected?: number |
@@ -122,6 +123,29 @@ function makePutBodyRequest (options: { | |||
122 | .expect(options.statusCodeExpected) | 123 | .expect(options.statusCodeExpected) |
123 | } | 124 | } |
124 | 125 | ||
126 | function updateAvatarRequest (options: { | ||
127 | url: string, | ||
128 | path: string, | ||
129 | accessToken: string, | ||
130 | fixture: string | ||
131 | }) { | ||
132 | let filePath = '' | ||
133 | if (isAbsolute(options.fixture)) { | ||
134 | filePath = options.fixture | ||
135 | } else { | ||
136 | filePath = join(__dirname, '..', '..', 'fixtures', options.fixture) | ||
137 | } | ||
138 | |||
139 | return makeUploadRequest({ | ||
140 | url: options.url, | ||
141 | path: options.path, | ||
142 | token: options.accessToken, | ||
143 | fields: {}, | ||
144 | attaches: { avatarfile: filePath }, | ||
145 | statusCodeExpected: 200 | ||
146 | }) | ||
147 | } | ||
148 | |||
125 | // --------------------------------------------------------------------------- | 149 | // --------------------------------------------------------------------------- |
126 | 150 | ||
127 | export { | 151 | export { |
@@ -129,5 +153,6 @@ export { | |||
129 | makeUploadRequest, | 153 | makeUploadRequest, |
130 | makePostBodyRequest, | 154 | makePostBodyRequest, |
131 | makePutBodyRequest, | 155 | makePutBodyRequest, |
132 | makeDeleteRequest | 156 | makeDeleteRequest, |
157 | updateAvatarRequest | ||
133 | } | 158 | } |