diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-13 18:17:05 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-14 16:03:09 +0100 |
commit | ac81d1a06d57b9ae86663831e7f5edcef57b0fa4 (patch) | |
tree | da31775c9533d3e270f68f921e146f086bf7c0b8 /server/tests | |
parent | e883399fa6caa56bb8519c9a2e22d88001f26661 (diff) | |
download | PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.gz PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.zst PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.zip |
Add ability to set video thumbnail/preview
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/users.ts | 8 | ||||
-rw-r--r-- | server/tests/api/check-params/videos.ts | 150 | ||||
-rw-r--r-- | server/tests/api/fixtures/preview.jpg | bin | 0 -> 4215 bytes | |||
-rw-r--r-- | server/tests/api/fixtures/thumbnail.jpg | bin | 0 -> 1457 bytes | |||
-rw-r--r-- | server/tests/api/videos/multiple-servers.ts | 16 | ||||
-rw-r--r-- | server/tests/utils/miscs/miscs.ts | 15 | ||||
-rw-r--r-- | server/tests/utils/requests/requests.ts | 19 | ||||
-rw-r--r-- | server/tests/utils/users/users.ts | 4 | ||||
-rw-r--r-- | server/tests/utils/videos/videos.ts | 83 |
9 files changed, 230 insertions, 65 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 0fbc414c9..d9dea0713 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -7,7 +7,7 @@ import { UserRole } from '../../../../shared' | |||
7 | 7 | ||
8 | import { | 8 | import { |
9 | createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, | 9 | createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, |
10 | makePostBodyRequest, makePostUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, | 10 | makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, |
11 | updateUser, uploadVideo, userLogin | 11 | updateUser, uploadVideo, userLogin |
12 | } from '../../utils' | 12 | } from '../../utils' |
13 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 13 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
@@ -273,7 +273,7 @@ describe('Test users API validators', function () { | |||
273 | const attaches = { | 273 | const attaches = { |
274 | 'avatarfile': join(__dirname, '..', 'fixtures', 'video_short.mp4') | 274 | 'avatarfile': join(__dirname, '..', 'fixtures', 'video_short.mp4') |
275 | } | 275 | } |
276 | await makePostUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) | 276 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) |
277 | }) | 277 | }) |
278 | 278 | ||
279 | it('Should fail with a big file', async function () { | 279 | it('Should fail with a big file', async function () { |
@@ -281,7 +281,7 @@ describe('Test users API validators', function () { | |||
281 | const attaches = { | 281 | const attaches = { |
282 | 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar-big.png') | 282 | 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar-big.png') |
283 | } | 283 | } |
284 | await makePostUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) | 284 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) |
285 | }) | 285 | }) |
286 | 286 | ||
287 | it('Should succeed with the correct params', async function () { | 287 | it('Should succeed with the correct params', async function () { |
@@ -289,7 +289,7 @@ describe('Test users API validators', function () { | |||
289 | const attaches = { | 289 | const attaches = { |
290 | 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar.png') | 290 | 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar.png') |
291 | } | 291 | } |
292 | await makePostUploadRequest({ | 292 | await makeUploadRequest({ |
293 | url: server.url, | 293 | url: server.url, |
294 | path: path + '/me/avatar/pick', | 294 | path: path + '/me/avatar/pick', |
295 | token: server.accessToken, | 295 | token: server.accessToken, |
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index f25e3f595..aa30b721b 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts | |||
@@ -7,7 +7,7 @@ import { join } from 'path' | |||
7 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | 7 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' |
8 | import { | 8 | import { |
9 | createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, | 9 | createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, |
10 | makeGetRequest, makePostUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin | 10 | makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin |
11 | } from '../../utils' | 11 | } from '../../utils' |
12 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 12 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
13 | 13 | ||
@@ -111,91 +111,91 @@ describe('Test videos API validator', function () { | |||
111 | it('Should fail with nothing', async function () { | 111 | it('Should fail with nothing', async function () { |
112 | const fields = {} | 112 | const fields = {} |
113 | const attaches = {} | 113 | const attaches = {} |
114 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 114 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
115 | }) | 115 | }) |
116 | 116 | ||
117 | it('Should fail without name', async function () { | 117 | it('Should fail without name', async function () { |
118 | const fields = omit(baseCorrectParams, 'name') | 118 | const fields = omit(baseCorrectParams, 'name') |
119 | const attaches = baseCorrectAttaches | 119 | const attaches = baseCorrectAttaches |
120 | 120 | ||
121 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 121 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
122 | }) | 122 | }) |
123 | 123 | ||
124 | it('Should fail with a long name', async function () { | 124 | it('Should fail with a long name', async function () { |
125 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) | 125 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) |
126 | const attaches = baseCorrectAttaches | 126 | const attaches = baseCorrectAttaches |
127 | 127 | ||
128 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 128 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
129 | }) | 129 | }) |
130 | 130 | ||
131 | it('Should fail with a bad category', async function () { | 131 | it('Should fail with a bad category', async function () { |
132 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) | 132 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) |
133 | const attaches = baseCorrectAttaches | 133 | const attaches = baseCorrectAttaches |
134 | 134 | ||
135 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 135 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
136 | }) | 136 | }) |
137 | 137 | ||
138 | it('Should fail with a bad licence', async function () { | 138 | it('Should fail with a bad licence', async function () { |
139 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) | 139 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) |
140 | const attaches = baseCorrectAttaches | 140 | const attaches = baseCorrectAttaches |
141 | 141 | ||
142 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 142 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
143 | }) | 143 | }) |
144 | 144 | ||
145 | it('Should fail with a bad language', async function () { | 145 | it('Should fail with a bad language', async function () { |
146 | const fields = immutableAssign(baseCorrectParams, { language: 125 }) | 146 | const fields = immutableAssign(baseCorrectParams, { language: 125 }) |
147 | const attaches = baseCorrectAttaches | 147 | const attaches = baseCorrectAttaches |
148 | 148 | ||
149 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 149 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
150 | }) | 150 | }) |
151 | 151 | ||
152 | it('Should fail without nsfw attribute', async function () { | 152 | it('Should fail without nsfw attribute', async function () { |
153 | const fields = omit(baseCorrectParams, 'nsfw') | 153 | const fields = omit(baseCorrectParams, 'nsfw') |
154 | const attaches = baseCorrectAttaches | 154 | const attaches = baseCorrectAttaches |
155 | 155 | ||
156 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 156 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
157 | }) | 157 | }) |
158 | 158 | ||
159 | it('Should fail with a bad nsfw attribute', async function () { | 159 | it('Should fail with a bad nsfw attribute', async function () { |
160 | const fields = immutableAssign(baseCorrectParams, { nsfw: 2 }) | 160 | const fields = immutableAssign(baseCorrectParams, { nsfw: 2 }) |
161 | const attaches = baseCorrectAttaches | 161 | const attaches = baseCorrectAttaches |
162 | 162 | ||
163 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 163 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
164 | }) | 164 | }) |
165 | 165 | ||
166 | it('Should fail without commentsEnabled attribute', async function () { | 166 | it('Should fail without commentsEnabled attribute', async function () { |
167 | const fields = omit(baseCorrectParams, 'commentsEnabled') | 167 | const fields = omit(baseCorrectParams, 'commentsEnabled') |
168 | const attaches = baseCorrectAttaches | 168 | const attaches = baseCorrectAttaches |
169 | 169 | ||
170 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 170 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
171 | }) | 171 | }) |
172 | 172 | ||
173 | it('Should fail with a bad commentsEnabled attribute', async function () { | 173 | it('Should fail with a bad commentsEnabled attribute', async function () { |
174 | const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 }) | 174 | const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 }) |
175 | const attaches = baseCorrectAttaches | 175 | const attaches = baseCorrectAttaches |
176 | 176 | ||
177 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 177 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
178 | }) | 178 | }) |
179 | 179 | ||
180 | it('Should fail with a long description', async function () { | 180 | it('Should fail with a long description', async function () { |
181 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) | 181 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) |
182 | const attaches = baseCorrectAttaches | 182 | const attaches = baseCorrectAttaches |
183 | 183 | ||
184 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 184 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
185 | }) | 185 | }) |
186 | 186 | ||
187 | it('Should fail without a channel', async function () { | 187 | it('Should fail without a channel', async function () { |
188 | const fields = omit(baseCorrectParams, 'channelId') | 188 | const fields = omit(baseCorrectParams, 'channelId') |
189 | const attaches = baseCorrectAttaches | 189 | const attaches = baseCorrectAttaches |
190 | 190 | ||
191 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 191 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
192 | }) | 192 | }) |
193 | 193 | ||
194 | it('Should fail with a bad channel', async function () { | 194 | it('Should fail with a bad channel', async function () { |
195 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | 195 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) |
196 | const attaches = baseCorrectAttaches | 196 | const attaches = baseCorrectAttaches |
197 | 197 | ||
198 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 198 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
199 | }) | 199 | }) |
200 | 200 | ||
201 | it('Should fail with another user channel', async function () { | 201 | it('Should fail with another user channel', async function () { |
@@ -212,34 +212,34 @@ describe('Test videos API validator', function () { | |||
212 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) | 212 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) |
213 | const attaches = baseCorrectAttaches | 213 | const attaches = baseCorrectAttaches |
214 | 214 | ||
215 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 215 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
216 | }) | 216 | }) |
217 | 217 | ||
218 | it('Should fail with too many tags', async function () { | 218 | it('Should fail with too many tags', async function () { |
219 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) | 219 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) |
220 | const attaches = baseCorrectAttaches | 220 | const attaches = baseCorrectAttaches |
221 | 221 | ||
222 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 222 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
223 | }) | 223 | }) |
224 | 224 | ||
225 | it('Should fail with a tag length too low', async function () { | 225 | it('Should fail with a tag length too low', async function () { |
226 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) | 226 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) |
227 | const attaches = baseCorrectAttaches | 227 | const attaches = baseCorrectAttaches |
228 | 228 | ||
229 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 229 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
230 | }) | 230 | }) |
231 | 231 | ||
232 | it('Should fail with a tag length too big', async function () { | 232 | it('Should fail with a tag length too big', async function () { |
233 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) | 233 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) |
234 | const attaches = baseCorrectAttaches | 234 | const attaches = baseCorrectAttaches |
235 | 235 | ||
236 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 236 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
237 | }) | 237 | }) |
238 | 238 | ||
239 | it('Should fail without an input file', async function () { | 239 | it('Should fail without an input file', async function () { |
240 | const fields = baseCorrectParams | 240 | const fields = baseCorrectParams |
241 | const attaches = {} | 241 | const attaches = {} |
242 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 242 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
243 | }) | 243 | }) |
244 | 244 | ||
245 | it('Should fail without an incorrect input file', async function () { | 245 | it('Should fail without an incorrect input file', async function () { |
@@ -247,7 +247,47 @@ describe('Test videos API validator', function () { | |||
247 | const attaches = { | 247 | const attaches = { |
248 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | 248 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') |
249 | } | 249 | } |
250 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | 250 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
251 | }) | ||
252 | |||
253 | it('Should fail with an incorrect thumbnail file', async function () { | ||
254 | const fields = baseCorrectParams | ||
255 | const attaches = { | ||
256 | 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png'), | ||
257 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | ||
258 | } | ||
259 | |||
260 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | ||
261 | }) | ||
262 | |||
263 | it('Should fail with a big thumbnail file', async function () { | ||
264 | const fields = baseCorrectParams | ||
265 | const attaches = { | ||
266 | 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'), | ||
267 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | ||
268 | } | ||
269 | |||
270 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | ||
271 | }) | ||
272 | |||
273 | it('Should fail with an incorrect preview file', async function () { | ||
274 | const fields = baseCorrectParams | ||
275 | const attaches = { | ||
276 | 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png'), | ||
277 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | ||
278 | } | ||
279 | |||
280 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | ||
281 | }) | ||
282 | |||
283 | it('Should fail with a big preview file', async function () { | ||
284 | const fields = baseCorrectParams | ||
285 | const attaches = { | ||
286 | 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'), | ||
287 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | ||
288 | } | ||
289 | |||
290 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | ||
251 | }) | 291 | }) |
252 | 292 | ||
253 | it('Should succeed with the correct parameters', async function () { | 293 | it('Should succeed with the correct parameters', async function () { |
@@ -257,7 +297,7 @@ describe('Test videos API validator', function () { | |||
257 | 297 | ||
258 | { | 298 | { |
259 | const attaches = baseCorrectAttaches | 299 | const attaches = baseCorrectAttaches |
260 | await makePostUploadRequest({ | 300 | await makeUploadRequest({ |
261 | url: server.url, | 301 | url: server.url, |
262 | path: path + '/upload', | 302 | path: path + '/upload', |
263 | token: server.accessToken, | 303 | token: server.accessToken, |
@@ -272,7 +312,7 @@ describe('Test videos API validator', function () { | |||
272 | videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4') | 312 | videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4') |
273 | }) | 313 | }) |
274 | 314 | ||
275 | await makePostUploadRequest({ | 315 | await makeUploadRequest({ |
276 | url: server.url, | 316 | url: server.url, |
277 | path: path + '/upload', | 317 | path: path + '/upload', |
278 | token: server.accessToken, | 318 | token: server.accessToken, |
@@ -287,7 +327,7 @@ describe('Test videos API validator', function () { | |||
287 | videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv') | 327 | videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv') |
288 | }) | 328 | }) |
289 | 329 | ||
290 | await makePostUploadRequest({ | 330 | await makeUploadRequest({ |
291 | url: server.url, | 331 | url: server.url, |
292 | path: path + '/upload', | 332 | path: path + '/upload', |
293 | token: server.accessToken, | 333 | token: server.accessToken, |
@@ -400,6 +440,70 @@ describe('Test videos API validator', function () { | |||
400 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | 440 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
401 | }) | 441 | }) |
402 | 442 | ||
443 | it('Should fail with an incorrect thumbnail file', async function () { | ||
444 | const fields = baseCorrectParams | ||
445 | const attaches = { | ||
446 | 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png') | ||
447 | } | ||
448 | |||
449 | await makeUploadRequest({ | ||
450 | url: server.url, | ||
451 | method: 'PUT', | ||
452 | path: path + videoId, | ||
453 | token: server.accessToken, | ||
454 | fields, | ||
455 | attaches | ||
456 | }) | ||
457 | }) | ||
458 | |||
459 | it('Should fail with a big thumbnail file', async function () { | ||
460 | const fields = baseCorrectParams | ||
461 | const attaches = { | ||
462 | 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png') | ||
463 | } | ||
464 | |||
465 | await makeUploadRequest({ | ||
466 | url: server.url, | ||
467 | method: 'PUT', | ||
468 | path: path + videoId, | ||
469 | token: server.accessToken, | ||
470 | fields, | ||
471 | attaches | ||
472 | }) | ||
473 | }) | ||
474 | |||
475 | it('Should fail with an incorrect preview file', async function () { | ||
476 | const fields = baseCorrectParams | ||
477 | const attaches = { | ||
478 | 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png') | ||
479 | } | ||
480 | |||
481 | await makeUploadRequest({ | ||
482 | url: server.url, | ||
483 | method: 'PUT', | ||
484 | path: path + videoId, | ||
485 | token: server.accessToken, | ||
486 | fields, | ||
487 | attaches | ||
488 | }) | ||
489 | }) | ||
490 | |||
491 | it('Should fail with a big preview file', async function () { | ||
492 | const fields = baseCorrectParams | ||
493 | const attaches = { | ||
494 | 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png') | ||
495 | } | ||
496 | |||
497 | await makeUploadRequest({ | ||
498 | url: server.url, | ||
499 | method: 'PUT', | ||
500 | path: path + videoId, | ||
501 | token: server.accessToken, | ||
502 | fields, | ||
503 | attaches | ||
504 | }) | ||
505 | }) | ||
506 | |||
403 | it('Should fail with a video of another user') | 507 | it('Should fail with a video of another user') |
404 | 508 | ||
405 | it('Should fail with a video of another server') | 509 | it('Should fail with a video of another server') |
diff --git a/server/tests/api/fixtures/preview.jpg b/server/tests/api/fixtures/preview.jpg new file mode 100644 index 000000000..c40ece838 --- /dev/null +++ b/server/tests/api/fixtures/preview.jpg | |||
Binary files differ | |||
diff --git a/server/tests/api/fixtures/thumbnail.jpg b/server/tests/api/fixtures/thumbnail.jpg new file mode 100644 index 000000000..cc3af8a4a --- /dev/null +++ b/server/tests/api/fixtures/thumbnail.jpg | |||
Binary files differ | |||
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 0215b3011..3646fbb0f 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts | |||
@@ -137,7 +137,9 @@ describe('Test multiple servers', function () { | |||
137 | nsfw: true, | 137 | nsfw: true, |
138 | description: 'my super description for server 2', | 138 | description: 'my super description for server 2', |
139 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], | 139 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], |
140 | fixture: 'video_short2.webm' | 140 | fixture: 'video_short2.webm', |
141 | thumbnailfile: 'thumbnail.jpg', | ||
142 | previewfile: 'preview.jpg' | ||
141 | } | 143 | } |
142 | await uploadVideo(servers[1].url, userAccessToken, videoAttributes) | 144 | await uploadVideo(servers[1].url, userAccessToken, videoAttributes) |
143 | 145 | ||
@@ -184,7 +186,9 @@ describe('Test multiple servers', function () { | |||
184 | resolution: 720, | 186 | resolution: 720, |
185 | size: 710000 | 187 | size: 710000 |
186 | } | 188 | } |
187 | ] | 189 | ], |
190 | thumbnailfile: 'thumbnail', | ||
191 | previewfile: 'preview' | ||
188 | } | 192 | } |
189 | 193 | ||
190 | const res = await getVideosList(server.url) | 194 | const res = await getVideosList(server.url) |
@@ -521,7 +525,9 @@ describe('Test multiple servers', function () { | |||
521 | language: 13, | 525 | language: 13, |
522 | nsfw: true, | 526 | nsfw: true, |
523 | description: 'my super description updated', | 527 | description: 'my super description updated', |
524 | tags: [ 'tag_up_1', 'tag_up_2' ] | 528 | tags: [ 'tag_up_1', 'tag_up_2' ], |
529 | thumbnailfile: 'thumbnail.jpg', | ||
530 | previewfile: 'preview.jpg' | ||
525 | } | 531 | } |
526 | 532 | ||
527 | await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) | 533 | await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) |
@@ -565,7 +571,9 @@ describe('Test multiple servers', function () { | |||
565 | resolution: 720, | 571 | resolution: 720, |
566 | size: 292677 | 572 | size: 292677 |
567 | } | 573 | } |
568 | ] | 574 | ], |
575 | thumbnailfile: 'thumbnail', | ||
576 | previewfile: 'preview' | ||
569 | } | 577 | } |
570 | await completeVideoCheck(server.url, videoUpdated, checkAttributes) | 578 | await completeVideoCheck(server.url, videoUpdated, checkAttributes) |
571 | } | 579 | } |
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts index 99d109bfe..24cbf59ca 100644 --- a/server/tests/utils/miscs/miscs.ts +++ b/server/tests/utils/miscs/miscs.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* tslint:disable:no-unused-expression */ |
2 | 2 | ||
3 | import { join } from 'path' | 3 | import { isAbsolute, join } from 'path' |
4 | import * as request from 'supertest' | 4 | import * as request from 'supertest' |
5 | import * as WebTorrent from 'webtorrent' | 5 | import * as WebTorrent from 'webtorrent' |
6 | import { readFileBufferPromise } from '../../../helpers/core-utils' | 6 | import { readFileBufferPromise } from '../../../helpers/core-utils' |
@@ -45,8 +45,8 @@ async function testImage (url: string, imageName: string, imagePath: string, ext | |||
45 | const body = res.body | 45 | const body = res.body |
46 | 46 | ||
47 | const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) | 47 | const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) |
48 | const minLength = body.length - ((50 * body.length) / 100) | 48 | const minLength = body.length - ((20 * body.length) / 100) |
49 | const maxLength = body.length + ((50 * body.length) / 100) | 49 | const maxLength = body.length + ((20 * body.length) / 100) |
50 | 50 | ||
51 | return data.length > minLength && data.length < maxLength | 51 | return data.length > minLength && data.length < maxLength |
52 | } else { | 52 | } else { |
@@ -55,6 +55,14 @@ async function testImage (url: string, imageName: string, imagePath: string, ext | |||
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | function buildAbsoluteFixturePath (path: string) { | ||
59 | if (isAbsolute(path)) { | ||
60 | return path | ||
61 | } | ||
62 | |||
63 | return join(__dirname, '..', '..', 'api', 'fixtures', path) | ||
64 | } | ||
65 | |||
58 | // --------------------------------------------------------------------------- | 66 | // --------------------------------------------------------------------------- |
59 | 67 | ||
60 | export { | 68 | export { |
@@ -63,5 +71,6 @@ export { | |||
63 | webtorrentAdd, | 71 | webtorrentAdd, |
64 | immutableAssign, | 72 | immutableAssign, |
65 | testImage, | 73 | testImage, |
74 | buildAbsoluteFixturePath, | ||
66 | root | 75 | root |
67 | } | 76 | } |
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index 840072430..a9b1dff9a 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { buildAbsoluteFixturePath } from '../' | ||
2 | 3 | ||
3 | function makeGetRequest (options: { | 4 | function makeGetRequest (options: { |
4 | url: string, | 5 | url: string, |
@@ -40,8 +41,9 @@ function makeDeleteRequest (options: { | |||
40 | .expect(options.statusCodeExpected) | 41 | .expect(options.statusCodeExpected) |
41 | } | 42 | } |
42 | 43 | ||
43 | function makePostUploadRequest (options: { | 44 | function makeUploadRequest (options: { |
44 | url: string, | 45 | url: string, |
46 | method?: 'POST' | 'PUT', | ||
45 | path: string, | 47 | path: string, |
46 | token: string, | 48 | token: string, |
47 | fields: { [ fieldName: string ]: any }, | 49 | fields: { [ fieldName: string ]: any }, |
@@ -50,9 +52,14 @@ function makePostUploadRequest (options: { | |||
50 | }) { | 52 | }) { |
51 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 53 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 |
52 | 54 | ||
53 | const req = request(options.url) | 55 | let req: request.Test |
54 | .post(options.path) | 56 | if (options.method === 'PUT') { |
55 | .set('Accept', 'application/json') | 57 | req = request(options.url).put(options.path) |
58 | } else { | ||
59 | req = request(options.url).post(options.path) | ||
60 | } | ||
61 | |||
62 | req.set('Accept', 'application/json') | ||
56 | 63 | ||
57 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) | 64 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) |
58 | 65 | ||
@@ -70,7 +77,7 @@ function makePostUploadRequest (options: { | |||
70 | 77 | ||
71 | Object.keys(options.attaches).forEach(attach => { | 78 | Object.keys(options.attaches).forEach(attach => { |
72 | const value = options.attaches[attach] | 79 | const value = options.attaches[attach] |
73 | req.attach(attach, value) | 80 | req.attach(attach, buildAbsoluteFixturePath(value)) |
74 | }) | 81 | }) |
75 | 82 | ||
76 | return req.expect(options.statusCodeExpected) | 83 | return req.expect(options.statusCodeExpected) |
@@ -119,7 +126,7 @@ function makePutBodyRequest (options: { | |||
119 | 126 | ||
120 | export { | 127 | export { |
121 | makeGetRequest, | 128 | makeGetRequest, |
122 | makePostUploadRequest, | 129 | makeUploadRequest, |
123 | makePostBodyRequest, | 130 | makePostBodyRequest, |
124 | makePutBodyRequest, | 131 | makePutBodyRequest, |
125 | makeDeleteRequest | 132 | makeDeleteRequest |
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index 9e33e6796..3c9d46246 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { isAbsolute, join } from 'path' | 1 | import { isAbsolute, join } from 'path' |
2 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
3 | import { makePostBodyRequest, makePostUploadRequest, makePutBodyRequest } from '../' | 3 | import { makePostBodyRequest, makeUploadRequest, makePutBodyRequest } from '../' |
4 | 4 | ||
5 | import { UserRole } from '../../../../shared/index' | 5 | import { UserRole } from '../../../../shared/index' |
6 | 6 | ||
@@ -162,7 +162,7 @@ function updateMyAvatar (options: { | |||
162 | filePath = join(__dirname, '..', '..', 'api', 'fixtures', options.fixture) | 162 | filePath = join(__dirname, '..', '..', 'api', 'fixtures', options.fixture) |
163 | } | 163 | } |
164 | 164 | ||
165 | return makePostUploadRequest({ | 165 | return makeUploadRequest({ |
166 | url: options.url, | 166 | url: options.url, |
167 | path, | 167 | path, |
168 | token: options.accessToken, | 168 | token: options.accessToken, |
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 9105b5f13..9d4267db8 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts | |||
@@ -5,7 +5,16 @@ import { existsSync, readFile } from 'fs' | |||
5 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
6 | import { extname, isAbsolute, join } from 'path' | 6 | import { extname, isAbsolute, join } from 'path' |
7 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
8 | import { getMyUserInformation, makeGetRequest, root, ServerInfo, testImage } from '../' | 8 | import { |
9 | buildAbsoluteFixturePath, | ||
10 | getMyUserInformation, | ||
11 | makeGetRequest, | ||
12 | makePutBodyRequest, | ||
13 | makeUploadRequest, | ||
14 | root, | ||
15 | ServerInfo, | ||
16 | testImage | ||
17 | } from '../' | ||
9 | import { VideoPrivacy } from '../../../../shared/models/videos' | 18 | import { VideoPrivacy } from '../../../../shared/models/videos' |
10 | import { readdirPromise } from '../../../helpers/core-utils' | 19 | import { readdirPromise } from '../../../helpers/core-utils' |
11 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' | 20 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' |
@@ -23,6 +32,8 @@ type VideoAttributes = { | |||
23 | channelId?: number | 32 | channelId?: number |
24 | privacy?: VideoPrivacy | 33 | privacy?: VideoPrivacy |
25 | fixture?: string | 34 | fixture?: string |
35 | thumbnailfile?: string | ||
36 | previewfile?: string | ||
26 | } | 37 | } |
27 | 38 | ||
28 | function getVideoCategories (url: string) { | 39 | function getVideoCategories (url: string) { |
@@ -228,8 +239,8 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
228 | defaultChannelId = res.body.videoChannels[0].id | 239 | defaultChannelId = res.body.videoChannels[0].id |
229 | } catch (e) { /* empty */ } | 240 | } catch (e) { /* empty */ } |
230 | 241 | ||
231 | // Default attributes | 242 | // Override default attributes |
232 | let attributes = { | 243 | const attributes = Object.assign({ |
233 | name: 'my super video', | 244 | name: 'my super video', |
234 | category: 5, | 245 | category: 5, |
235 | licence: 4, | 246 | licence: 4, |
@@ -241,8 +252,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
241 | privacy: VideoPrivacy.PUBLIC, | 252 | privacy: VideoPrivacy.PUBLIC, |
242 | commentsEnabled: true, | 253 | commentsEnabled: true, |
243 | fixture: 'video_short.webm' | 254 | fixture: 'video_short.webm' |
244 | } | 255 | }, videoAttributesArg) |
245 | attributes = Object.assign(attributes, videoAttributesArg) | ||
246 | 256 | ||
247 | const req = request(url) | 257 | const req = request(url) |
248 | .post(path) | 258 | .post(path) |
@@ -267,22 +277,22 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
267 | req.field('licence', attributes.licence.toString()) | 277 | req.field('licence', attributes.licence.toString()) |
268 | } | 278 | } |
269 | 279 | ||
270 | for (let i = 0; i < attributes.tags.length; i++) { | 280 | if (attributes.thumbnailfile !== undefined) { |
271 | req.field('tags[' + i + ']', attributes.tags[i]) | 281 | req.attach('thumbnailfile', buildAbsoluteFixturePath(attributes.thumbnailfile)) |
282 | } | ||
283 | if (attributes.previewfile !== undefined) { | ||
284 | req.attach('previewfile', buildAbsoluteFixturePath(attributes.previewfile)) | ||
272 | } | 285 | } |
273 | 286 | ||
274 | let filePath = '' | 287 | for (let i = 0; i < attributes.tags.length; i++) { |
275 | if (isAbsolute(attributes.fixture)) { | 288 | req.field('tags[' + i + ']', attributes.tags[i]) |
276 | filePath = attributes.fixture | ||
277 | } else { | ||
278 | filePath = join(__dirname, '..', '..', 'api', 'fixtures', attributes.fixture) | ||
279 | } | 289 | } |
280 | 290 | ||
281 | return req.attach('videofile', filePath) | 291 | return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) |
282 | .expect(specialStatus) | 292 | .expect(specialStatus) |
283 | } | 293 | } |
284 | 294 | ||
285 | function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, specialStatus = 204) { | 295 | function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, statusCodeExpected = 204) { |
286 | const path = '/api/v1/videos/' + id | 296 | const path = '/api/v1/videos/' + id |
287 | const body = {} | 297 | const body = {} |
288 | 298 | ||
@@ -296,12 +306,30 @@ function updateVideo (url: string, accessToken: string, id: number | string, att | |||
296 | if (attributes.tags) body['tags'] = attributes.tags | 306 | if (attributes.tags) body['tags'] = attributes.tags |
297 | if (attributes.privacy) body['privacy'] = attributes.privacy | 307 | if (attributes.privacy) body['privacy'] = attributes.privacy |
298 | 308 | ||
299 | return request(url) | 309 | // Upload request |
300 | .put(path) | 310 | if (attributes.thumbnailfile || attributes.previewfile) { |
301 | .send(body) | 311 | const attaches: any = {} |
302 | .set('Accept', 'application/json') | 312 | if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile |
303 | .set('Authorization', 'Bearer ' + accessToken) | 313 | if (attributes.previewfile) attaches.previewfile = attributes.previewfile |
304 | .expect(specialStatus) | 314 | |
315 | return makeUploadRequest({ | ||
316 | url, | ||
317 | method: 'PUT', | ||
318 | path, | ||
319 | token: accessToken, | ||
320 | fields: body, | ||
321 | attaches, | ||
322 | statusCodeExpected | ||
323 | }) | ||
324 | } | ||
325 | |||
326 | return makePutBodyRequest({ | ||
327 | url, | ||
328 | path, | ||
329 | fields: body, | ||
330 | token: accessToken, | ||
331 | statusCodeExpected | ||
332 | }) | ||
305 | } | 333 | } |
306 | 334 | ||
307 | function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { | 335 | function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { |
@@ -355,7 +383,9 @@ async function completeVideoCheck ( | |||
355 | files: { | 383 | files: { |
356 | resolution: number | 384 | resolution: number |
357 | size: number | 385 | size: number |
358 | }[] | 386 | }[], |
387 | thumbnailfile?: string | ||
388 | previewfile?: string | ||
359 | } | 389 | } |
360 | ) { | 390 | ) { |
361 | if (!attributes.likes) attributes.likes = 0 | 391 | if (!attributes.likes) attributes.likes = 0 |
@@ -414,8 +444,15 @@ async function completeVideoCheck ( | |||
414 | const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) | 444 | const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) |
415 | expect(file.size).to.be.above(minSize).and.below(maxSize) | 445 | expect(file.size).to.be.above(minSize).and.below(maxSize) |
416 | 446 | ||
417 | const test = await testImage(url, attributes.fixture, videoDetails.thumbnailPath) | 447 | { |
418 | expect(test).to.equal(true) | 448 | const test = await testImage(url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath) |
449 | expect(test).to.equal(true) | ||
450 | } | ||
451 | |||
452 | if (attributes.previewfile) { | ||
453 | const test = await testImage(url, attributes.previewfile, videoDetails.previewPath) | ||
454 | expect(test).to.equal(true) | ||
455 | } | ||
419 | 456 | ||
420 | const torrent = await webtorrentAdd(magnetUri, true) | 457 | const torrent = await webtorrentAdd(magnetUri, true) |
421 | expect(torrent.files).to.be.an('array') | 458 | expect(torrent.files).to.be.an('array') |