aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils')
-rw-r--r--server/tests/utils/requests/requests.ts29
-rw-r--r--server/tests/utils/users/users.ts18
-rw-r--r--server/tests/utils/videos/video-channels.ts14
3 files changed, 43 insertions, 18 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 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { buildAbsoluteFixturePath } from '../miscs/miscs' 2import { buildAbsoluteFixturePath } from '../miscs/miscs'
3import { isAbsolute, join } from 'path'
3 4
4function makeGetRequest (options: { 5function 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
126function 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
127export { 151export {
@@ -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}
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index 34d50f7ad..37b15f64a 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -1,6 +1,5 @@
1import { isAbsolute, join } from 'path'
2import * as request from 'supertest' 1import * as request from 'supertest'
3import { makePostBodyRequest, makeUploadRequest, makePutBodyRequest } from '../' 2import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../'
4 3
5import { UserRole } from '../../../../shared/index' 4import { UserRole } from '../../../../shared/index'
6import { NSFWPolicyType } from '../../../../shared/models/videos/nsfw-policy.type' 5import { NSFWPolicyType } from '../../../../shared/models/videos/nsfw-policy.type'
@@ -160,21 +159,8 @@ function updateMyAvatar (options: {
160 fixture: string 159 fixture: string
161}) { 160}) {
162 const path = '/api/v1/users/me/avatar/pick' 161 const path = '/api/v1/users/me/avatar/pick'
163 let filePath = ''
164 if (isAbsolute(options.fixture)) {
165 filePath = options.fixture
166 } else {
167 filePath = join(__dirname, '..', '..', 'fixtures', options.fixture)
168 }
169 162
170 return makeUploadRequest({ 163 return updateAvatarRequest(Object.assign(options, { path }))
171 url: options.url,
172 path,
173 token: options.accessToken,
174 fields: {},
175 attaches: { avatarfile: filePath },
176 statusCodeExpected: 200
177 })
178} 164}
179 165
180function updateUser (options: { 166function updateUser (options: {
diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts
index a064598f4..3ca39469c 100644
--- a/server/tests/utils/videos/video-channels.ts
+++ b/server/tests/utils/videos/video-channels.ts
@@ -1,5 +1,6 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared/models/videos' 2import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared/models/videos'
3import { updateAvatarRequest } from '../index'
3 4
4function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { 5function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
5 const path = '/api/v1/video-channels' 6 const path = '/api/v1/video-channels'
@@ -92,9 +93,22 @@ function getVideoChannel (url: string, channelId: number | string) {
92 .expect('Content-Type', /json/) 93 .expect('Content-Type', /json/)
93} 94}
94 95
96function updateVideoChannelAvatar (options: {
97 url: string,
98 accessToken: string,
99 fixture: string,
100 videoChannelId: string | number
101}) {
102
103 const path = '/api/v1/video-channels/' + options.videoChannelId + '/avatar/pick'
104
105 return updateAvatarRequest(Object.assign(options, { path }))
106}
107
95// --------------------------------------------------------------------------- 108// ---------------------------------------------------------------------------
96 109
97export { 110export {
111 updateVideoChannelAvatar,
98 getVideoChannelsList, 112 getVideoChannelsList,
99 getAccountVideoChannelsList, 113 getAccountVideoChannelsList,
100 addVideoChannel, 114 addVideoChannel,