aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/users.ts14
-rw-r--r--server/tests/api/check-params/video-channels.ts56
-rw-r--r--server/tests/api/videos/video-channels.ts34
-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
6 files changed, 145 insertions, 20 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 28537315e..e1954c64f 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -304,6 +304,20 @@ describe('Test users API validators', function () {
304 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) 304 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
305 }) 305 })
306 306
307 it('Should fail with an unauthenticated user', async function () {
308 const fields = {}
309 const attaches = {
310 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
311 }
312 await makeUploadRequest({
313 url: server.url,
314 path: path + '/me/avatar/pick',
315 fields,
316 attaches,
317 statusCodeExpected: 401
318 })
319 })
320
307 it('Should succeed with the correct params', async function () { 321 it('Should succeed with the correct params', async function () {
308 const fields = {} 322 const fields = {}
309 const attaches = { 323 const attaches = {
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 5080af2c9..7b05e5882 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -14,7 +14,7 @@ import {
14 killallServers, 14 killallServers,
15 makeGetRequest, 15 makeGetRequest,
16 makePostBodyRequest, 16 makePostBodyRequest,
17 makePutBodyRequest, 17 makePutBodyRequest, makeUploadRequest,
18 runServer, 18 runServer,
19 ServerInfo, 19 ServerInfo,
20 setAccessTokensToServers, 20 setAccessTokensToServers,
@@ -22,6 +22,7 @@ import {
22} from '../../utils' 22} from '../../utils'
23import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 23import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
24import { User } from '../../../../shared/models/users' 24import { User } from '../../../../shared/models/users'
25import { join } from "path"
25 26
26const expect = chai.expect 27const expect = chai.expect
27 28
@@ -189,6 +190,59 @@ describe('Test video channels API validator', function () {
189 }) 190 })
190 }) 191 })
191 192
193 describe('When updating video channel avatar', function () {
194 let path: string
195
196 before(async function () {
197 path = videoChannelPath + '/' + videoChannelUUID
198 })
199
200 it('Should fail with an incorrect input file', async function () {
201 const fields = {}
202 const attaches = {
203 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
204 }
205 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
206 })
207
208 it('Should fail with a big file', async function () {
209 const fields = {}
210 const attaches = {
211 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
212 }
213 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
214 })
215
216 it('Should fail with an unauthenticated user', async function () {
217 const fields = {}
218 const attaches = {
219 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
220 }
221 await makeUploadRequest({
222 url: server.url,
223 path: path + '/avatar/pick',
224 fields,
225 attaches,
226 statusCodeExpected: 401
227 })
228 })
229
230 it('Should succeed with the correct params', async function () {
231 const fields = {}
232 const attaches = {
233 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
234 }
235 await makeUploadRequest({
236 url: server.url,
237 path: path + '/avatar/pick',
238 token: server.accessToken,
239 fields,
240 attaches,
241 statusCodeExpected: 200
242 })
243 })
244 })
245
192 describe('When getting a video channel', function () { 246 describe('When getting a video channel', function () {
193 it('Should return the list of the video channels with nothing', async function () { 247 it('Should return the list of the video channels with nothing', async function () {
194 const res = await makeGetRequest({ 248 const res = await makeGetRequest({
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index ad543e2d6..e4e3ce9d9 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -3,7 +3,14 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { User, Video } from '../../../../shared/index' 5import { User, Video } from '../../../../shared/index'
6import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, updateVideo, uploadVideo } from '../../utils' 6import {
7 doubleFollow,
8 flushAndRunMultipleServers,
9 getVideoChannelVideos, testImage,
10 updateVideo,
11 updateVideoChannelAvatar,
12 uploadVideo, wait
13} from '../../utils'
7import { 14import {
8 addVideoChannel, 15 addVideoChannel,
9 deleteVideoChannel, 16 deleteVideoChannel,
@@ -159,6 +166,31 @@ describe('Test video channels', function () {
159 } 166 }
160 }) 167 })
161 168
169 it('Should update video channel avatar', async function () {
170 this.timeout(5000)
171
172 const fixture = 'avatar.png'
173
174 await updateVideoChannelAvatar({
175 url: servers[0].url,
176 accessToken: servers[0].accessToken,
177 videoChannelId: secondVideoChannelId,
178 fixture
179 })
180
181 await waitJobs(servers)
182 })
183
184 it('Should have video channel avatar updated', async function () {
185 for (const server of servers) {
186 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
187
188 const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId)
189
190 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
191 }
192 })
193
162 it('Should get video channel', async function () { 194 it('Should get video channel', async function () {
163 const res = await getVideoChannel(servers[0].url, secondVideoChannelId) 195 const res = await getVideoChannel(servers[0].url, secondVideoChannelId)
164 196
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,