aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/activitypub.ts4
-rw-r--r--server/tests/api/check-params/users.ts16
-rw-r--r--server/tests/api/check-params/video-comments.ts35
-rw-r--r--server/tests/api/check-params/videos.ts22
-rw-r--r--server/tests/api/server/follows.ts1
-rw-r--r--server/tests/api/videos/multiple-servers.ts27
-rw-r--r--server/tests/api/videos/single-server.ts5
-rw-r--r--server/tests/utils/videos/videos.ts10
8 files changed, 107 insertions, 13 deletions
diff --git a/server/tests/activitypub.ts b/server/tests/activitypub.ts
index 94615c63f..c8884719d 100644
--- a/server/tests/activitypub.ts
+++ b/server/tests/activitypub.ts
@@ -20,11 +20,11 @@ describe('Test activitypub', function () {
20 }) 20 })
21 21
22 it('Should return the account object', async function () { 22 it('Should return the account object', async function () {
23 const res = await makeActivityPubGetRequest(server.url, '/account/root') 23 const res = await makeActivityPubGetRequest(server.url, '/accounts/root')
24 const object = res.body 24 const object = res.body
25 25
26 expect(object.type).to.equal('Person') 26 expect(object.type).to.equal('Person')
27 expect(object.id).to.equal('http://localhost:9001/account/root') 27 expect(object.id).to.equal('http://localhost:9001/accounts/root')
28 expect(object.name).to.equal('root') 28 expect(object.name).to.equal('root')
29 expect(object.preferredUsername).to.equal('root') 29 expect(object.preferredUsername).to.equal('root')
30 }) 30 })
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 44412ad82..33d92ac24 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -2,14 +2,13 @@
2 2
3import { omit } from 'lodash' 3import { omit } from 'lodash'
4import 'mocha' 4import 'mocha'
5import { join } from "path" 5import { join } from 'path'
6import { UserRole } from '../../../../shared' 6import { UserRole } from '../../../../shared'
7 7
8import { 8import {
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, makePostUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers,
11 updateUser, 11 updateUser, uploadVideo, userLogin
12 uploadVideo, userLogin
13} from '../../utils' 12} from '../../utils'
14import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 13import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
15 14
@@ -25,7 +24,7 @@ describe('Test users API validators', function () {
25 // --------------------------------------------------------------- 24 // ---------------------------------------------------------------
26 25
27 before(async function () { 26 before(async function () {
28 this.timeout(120000) 27 this.timeout(20000)
29 28
30 await flushTests() 29 await flushTests()
31 30
@@ -282,7 +281,14 @@ describe('Test users API validators', function () {
282 const attaches = { 281 const attaches = {
283 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar.png') 282 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar.png')
284 } 283 }
285 await makePostUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) 284 await makePostUploadRequest({
285 url: server.url,
286 path: path + '/me/avatar/pick',
287 token: server.accessToken,
288 fields,
289 attaches,
290 statusCodeExpected: 200
291 })
286 }) 292 })
287 }) 293 })
288 294
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index cdb48a276..c11660d07 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -1,5 +1,6 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as chai from 'chai'
3import 'mocha' 4import 'mocha'
4import { 5import {
5 flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, 6 flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
@@ -8,6 +9,8 @@ import {
8import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
9import { addVideoCommentThread } from '../../utils/videos/video-comments' 10import { addVideoCommentThread } from '../../utils/videos/video-comments'
10 11
12const expect = chai.expect
13
11describe('Test video comments API validator', function () { 14describe('Test video comments API validator', function () {
12 let pathThread: string 15 let pathThread: string
13 let pathComment: string 16 let pathComment: string
@@ -42,17 +45,14 @@ describe('Test video comments API validator', function () {
42 describe('When listing video comment threads', function () { 45 describe('When listing video comment threads', function () {
43 it('Should fail with a bad start pagination', async function () { 46 it('Should fail with a bad start pagination', async function () {
44 await checkBadStartPagination(server.url, pathThread, server.accessToken) 47 await checkBadStartPagination(server.url, pathThread, server.accessToken)
45
46 }) 48 })
47 49
48 it('Should fail with a bad count pagination', async function () { 50 it('Should fail with a bad count pagination', async function () {
49 await checkBadCountPagination(server.url, pathThread, server.accessToken) 51 await checkBadCountPagination(server.url, pathThread, server.accessToken)
50
51 }) 52 })
52 53
53 it('Should fail with an incorrect sort', async function () { 54 it('Should fail with an incorrect sort', async function () {
54 await checkBadSortPagination(server.url, pathThread, server.accessToken) 55 await checkBadSortPagination(server.url, pathThread, server.accessToken)
55
56 }) 56 })
57 57
58 it('Should fail with an incorrect video', async function () { 58 it('Should fail with an incorrect video', async function () {
@@ -185,6 +185,35 @@ describe('Test video comments API validator', function () {
185 }) 185 })
186 }) 186 })
187 187
188 describe('When a video has comments disabled', function () {
189 before(async function () {
190 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
191 videoUUID = res.body.video.uuid
192 pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
193 })
194
195 it('Should return an empty thread list', async function () {
196 const res = await makeGetRequest({
197 url: server.url,
198 path: pathThread,
199 statusCodeExpected: 200
200 })
201 expect(res.body.total).to.equal(0)
202 expect(res.body.data).to.have.lengthOf(0)
203 })
204
205 it('Should return an thread comments list')
206
207 it('Should return conflict on thread add', async function () {
208 const fields = {
209 text: 'super comment'
210 }
211 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 })
212 })
213
214 it('Should return conflict on comment thread add')
215 })
216
188 after(async function () { 217 after(async function () {
189 killallServers([ server ]) 218 killallServers([ server ])
190 219
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index b9484afc4..5c067dc96 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -100,6 +100,7 @@ describe('Test videos API validator', function () {
100 licence: 1, 100 licence: 1,
101 language: 6, 101 language: 6,
102 nsfw: false, 102 nsfw: false,
103 commentsEnabled: true,
103 description: 'my super description', 104 description: 'my super description',
104 tags: [ 'tag1', 'tag2' ], 105 tags: [ 'tag1', 'tag2' ],
105 privacy: VideoPrivacy.PUBLIC, 106 privacy: VideoPrivacy.PUBLIC,
@@ -162,6 +163,20 @@ describe('Test videos API validator', function () {
162 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 163 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
163 }) 164 })
164 165
166 it('Should fail without commentsEnabled attribute', async function () {
167 const fields = omit(baseCorrectParams, 'commentsEnabled')
168 const attaches = baseCorrectAttaches
169
170 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
171 })
172
173 it('Should fail with a bad commentsEnabled attribute', async function () {
174 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
175 const attaches = baseCorrectAttaches
176
177 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
178 })
179
165 it('Should fail with a long description', async function () { 180 it('Should fail with a long description', async function () {
166 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) 181 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
167 const attaches = baseCorrectAttaches 182 const attaches = baseCorrectAttaches
@@ -291,6 +306,7 @@ describe('Test videos API validator', function () {
291 licence: 2, 306 licence: 2,
292 language: 6, 307 language: 6,
293 nsfw: false, 308 nsfw: false,
309 commentsEnabled: false,
294 description: 'my super description', 310 description: 'my super description',
295 privacy: VideoPrivacy.PUBLIC, 311 privacy: VideoPrivacy.PUBLIC,
296 tags: [ 'tag1', 'tag2' ] 312 tags: [ 'tag1', 'tag2' ]
@@ -354,6 +370,12 @@ describe('Test videos API validator', function () {
354 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 370 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
355 }) 371 })
356 372
373 it('Should fail with a bad commentsEnabled attribute', async function () {
374 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
375
376 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
377 })
378
357 it('Should fail with a long description', async function () { 379 it('Should fail with a long description', async function () {
358 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) 380 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
359 381
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index fc9c5c3b6..e6dfd5f62 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -246,6 +246,7 @@ describe('Test follows', function () {
246 host: 'localhost:9003', 246 host: 'localhost:9003',
247 account: 'root', 247 account: 'root',
248 isLocal, 248 isLocal,
249 commentsEnabled: true,
249 duration: 5, 250 duration: 5,
250 tags: [ 'tag1', 'tag2', 'tag3' ], 251 tags: [ 'tag1', 'tag2', 'tag3' ],
251 privacy: VideoPrivacy.PUBLIC, 252 privacy: VideoPrivacy.PUBLIC,
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index abd051a30..b6dfe0d1b 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -93,6 +93,7 @@ describe('Test multiple servers', function () {
93 duration: 10, 93 duration: 10,
94 tags: [ 'tag1p1', 'tag2p1' ], 94 tags: [ 'tag1p1', 'tag2p1' ],
95 privacy: VideoPrivacy.PUBLIC, 95 privacy: VideoPrivacy.PUBLIC,
96 commentsEnabled: true,
96 channel: { 97 channel: {
97 name: 'my channel', 98 name: 'my channel',
98 description: 'super channel', 99 description: 'super channel',
@@ -155,6 +156,7 @@ describe('Test multiple servers', function () {
155 host: 'localhost:9002', 156 host: 'localhost:9002',
156 account: 'user1', 157 account: 'user1',
157 isLocal, 158 isLocal,
159 commentsEnabled: true,
158 duration: 5, 160 duration: 5,
159 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], 161 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
160 privacy: VideoPrivacy.PUBLIC, 162 privacy: VideoPrivacy.PUBLIC,
@@ -254,6 +256,7 @@ describe('Test multiple servers', function () {
254 account: 'root', 256 account: 'root',
255 isLocal, 257 isLocal,
256 duration: 5, 258 duration: 5,
259 commentsEnabled: true,
257 tags: [ 'tag1p3' ], 260 tags: [ 'tag1p3' ],
258 privacy: VideoPrivacy.PUBLIC, 261 privacy: VideoPrivacy.PUBLIC,
259 channel: { 262 channel: {
@@ -280,6 +283,7 @@ describe('Test multiple servers', function () {
280 description: 'my super description for server 3-2', 283 description: 'my super description for server 3-2',
281 host: 'localhost:9003', 284 host: 'localhost:9003',
282 account: 'root', 285 account: 'root',
286 commentsEnabled: true,
283 isLocal, 287 isLocal,
284 duration: 5, 288 duration: 5,
285 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], 289 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
@@ -545,6 +549,7 @@ describe('Test multiple servers', function () {
545 account: 'root', 549 account: 'root',
546 isLocal, 550 isLocal,
547 duration: 5, 551 duration: 5,
552 commentsEnabled: true,
548 tags: [ 'tag_up_1', 'tag_up_2' ], 553 tags: [ 'tag_up_1', 'tag_up_2' ],
549 privacy: VideoPrivacy.PUBLIC, 554 privacy: VideoPrivacy.PUBLIC,
550 channel: { 555 channel: {
@@ -732,6 +737,26 @@ describe('Test multiple servers', function () {
732 expect(secondChild.children).to.have.lengthOf(0) 737 expect(secondChild.children).to.have.lengthOf(0)
733 } 738 }
734 }) 739 })
740
741 it('Should disable comments', async function () {
742 this.timeout(20000)
743
744 const attributes = {
745 commentsEnabled: false
746 }
747
748 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes)
749
750 await wait(5000)
751
752 for (const server of servers) {
753 const res = await getVideo(server.url, videoUUID)
754 expect(res.body.commentsEnabled).to.be.false
755
756 const text = 'my super forbidden comment'
757 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409)
758 }
759 })
735 }) 760 })
736 761
737 describe('With minimum parameters', function () { 762 describe('With minimum parameters', function () {
@@ -748,6 +773,7 @@ describe('Test multiple servers', function () {
748 .field('privacy', '1') 773 .field('privacy', '1')
749 .field('nsfw', 'false') 774 .field('nsfw', 'false')
750 .field('channelId', '1') 775 .field('channelId', '1')
776 .field('commentsEnabled', 'true')
751 777
752 const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm') 778 const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm')
753 779
@@ -772,6 +798,7 @@ describe('Test multiple servers', function () {
772 account: 'root', 798 account: 'root',
773 isLocal, 799 isLocal,
774 duration: 5, 800 duration: 5,
801 commentsEnabled: true,
775 tags: [ ], 802 tags: [ ],
776 privacy: VideoPrivacy.PUBLIC, 803 privacy: VideoPrivacy.PUBLIC,
777 channel: { 804 channel: {
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index 2a3126f32..0a0c95750 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -32,6 +32,7 @@ describe('Test a single server', function () {
32 duration: 5, 32 duration: 5,
33 tags: [ 'tag1', 'tag2', 'tag3' ], 33 tags: [ 'tag1', 'tag2', 'tag3' ],
34 privacy: VideoPrivacy.PUBLIC, 34 privacy: VideoPrivacy.PUBLIC,
35 commentsEnabled: true,
35 channel: { 36 channel: {
36 name: 'Default root channel', 37 name: 'Default root channel',
37 description: '', 38 description: '',
@@ -51,7 +52,7 @@ describe('Test a single server', function () {
51 category: 4, 52 category: 4,
52 licence: 2, 53 licence: 2,
53 language: 5, 54 language: 5,
54 nsfw: true, 55 nsfw: false,
55 description: 'my super description updated', 56 description: 'my super description updated',
56 host: 'localhost:9001', 57 host: 'localhost:9001',
57 account: 'root', 58 account: 'root',
@@ -59,6 +60,7 @@ describe('Test a single server', function () {
59 tags: [ 'tagup1', 'tagup2' ], 60 tags: [ 'tagup1', 'tagup2' ],
60 privacy: VideoPrivacy.PUBLIC, 61 privacy: VideoPrivacy.PUBLIC,
61 duration: 5, 62 duration: 5,
63 commentsEnabled: false,
62 channel: { 64 channel: {
63 name: 'Default root channel', 65 name: 'Default root channel',
64 description: '', 66 description: '',
@@ -475,6 +477,7 @@ describe('Test a single server', function () {
475 language: 5, 477 language: 5,
476 nsfw: false, 478 nsfw: false,
477 description: 'my super description updated', 479 description: 'my super description updated',
480 commentsEnabled: false,
478 tags: [ 'tagup1', 'tagup2' ] 481 tags: [ 'tagup1', 'tagup2' ]
479 } 482 }
480 await updateVideo(server.url, server.accessToken, videoId, attributes) 483 await updateVideo(server.url, server.accessToken, videoId, attributes)
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index aca51ee5d..c437c21b2 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -16,6 +16,7 @@ type VideoAttributes = {
16 licence?: number 16 licence?: number
17 language?: number 17 language?: number
18 nsfw?: boolean 18 nsfw?: boolean
19 commentsEnabled?: boolean
19 description?: string 20 description?: string
20 tags?: string[] 21 tags?: string[]
21 channelId?: number 22 channelId?: number
@@ -238,6 +239,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
238 description: 'my super description', 239 description: 'my super description',
239 tags: [ 'tag' ], 240 tags: [ 'tag' ],
240 privacy: VideoPrivacy.PUBLIC, 241 privacy: VideoPrivacy.PUBLIC,
242 commentsEnabled: true,
241 fixture: 'video_short.webm' 243 fixture: 'video_short.webm'
242 } 244 }
243 attributes = Object.assign(attributes, videoAttributesArg) 245 attributes = Object.assign(attributes, videoAttributesArg)
@@ -250,6 +252,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
250 .field('category', attributes.category.toString()) 252 .field('category', attributes.category.toString())
251 .field('licence', attributes.licence.toString()) 253 .field('licence', attributes.licence.toString())
252 .field('nsfw', JSON.stringify(attributes.nsfw)) 254 .field('nsfw', JSON.stringify(attributes.nsfw))
255 .field('commentsEnabled', JSON.stringify(attributes.commentsEnabled))
253 .field('description', attributes.description) 256 .field('description', attributes.description)
254 .field('privacy', attributes.privacy.toString()) 257 .field('privacy', attributes.privacy.toString())
255 .field('channelId', attributes.channelId) 258 .field('channelId', attributes.channelId)
@@ -273,7 +276,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
273 .expect(specialStatus) 276 .expect(specialStatus)
274} 277}
275 278
276function updateVideo (url: string, accessToken: string, id: number, attributes: VideoAttributes, specialStatus = 204) { 279function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, specialStatus = 204) {
277 const path = '/api/v1/videos/' + id 280 const path = '/api/v1/videos/' + id
278 const body = {} 281 const body = {}
279 282
@@ -281,7 +284,8 @@ function updateVideo (url: string, accessToken: string, id: number, attributes:
281 if (attributes.category) body['category'] = attributes.category 284 if (attributes.category) body['category'] = attributes.category
282 if (attributes.licence) body['licence'] = attributes.licence 285 if (attributes.licence) body['licence'] = attributes.licence
283 if (attributes.language) body['language'] = attributes.language 286 if (attributes.language) body['language'] = attributes.language
284 if (attributes.nsfw) body['nsfw'] = attributes.nsfw 287 if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw)
288 if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled)
285 if (attributes.description) body['description'] = attributes.description 289 if (attributes.description) body['description'] = attributes.description
286 if (attributes.tags) body['tags'] = attributes.tags 290 if (attributes.tags) body['tags'] = attributes.tags
287 if (attributes.privacy) body['privacy'] = attributes.privacy 291 if (attributes.privacy) body['privacy'] = attributes.privacy
@@ -326,6 +330,7 @@ async function completeVideoCheck (
326 licence: number 330 licence: number
327 language: number 331 language: number
328 nsfw: boolean 332 nsfw: boolean
333 commentsEnabled: boolean
329 description: string 334 description: string
330 host: string 335 host: string
331 account: string 336 account: string
@@ -376,6 +381,7 @@ async function completeVideoCheck (
376 expect(videoDetails.privacy).to.deep.equal(attributes.privacy) 381 expect(videoDetails.privacy).to.deep.equal(attributes.privacy)
377 expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy]) 382 expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
378 expect(videoDetails.account.name).to.equal(attributes.account) 383 expect(videoDetails.account.name).to.equal(attributes.account)
384 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
379 385
380 expect(videoDetails.channel.name).to.equal(attributes.channel.name) 386 expect(videoDetails.channel.name).to.equal(attributes.channel.name)
381 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal) 387 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal)