aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/activitypub/cleaner.ts64
-rw-r--r--server/tests/api/activitypub/client.ts2
-rw-r--r--server/tests/api/activitypub/fetch.ts9
-rw-r--r--server/tests/api/activitypub/helpers.ts3
-rw-r--r--server/tests/api/activitypub/refresher.ts6
-rw-r--r--server/tests/api/activitypub/security.ts5
-rw-r--r--server/tests/api/check-params/abuses.ts8
-rw-r--r--server/tests/api/check-params/accounts.ts10
-rw-r--r--server/tests/api/check-params/blocklist.ts80
-rw-r--r--server/tests/api/check-params/bulk.ts2
-rw-r--r--server/tests/api/check-params/config.ts14
-rw-r--r--server/tests/api/check-params/contact-form.ts4
-rw-r--r--server/tests/api/check-params/custom-pages.ts2
-rw-r--r--server/tests/api/check-params/debug.ts2
-rw-r--r--server/tests/api/check-params/follows.ts8
-rw-r--r--server/tests/api/check-params/jobs.ts12
-rw-r--r--server/tests/api/check-params/live.ts6
-rw-r--r--server/tests/api/check-params/logs.ts2
-rw-r--r--server/tests/api/check-params/my-user.ts11
-rw-r--r--server/tests/api/check-params/plugins.ts10
-rw-r--r--server/tests/api/check-params/redundancy.ts8
-rw-r--r--server/tests/api/check-params/search.ts12
-rw-r--r--server/tests/api/check-params/services.ts2
-rw-r--r--server/tests/api/check-params/transcoding.ts11
-rw-r--r--server/tests/api/check-params/upload-quota.ts6
-rw-r--r--server/tests/api/check-params/user-notifications.ts12
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts6
-rw-r--r--server/tests/api/check-params/users-admin.ts9
-rw-r--r--server/tests/api/check-params/users.ts10
-rw-r--r--server/tests/api/check-params/video-blacklist.ts8
-rw-r--r--server/tests/api/check-params/video-captions.ts6
-rw-r--r--server/tests/api/check-params/video-channels.ts10
-rw-r--r--server/tests/api/check-params/video-comments.ts8
-rw-r--r--server/tests/api/check-params/video-files.ts9
-rw-r--r--server/tests/api/check-params/video-imports.ts11
-rw-r--r--server/tests/api/check-params/video-playlists.ts22
-rw-r--r--server/tests/api/check-params/videos-common-filters.ts2
-rw-r--r--server/tests/api/check-params/videos-history.ts7
-rw-r--r--server/tests/api/check-params/videos-overviews.ts2
-rw-r--r--server/tests/api/check-params/videos.ts12
-rw-r--r--server/tests/api/live/live-constraints.ts6
-rw-r--r--server/tests/api/live/live-permanent.ts6
-rw-r--r--server/tests/api/live/live-rtmps.ts4
-rw-r--r--server/tests/api/live/live-save-replay.ts8
-rw-r--r--server/tests/api/live/live-socket-messages.ts4
-rw-r--r--server/tests/api/live/live-views.ts4
-rw-r--r--server/tests/api/live/live.ts27
-rw-r--r--server/tests/api/moderation/abuses.ts2
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts9
-rw-r--r--server/tests/api/moderation/blocklist.ts109
-rw-r--r--server/tests/api/moderation/video-blacklist.ts6
-rw-r--r--server/tests/api/notifications/admin-notifications.ts9
-rw-r--r--server/tests/api/notifications/comments-notifications.ts8
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts96
-rw-r--r--server/tests/api/notifications/notifications-api.ts8
-rw-r--r--server/tests/api/notifications/user-notifications.ts16
-rw-r--r--server/tests/api/object-storage/live.ts8
-rw-r--r--server/tests/api/object-storage/video-imports.ts9
-rw-r--r--server/tests/api/object-storage/videos.ts11
-rw-r--r--server/tests/api/redundancy/manage-redundancy.ts2
-rw-r--r--server/tests/api/redundancy/redundancy-constraints.ts9
-rw-r--r--server/tests/api/redundancy/redundancy.ts41
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts6
-rw-r--r--server/tests/api/search/search-activitypub-video-playlists.ts6
-rw-r--r--server/tests/api/search/search-activitypub-videos.ts6
-rw-r--r--server/tests/api/search/search-channels.ts2
-rw-r--r--server/tests/api/search/search-index.ts2
-rw-r--r--server/tests/api/search/search-playlists.ts2
-rw-r--r--server/tests/api/search/search-videos.ts6
-rw-r--r--server/tests/api/server/auto-follows.ts12
-rw-r--r--server/tests/api/server/bulk.ts2
-rw-r--r--server/tests/api/server/config-defaults.ts213
-rw-r--r--server/tests/api/server/config.ts24
-rw-r--r--server/tests/api/server/contact-form.ts8
-rw-r--r--server/tests/api/server/email.ts5
-rw-r--r--server/tests/api/server/follow-constraints.ts4
-rw-r--r--server/tests/api/server/follows-moderation.ts2
-rw-r--r--server/tests/api/server/follows.ts18
-rw-r--r--server/tests/api/server/handle-down.ts10
-rw-r--r--server/tests/api/server/homepage.ts2
-rw-r--r--server/tests/api/server/index.ts2
-rw-r--r--server/tests/api/server/jobs.ts4
-rw-r--r--server/tests/api/server/logs.ts2
-rw-r--r--server/tests/api/server/no-client.ts2
-rw-r--r--server/tests/api/server/plugins.ts12
-rw-r--r--server/tests/api/server/proxy.ts11
-rw-r--r--server/tests/api/server/reverse-proxy.ts3
-rw-r--r--server/tests/api/server/services.ts2
-rw-r--r--server/tests/api/server/slow-follows.ts9
-rw-r--r--server/tests/api/server/stats.ts6
-rw-r--r--server/tests/api/server/tracker.ts2
-rw-r--r--server/tests/api/users/user-subscriptions.ts57
-rw-r--r--server/tests/api/users/users-multiple-servers.ts10
-rw-r--r--server/tests/api/users/users-verification.ts3
-rw-r--r--server/tests/api/users/users.ts30
-rw-r--r--server/tests/api/videos/audio-only.ts9
-rw-r--r--server/tests/api/videos/multiple-servers.ts37
-rw-r--r--server/tests/api/videos/resumable-upload.ts10
-rw-r--r--server/tests/api/videos/single-server.ts13
-rw-r--r--server/tests/api/videos/video-captions.ts7
-rw-r--r--server/tests/api/videos/video-change-ownership.ts2
-rw-r--r--server/tests/api/videos/video-channels.ts46
-rw-r--r--server/tests/api/videos/video-comments.ts11
-rw-r--r--server/tests/api/videos/video-create-transcoding.ts8
-rw-r--r--server/tests/api/videos/video-description.ts9
-rw-r--r--server/tests/api/videos/video-files.ts9
-rw-r--r--server/tests/api/videos/video-hls.ts13
-rw-r--r--server/tests/api/videos/video-imports.ts10
-rw-r--r--server/tests/api/videos/video-nsfw.ts2
-rw-r--r--server/tests/api/videos/video-playlist-thumbnails.ts6
-rw-r--r--server/tests/api/videos/video-playlists.ts25
-rw-r--r--server/tests/api/videos/video-privacy.ts6
-rw-r--r--server/tests/api/videos/video-schedule-update.ts6
-rw-r--r--server/tests/api/videos/video-transcoder.ts20
-rw-r--r--server/tests/api/videos/videos-common-filters.ts2
-rw-r--r--server/tests/api/videos/videos-history.ts8
-rw-r--r--server/tests/api/videos/videos-overview.ts3
-rw-r--r--server/tests/api/videos/videos-views-cleaner.ts4
-rw-r--r--server/tests/cli/create-import-video-file-job.ts8
-rw-r--r--server/tests/cli/create-move-video-storage-job.ts9
-rw-r--r--server/tests/cli/create-transcoding-job.ts6
-rw-r--r--server/tests/cli/peertube.ts27
-rw-r--r--server/tests/cli/plugins.ts2
-rw-r--r--server/tests/cli/print-transcode-command.ts3
-rw-r--r--server/tests/cli/prune-storage.ts57
-rw-r--r--server/tests/cli/regenerate-thumbnails.ts2
-rw-r--r--server/tests/cli/reset-password.ts2
-rw-r--r--server/tests/cli/update-host.ts2
-rw-r--r--server/tests/client.ts2
-rw-r--r--server/tests/external-plugins/auth-ldap.ts2
-rw-r--r--server/tests/external-plugins/auto-block-videos.ts10
-rw-r--r--server/tests/external-plugins/auto-mute.ts10
-rw-r--r--server/tests/feeds/feeds.ts9
-rw-r--r--server/tests/fixtures/peertube-plugin-test-four/main.js14
-rw-r--r--server/tests/fixtures/peertube-plugin-test-six/main.js5
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js25
-rw-r--r--server/tests/helpers/image.ts2
-rw-r--r--server/tests/helpers/request.ts4
-rw-r--r--server/tests/misc-endpoints.ts2
-rw-r--r--server/tests/plugins/action-hooks.ts16
-rw-r--r--server/tests/plugins/external-auth.ts10
-rw-r--r--server/tests/plugins/filter-hooks.ts75
-rw-r--r--server/tests/plugins/html-injection.ts2
-rw-r--r--server/tests/plugins/id-and-pass-auth.ts3
-rw-r--r--server/tests/plugins/plugin-helpers.ts73
-rw-r--r--server/tests/plugins/plugin-router.ts2
-rw-r--r--server/tests/plugins/plugin-storage.ts8
-rw-r--r--server/tests/plugins/plugin-transcoding.ts2
-rw-r--r--server/tests/plugins/plugin-unloading.ts2
-rw-r--r--server/tests/plugins/translations.ts2
-rw-r--r--server/tests/plugins/video-constants.ts2
-rw-r--r--server/tests/register.ts3
-rw-r--r--server/tests/shared/actors.ts73
-rw-r--r--server/tests/shared/captions.ts21
-rw-r--r--server/tests/shared/checks.ts98
-rw-r--r--server/tests/shared/directories.ts34
-rw-r--r--server/tests/shared/generate.ts74
-rw-r--r--server/tests/shared/index.ts15
-rw-r--r--server/tests/shared/live.ts41
-rw-r--r--server/tests/shared/mock-servers/index.ts7
-rw-r--r--server/tests/shared/mock-servers/mock-429.ts33
-rw-r--r--server/tests/shared/mock-servers/mock-email.ts62
-rw-r--r--server/tests/shared/mock-servers/mock-instances-index.ts46
-rw-r--r--server/tests/shared/mock-servers/mock-joinpeertube-versions.ts34
-rw-r--r--server/tests/shared/mock-servers/mock-object-storage.ts41
-rw-r--r--server/tests/shared/mock-servers/mock-plugin-blocklist.ts36
-rw-r--r--server/tests/shared/mock-servers/mock-proxy.ts24
-rw-r--r--server/tests/shared/mock-servers/shared.ts33
-rw-r--r--server/tests/shared/notifications.ts798
-rw-r--r--server/tests/shared/playlists.ts25
-rw-r--r--server/tests/shared/plugins.ts18
-rw-r--r--server/tests/shared/requests.ts41
-rw-r--r--server/tests/shared/streaming-playlists.ts77
-rw-r--r--server/tests/shared/tests.ts37
-rw-r--r--server/tests/shared/tracker.ts27
-rw-r--r--server/tests/shared/videos.ts251
176 files changed, 3302 insertions, 633 deletions
diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts
index 51cf6e599..d0a151f5c 100644
--- a/server/tests/api/activitypub/cleaner.ts
+++ b/server/tests/api/activitypub/cleaner.ts
@@ -2,15 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 createMultipleServers, 8 createMultipleServers,
8 doubleFollow, 9 doubleFollow,
9 PeerTubeServer, 10 PeerTubeServer,
10 setAccessTokensToServers, 11 setAccessTokensToServers,
11 wait,
12 waitJobs 12 waitJobs
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14 14
15const expect = chai.expect 15const expect = chai.expect
16 16
@@ -270,6 +270,66 @@ describe('Test AP cleaner', function () {
270 await checkRemote('kyle') 270 await checkRemote('kyle')
271 }) 271 })
272 272
273 it('Should remove unavailable remote resources', async function () {
274 this.timeout(240000)
275
276 async function expectNotDeleted () {
277 {
278 const video = await servers[0].videos.get({ id: uuid })
279
280 expect(video.likes).to.equal(3)
281 expect(video.dislikes).to.equal(0)
282 }
283
284 {
285 const { total } = await servers[0].comments.listThreads({ videoId: uuid })
286 expect(total).to.equal(3)
287 }
288 }
289
290 async function expectDeleted () {
291 {
292 const video = await servers[0].videos.get({ id: uuid })
293
294 expect(video.likes).to.equal(2)
295 expect(video.dislikes).to.equal(0)
296 }
297
298 {
299 const { total } = await servers[0].comments.listThreads({ videoId: uuid })
300 expect(total).to.equal(2)
301 }
302 }
303
304 const uuid = (await servers[0].videos.quickUpload({ name: 'server 1 video 2' })).uuid
305
306 await waitJobs(servers)
307
308 for (const server of servers) {
309 await server.videos.rate({ id: uuid, rating: 'like' })
310 await server.comments.createThread({ videoId: uuid, text: 'comment' })
311 }
312
313 await waitJobs(servers)
314
315 await expectNotDeleted()
316
317 await servers[1].kill()
318
319 await wait(5000)
320 await expectNotDeleted()
321
322 let continueWhile = true
323
324 do {
325 try {
326 await expectDeleted()
327 continueWhile = false
328 } catch {
329 }
330 } while (continueWhile)
331 })
332
273 after(async function () { 333 after(async function () {
274 await cleanupTests(servers) 334 await cleanupTests(servers)
275 }) 335 })
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts
index c3e4b7f74..e69ab3cb9 100644
--- a/server/tests/api/activitypub/client.ts
+++ b/server/tests/api/activitypub/client.ts
@@ -10,7 +10,7 @@ import {
10 PeerTubeServer, 10 PeerTubeServer,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 setDefaultVideoChannel 12 setDefaultVideoChannel
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' 14import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
index 422a75d6e..cc71e82ea 100644
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@ -2,7 +2,14 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12} from '@shared/server-commands'
6 13
7const expect = chai.expect 14const expect = chai.expect
8 15
diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts
index 57b1cab23..25e1d9823 100644
--- a/server/tests/api/activitypub/helpers.ts
+++ b/server/tests/api/activitypub/helpers.ts
@@ -3,7 +3,8 @@
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { cloneDeep } from 'lodash' 5import { cloneDeep } from 'lodash'
6import { buildAbsoluteFixturePath, buildRequestStub } from '@shared/extra-utils' 6import { buildRequestStub } from '@server/tests/shared'
7import { buildAbsoluteFixturePath } from '@shared/core-utils'
7import { buildSignedActivity } from '../../../helpers/activitypub' 8import { buildSignedActivity } from '../../../helpers/activitypub'
8import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' 9import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
9 10
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index 81fee0044..71e1c40ba 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -1,6 +1,8 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { wait } from '@shared/core-utils'
5import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
4import { 6import {
5 cleanupTests, 7 cleanupTests,
6 createMultipleServers, 8 createMultipleServers,
@@ -9,10 +11,8 @@ import {
9 PeerTubeServer, 11 PeerTubeServer,
10 setAccessTokensToServers, 12 setAccessTokensToServers,
11 setDefaultVideoChannel, 13 setDefaultVideoChannel,
12 wait,
13 waitJobs 14 waitJobs
14} from '@shared/extra-utils' 15} from '@shared/server-commands'
15import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
16 16
17describe('Test AP refresher', function () { 17describe('Test AP refresher', function () {
18 let servers: PeerTubeServer[] = [] 18 let servers: PeerTubeServer[] = []
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts
index 94d946563..c4cb5ea0d 100644
--- a/server/tests/api/activitypub/security.ts
+++ b/server/tests/api/activitypub/security.ts
@@ -6,9 +6,10 @@ import { activityPubContextify, buildSignedActivity } from '@server/helpers/acti
6import { buildDigest } from '@server/helpers/peertube-crypto' 6import { buildDigest } from '@server/helpers/peertube-crypto'
7import { HTTP_SIGNATURE } from '@server/initializers/constants' 7import { HTTP_SIGNATURE } from '@server/initializers/constants'
8import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils' 8import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils'
9import { buildAbsoluteFixturePath, cleanupTests, createMultipleServers, killallServers, PeerTubeServer, wait } from '@shared/extra-utils' 9import { makeFollowRequest, makePOSTAPRequest } from '@server/tests/shared'
10import { makeFollowRequest, makePOSTAPRequest } from '@shared/extra-utils/requests/activitypub' 10import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
11import { HttpStatusCode } from '@shared/models' 11import { HttpStatusCode } from '@shared/models'
12import { cleanupTests, createMultipleServers, killallServers, PeerTubeServer } from '@shared/server-commands'
12 13
13const expect = chai.expect 14const expect = chai.expect
14 15
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index fb9a5fd8b..c4b051723 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -1,11 +1,10 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models'
4import { 6import {
5 AbusesCommand, 7 AbusesCommand,
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
9 cleanupTests, 8 cleanupTests,
10 createSingleServer, 9 createSingleServer,
11 doubleFollow, 10 doubleFollow,
@@ -14,8 +13,7 @@ import {
14 PeerTubeServer, 13 PeerTubeServer,
15 setAccessTokensToServers, 14 setAccessTokensToServers,
16 waitJobs 15 waitJobs
17} from '@shared/extra-utils' 16} from '@shared/server-commands'
18import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models'
19 17
20describe('Test abuses API validators', function () { 18describe('Test abuses API validators', function () {
21 const basePath = '/api/v1/abuses/' 19 const basePath = '/api/v1/abuses/'
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts
index 141d869b7..07f879e0e 100644
--- a/server/tests/api/check-params/accounts.ts
+++ b/server/tests/api/check-params/accounts.ts
@@ -1,15 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { 4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests,
9 createSingleServer,
10 PeerTubeServer
11} from '@shared/extra-utils'
12import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands'
13 7
14describe('Test accounts API validators', function () { 8describe('Test accounts API validators', function () {
15 const path = '/api/v1/accounts/' 9 const path = '/api/v1/accounts/'
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts
index 7d5fae5cf..36526d494 100644
--- a/server/tests/api/check-params/blocklist.ts
+++ b/server/tests/api/check-params/blocklist.ts
@@ -1,10 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5import { HttpStatusCode } from '@shared/models'
4import { 6import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests, 7 cleanupTests,
9 createMultipleServers, 8 createMultipleServers,
10 doubleFollow, 9 doubleFollow,
@@ -13,8 +12,7 @@ import {
13 makePostBodyRequest, 12 makePostBodyRequest,
14 PeerTubeServer, 13 PeerTubeServer,
15 setAccessTokensToServers 14 setAccessTokensToServers
16} from '@shared/extra-utils' 15} from '@shared/server-commands'
17import { HttpStatusCode } from '@shared/models'
18 16
19describe('Test blocklist API validators', function () { 17describe('Test blocklist API validators', function () {
20 let servers: PeerTubeServer[] 18 let servers: PeerTubeServer[]
@@ -481,6 +479,78 @@ describe('Test blocklist API validators', function () {
481 }) 479 })
482 }) 480 })
483 481
482 describe('When getting blocklist status', function () {
483 const path = '/api/v1/blocklist/status'
484
485 it('Should fail with a bad token', async function () {
486 await makeGetRequest({
487 url: server.url,
488 path,
489 token: 'false',
490 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
491 })
492 })
493
494 it('Should fail with a bad accounts field', async function () {
495 await makeGetRequest({
496 url: server.url,
497 path,
498 query: {
499 accounts: 1
500 },
501 expectedStatus: HttpStatusCode.BAD_REQUEST_400
502 })
503
504 await makeGetRequest({
505 url: server.url,
506 path,
507 query: {
508 accounts: [ 1 ]
509 },
510 expectedStatus: HttpStatusCode.BAD_REQUEST_400
511 })
512 })
513
514 it('Should fail with a bad hosts field', async function () {
515 await makeGetRequest({
516 url: server.url,
517 path,
518 query: {
519 hosts: 1
520 },
521 expectedStatus: HttpStatusCode.BAD_REQUEST_400
522 })
523
524 await makeGetRequest({
525 url: server.url,
526 path,
527 query: {
528 hosts: [ 1 ]
529 },
530 expectedStatus: HttpStatusCode.BAD_REQUEST_400
531 })
532 })
533
534 it('Should succeed with the correct parameters', async function () {
535 await makeGetRequest({
536 url: server.url,
537 path,
538 query: {},
539 expectedStatus: HttpStatusCode.OK_200
540 })
541
542 await makeGetRequest({
543 url: server.url,
544 path,
545 query: {
546 hosts: [ 'example.com' ],
547 accounts: [ 'john@example.com' ]
548 },
549 expectedStatus: HttpStatusCode.OK_200
550 })
551 })
552 })
553
484 after(async function () { 554 after(async function () {
485 await cleanupTests(servers) 555 await cleanupTests(servers)
486 }) 556 })
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts
index bc9d7784d..9bd0016cf 100644
--- a/server/tests/api/check-params/bulk.ts
+++ b/server/tests/api/check-params/bulk.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 4import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6 6
7describe('Test bulk API validators', function () { 7describe('Test bulk API validators', function () {
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index d0cd7722b..3cccb612a 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -10,7 +10,7 @@ import {
10 makePutBodyRequest, 10 makePutBodyRequest,
11 PeerTubeServer, 11 PeerTubeServer,
12 setAccessTokensToServers 12 setAccessTokensToServers
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14import { CustomConfig, HttpStatusCode } from '@shared/models' 14import { CustomConfig, HttpStatusCode } from '@shared/models'
15 15
16describe('Test config API validators', function () { 16describe('Test config API validators', function () {
@@ -54,6 +54,18 @@ describe('Test config API validators', function () {
54 whitelisted: true 54 whitelisted: true
55 } 55 }
56 }, 56 },
57 client: {
58 videos: {
59 miniature: {
60 preferAuthorDisplayName: false
61 }
62 },
63 menu: {
64 login: {
65 redirectOnSingleExternalAuth: false
66 }
67 }
68 },
57 cache: { 69 cache: {
58 previews: { 70 previews: {
59 size: 2 71 size: 2
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts
index 9f86fecc6..9db442b0b 100644
--- a/server/tests/api/check-params/contact-form.ts
+++ b/server/tests/api/check-params/contact-form.ts
@@ -1,9 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createSingleServer, killallServers, MockSmtpServer, PeerTubeServer } from '@shared/extra-utils' 4import { MockSmtpServer } from '@server/tests/shared'
5import { ContactFormCommand } from '@shared/extra-utils/server'
6import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, ContactFormCommand, createSingleServer, killallServers, PeerTubeServer } from '@shared/server-commands'
7 7
8describe('Test contact form API validators', function () { 8describe('Test contact form API validators', function () {
9 let server: PeerTubeServer 9 let server: PeerTubeServer
diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts
index 9fbbea315..a102ee437 100644
--- a/server/tests/api/check-params/custom-pages.ts
+++ b/server/tests/api/check-params/custom-pages.ts
@@ -8,7 +8,7 @@ import {
8 makePutBodyRequest, 8 makePutBodyRequest,
9 PeerTubeServer, 9 PeerTubeServer,
10 setAccessTokensToServers 10 setAccessTokensToServers
11} from '@shared/extra-utils' 11} from '@shared/server-commands'
12import { HttpStatusCode } from '@shared/models' 12import { HttpStatusCode } from '@shared/models'
13 13
14describe('Test custom pages validators', function () { 14describe('Test custom pages validators', function () {
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
index a55786359..cfa44deca 100644
--- a/server/tests/api/check-params/debug.ts
+++ b/server/tests/api/check-params/debug.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 4import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6 6
7describe('Test debug API validators', function () { 7describe('Test debug API validators', function () {
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 2bc9f6b96..d4dae5a75 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -1,10 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5import { HttpStatusCode } from '@shared/models'
4import { 6import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests, 7 cleanupTests,
9 createSingleServer, 8 createSingleServer,
10 makeDeleteRequest, 9 makeDeleteRequest,
@@ -12,8 +11,7 @@ import {
12 makePostBodyRequest, 11 makePostBodyRequest,
13 PeerTubeServer, 12 PeerTubeServer,
14 setAccessTokensToServers 13 setAccessTokensToServers
15} from '@shared/extra-utils' 14} from '@shared/server-commands'
16import { HttpStatusCode } from '@shared/models'
17 15
18describe('Test server follows API validators', function () { 16describe('Test server follows API validators', function () {
19 let server: PeerTubeServer 17 let server: PeerTubeServer
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index 23d95d8e4..d85961d62 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -1,17 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { 4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests,
9 createSingleServer,
10 makeGetRequest,
11 PeerTubeServer,
12 setAccessTokensToServers
13} from '@shared/extra-utils'
14import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
15 7
16describe('Test jobs API validators', function () { 8describe('Test jobs API validators', function () {
17 const path = '/api/v1/jobs/failed' 9 const path = '/api/v1/jobs/failed'
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 8e1d655d4..8aee6164c 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { buildAbsoluteFixturePath } from '@shared/core-utils'
6import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
5import { 7import {
6 buildAbsoluteFixturePath,
7 cleanupTests, 8 cleanupTests,
8 createSingleServer, 9 createSingleServer,
9 LiveCommand, 10 LiveCommand,
@@ -13,8 +14,7 @@ import {
13 sendRTMPStream, 14 sendRTMPStream,
14 setAccessTokensToServers, 15 setAccessTokensToServers,
15 stopFfmpeg 16 stopFfmpeg
16} from '@shared/extra-utils' 17} from '@shared/server-commands'
17import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
18 18
19describe('Test video lives API validator', function () { 19describe('Test video lives API validator', function () {
20 const path = '/api/v1/videos/live' 20 const path = '/api/v1/videos/live'
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
index 05372257a..970671c15 100644
--- a/server/tests/api/check-params/logs.ts
+++ b/server/tests/api/check-params/logs.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 4import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6 6
7describe('Test logs API validators', function () { 7describe('Test logs API validators', function () {
diff --git a/server/tests/api/check-params/my-user.ts b/server/tests/api/check-params/my-user.ts
index d35284d60..95f2122ae 100644
--- a/server/tests/api/check-params/my-user.ts
+++ b/server/tests/api/check-params/my-user.ts
@@ -1,22 +1,19 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, MockSmtpServer } from '@server/tests/shared'
5import { buildAbsoluteFixturePath } from '@shared/core-utils'
6import { HttpStatusCode, UserRole, VideoCreateResult } from '@shared/models'
4import { 7import {
5 buildAbsoluteFixturePath,
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
9 cleanupTests, 8 cleanupTests,
10 createSingleServer, 9 createSingleServer,
11 makeGetRequest, 10 makeGetRequest,
12 makePutBodyRequest, 11 makePutBodyRequest,
13 makeUploadRequest, 12 makeUploadRequest,
14 MockSmtpServer,
15 PeerTubeServer, 13 PeerTubeServer,
16 setAccessTokensToServers, 14 setAccessTokensToServers,
17 UsersCommand 15 UsersCommand
18} from '@shared/extra-utils' 16} from '@shared/server-commands'
19import { HttpStatusCode, UserRole, VideoCreateResult } from '@shared/models'
20 17
21describe('Test my user API validators', function () { 18describe('Test my user API validators', function () {
22 const path = '/api/v1/users/' 19 const path = '/api/v1/users/'
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index 33f84ecbc..c3f15b86e 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -1,10 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5import { HttpStatusCode, PeerTubePlugin, PluginType } from '@shared/models'
4import { 6import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests, 7 cleanupTests,
9 createSingleServer, 8 createSingleServer,
10 makeGetRequest, 9 makeGetRequest,
@@ -12,8 +11,7 @@ import {
12 makePutBodyRequest, 11 makePutBodyRequest,
13 PeerTubeServer, 12 PeerTubeServer,
14 setAccessTokensToServers 13 setAccessTokensToServers
15} from '@shared/extra-utils' 14} from '@shared/server-commands'
16import { HttpStatusCode, PeerTubePlugin, PluginType } from '@shared/models'
17 15
18describe('Test server plugins API validators', function () { 16describe('Test server plugins API validators', function () {
19 let server: PeerTubeServer 17 let server: PeerTubeServer
@@ -30,7 +28,7 @@ describe('Test server plugins API validators', function () {
30 // --------------------------------------------------------------- 28 // ---------------------------------------------------------------
31 29
32 before(async function () { 30 before(async function () {
33 this.timeout(30000) 31 this.timeout(60000)
34 32
35 server = await createSingleServer(1) 33 server = await createSingleServer(1)
36 34
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index d9f905549..04519cf23 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -1,10 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5import { HttpStatusCode, VideoCreateResult } from '@shared/models'
4import { 6import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests, 7 cleanupTests,
9 createMultipleServers, 8 createMultipleServers,
10 doubleFollow, 9 doubleFollow,
@@ -15,8 +14,7 @@ import {
15 PeerTubeServer, 14 PeerTubeServer,
16 setAccessTokensToServers, 15 setAccessTokensToServers,
17 waitJobs 16 waitJobs
18} from '@shared/extra-utils' 17} from '@shared/server-commands'
19import { HttpStatusCode, VideoCreateResult } from '@shared/models'
20 18
21describe('Test server redundancy API validators', function () { 19describe('Test server redundancy API validators', function () {
22 let servers: PeerTubeServer[] 20 let servers: PeerTubeServer[]
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
index cc15d2593..ca0fbf31d 100644
--- a/server/tests/api/check-params/search.ts
+++ b/server/tests/api/check-params/search.ts
@@ -1,17 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { 4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests,
9 createSingleServer,
10 makeGetRequest,
11 PeerTubeServer,
12 setAccessTokensToServers
13} from '@shared/extra-utils'
14import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
15 7
16function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) { 8function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) {
17 return server.config.updateCustomSubConfig({ 9 return server.config.updateCustomSubConfig({
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
index 8d795fabc..e63f09884 100644
--- a/server/tests/api/check-params/services.ts
+++ b/server/tests/api/check-params/services.ts
@@ -8,7 +8,7 @@ import {
8 PeerTubeServer, 8 PeerTubeServer,
9 setAccessTokensToServers, 9 setAccessTokensToServers,
10 setDefaultVideoChannel 10 setDefaultVideoChannel
11} from '@shared/extra-utils' 11} from '@shared/server-commands'
12import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' 12import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
13 13
14describe('Test services API validators', function () { 14describe('Test services API validators', function () {
diff --git a/server/tests/api/check-params/transcoding.ts b/server/tests/api/check-params/transcoding.ts
index a8daafe3e..333012940 100644
--- a/server/tests/api/check-params/transcoding.ts
+++ b/server/tests/api/check-params/transcoding.ts
@@ -1,8 +1,15 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
5import { HttpStatusCode, UserRole } from '@shared/models' 4import { HttpStatusCode, UserRole } from '@shared/models'
5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12} from '@shared/server-commands'
6 13
7describe('Test transcoding API validators', function () { 14describe('Test transcoding API validators', function () {
8 let servers: PeerTubeServer[] 15 let servers: PeerTubeServer[]
@@ -16,7 +23,7 @@ describe('Test transcoding API validators', function () {
16 // --------------------------------------------------------------- 23 // ---------------------------------------------------------------
17 24
18 before(async function () { 25 before(async function () {
19 this.timeout(60000) 26 this.timeout(120000)
20 27
21 servers = await createMultipleServers(2) 28 servers = await createMultipleServers(2)
22 await setAccessTokensToServers(servers) 29 await setAccessTokensToServers(servers)
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts
index 322e93d0d..deb4a7aa3 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -2,18 +2,18 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { FIXTURE_URLS } from '@server/tests/shared'
5import { randomInt } from '@shared/core-utils' 6import { randomInt } from '@shared/core-utils'
7import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models'
6import { 8import {
7 cleanupTests, 9 cleanupTests,
8 createSingleServer, 10 createSingleServer,
9 FIXTURE_URLS,
10 PeerTubeServer, 11 PeerTubeServer,
11 setAccessTokensToServers, 12 setAccessTokensToServers,
12 setDefaultVideoChannel, 13 setDefaultVideoChannel,
13 VideosCommand, 14 VideosCommand,
14 waitJobs 15 waitJobs
15} from '@shared/extra-utils' 16} from '@shared/server-commands'
16import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models'
17 17
18describe('Test upload quota', function () { 18describe('Test upload quota', function () {
19 let server: PeerTubeServer 19 let server: PeerTubeServer
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 17edf5aa1..4bc8084a1 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -2,20 +2,18 @@
2 2
3import 'mocha' 3import 'mocha'
4import { io } from 'socket.io-client' 4import { io } from 'socket.io-client'
5import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
6import { wait } from '@shared/core-utils'
7import { HttpStatusCode, UserNotificationSetting, UserNotificationSettingValue } from '@shared/models'
5import { 8import {
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
9 cleanupTests, 9 cleanupTests,
10 createSingleServer, 10 createSingleServer,
11 makeGetRequest, 11 makeGetRequest,
12 makePostBodyRequest, 12 makePostBodyRequest,
13 makePutBodyRequest, 13 makePutBodyRequest,
14 PeerTubeServer, 14 PeerTubeServer,
15 setAccessTokensToServers, 15 setAccessTokensToServers
16 wait 16} from '@shared/server-commands'
17} from '@shared/extra-utils'
18import { HttpStatusCode, UserNotificationSetting, UserNotificationSettingValue } from '@shared/models'
19 17
20describe('Test user notifications API validators', function () { 18describe('Test user notifications API validators', function () {
21 let server: PeerTubeServer 19 let server: PeerTubeServer
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 624069c80..a13ed5aa3 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -2,9 +2,6 @@
2 2
3import 'mocha' 3import 'mocha'
4import { 4import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests, 5 cleanupTests,
9 createSingleServer, 6 createSingleServer,
10 makeDeleteRequest, 7 makeDeleteRequest,
@@ -13,8 +10,9 @@ import {
13 PeerTubeServer, 10 PeerTubeServer,
14 setAccessTokensToServers, 11 setAccessTokensToServers,
15 waitJobs 12 waitJobs
16} from '@shared/extra-utils' 13} from '@shared/server-commands'
17import { HttpStatusCode } from '@shared/models' 14import { HttpStatusCode } from '@shared/models'
15import { checkBadStartPagination, checkBadCountPagination, checkBadSortPagination } from '@server/tests/shared'
18 16
19describe('Test user subscriptions API validators', function () { 17describe('Test user subscriptions API validators', function () {
20 const path = '/api/v1/users/me/subscriptions' 18 const path = '/api/v1/users/me/subscriptions'
diff --git a/server/tests/api/check-params/users-admin.ts b/server/tests/api/check-params/users-admin.ts
index f71414a6b..d8353f83b 100644
--- a/server/tests/api/check-params/users-admin.ts
+++ b/server/tests/api/check-params/users-admin.ts
@@ -2,21 +2,18 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, MockSmtpServer } from '@server/tests/shared'
6import { HttpStatusCode, UserAdminFlag, UserRole } from '@shared/models'
5import { 7import {
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
9 cleanupTests, 8 cleanupTests,
10 createSingleServer, 9 createSingleServer,
11 killallServers, 10 killallServers,
12 makeGetRequest, 11 makeGetRequest,
13 makePostBodyRequest, 12 makePostBodyRequest,
14 makePutBodyRequest, 13 makePutBodyRequest,
15 MockSmtpServer,
16 PeerTubeServer, 14 PeerTubeServer,
17 setAccessTokensToServers 15 setAccessTokensToServers
18} from '@shared/extra-utils' 16} from '@shared/server-commands'
19import { HttpStatusCode, UserAdminFlag, UserRole } from '@shared/models'
20 17
21describe('Test users admin API validators', function () { 18describe('Test users admin API validators', function () {
22 const path = '/api/v1/users/' 19 const path = '/api/v1/users/'
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 5f9cbc5eb..84254945c 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -2,15 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { 5import { MockSmtpServer } from '@server/tests/shared'
6 cleanupTests,
7 createSingleServer,
8 makePostBodyRequest,
9 MockSmtpServer,
10 PeerTubeServer,
11 setAccessTokensToServers
12} from '@shared/extra-utils'
13import { HttpStatusCode, UserRole } from '@shared/models' 6import { HttpStatusCode, UserRole } from '@shared/models'
7import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
14 8
15describe('Test users API validators', function () { 9describe('Test users API validators', function () {
16 const path = '/api/v1/users/' 10 const path = '/api/v1/users/'
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 1f926d227..1aab60826 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -2,11 +2,10 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
6import { HttpStatusCode, VideoBlacklistType } from '@shared/models'
5import { 7import {
6 BlacklistCommand, 8 BlacklistCommand,
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination,
10 cleanupTests, 9 cleanupTests,
11 createMultipleServers, 10 createMultipleServers,
12 doubleFollow, 11 doubleFollow,
@@ -15,8 +14,7 @@ import {
15 PeerTubeServer, 14 PeerTubeServer,
16 setAccessTokensToServers, 15 setAccessTokensToServers,
17 waitJobs 16 waitJobs
18} from '@shared/extra-utils' 17} from '@shared/server-commands'
19import { HttpStatusCode, VideoBlacklistType } from '@shared/models'
20 18
21describe('Test video blacklist API validators', function () { 19describe('Test video blacklist API validators', function () {
22 let servers: PeerTubeServer[] 20 let servers: PeerTubeServer[]
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index 84c6c1355..9881df80c 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -1,8 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { buildAbsoluteFixturePath } from '@shared/core-utils'
5import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
4import { 6import {
5 buildAbsoluteFixturePath,
6 cleanupTests, 7 cleanupTests,
7 createSingleServer, 8 createSingleServer,
8 makeDeleteRequest, 9 makeDeleteRequest,
@@ -10,8 +11,7 @@ import {
10 makeUploadRequest, 11 makeUploadRequest,
11 PeerTubeServer, 12 PeerTubeServer,
12 setAccessTokensToServers 13 setAccessTokensToServers
13} from '@shared/extra-utils' 14} from '@shared/server-commands'
14import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
15 15
16describe('Test video captions API validator', function () { 16describe('Test video captions API validator', function () {
17 const path = '/api/v1/videos/' 17 const path = '/api/v1/videos/'
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index e86c315fa..1e9732fe9 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -3,12 +3,11 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
7import { buildAbsoluteFixturePath } from '@shared/core-utils'
8import { HttpStatusCode, VideoChannelUpdate } from '@shared/models'
6import { 9import {
7 buildAbsoluteFixturePath,
8 ChannelsCommand, 10 ChannelsCommand,
9 checkBadCountPagination,
10 checkBadSortPagination,
11 checkBadStartPagination,
12 cleanupTests, 11 cleanupTests,
13 createSingleServer, 12 createSingleServer,
14 makeGetRequest, 13 makeGetRequest,
@@ -17,8 +16,7 @@ import {
17 makeUploadRequest, 16 makeUploadRequest,
18 PeerTubeServer, 17 PeerTubeServer,
19 setAccessTokensToServers 18 setAccessTokensToServers
20} from '@shared/extra-utils' 19} from '@shared/server-commands'
21import { HttpStatusCode, VideoChannelUpdate } from '@shared/models'
22 20
23const expect = chai.expect 21const expect = chai.expect
24 22
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index 2d9ee1e0d..63c3582e9 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -2,10 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
6import { HttpStatusCode, VideoCreateResult } from '@shared/models'
5import { 7import {
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
9 cleanupTests, 8 cleanupTests,
10 createSingleServer, 9 createSingleServer,
11 makeDeleteRequest, 10 makeDeleteRequest,
@@ -13,8 +12,7 @@ import {
13 makePostBodyRequest, 12 makePostBodyRequest,
14 PeerTubeServer, 13 PeerTubeServer,
15 setAccessTokensToServers 14 setAccessTokensToServers
16} from '@shared/extra-utils' 15} from '@shared/server-commands'
17import { HttpStatusCode, VideoCreateResult } from '@shared/models'
18 16
19const expect = chai.expect 17const expect = chai.expect
20 18
diff --git a/server/tests/api/check-params/video-files.ts b/server/tests/api/check-params/video-files.ts
index 3ccdf5f49..8c0795092 100644
--- a/server/tests/api/check-params/video-files.ts
+++ b/server/tests/api/check-params/video-files.ts
@@ -1,8 +1,15 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
5import { HttpStatusCode, UserRole } from '@shared/models' 4import { HttpStatusCode, UserRole } from '@shared/models'
5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12} from '@shared/server-commands'
6 13
7describe('Test videos files', function () { 14describe('Test videos files', function () {
8 let servers: PeerTubeServer[] 15 let servers: PeerTubeServer[]
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 6c31daa9b..da05793a0 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -2,21 +2,18 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, FIXTURE_URLS } from '@server/tests/shared'
6import { buildAbsoluteFixturePath } from '@shared/core-utils'
7import { HttpStatusCode, VideoPrivacy } from '@shared/models'
5import { 8import {
6 buildAbsoluteFixturePath,
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination,
10 cleanupTests, 9 cleanupTests,
11 createSingleServer, 10 createSingleServer,
12 FIXTURE_URLS,
13 makeGetRequest, 11 makeGetRequest,
14 makePostBodyRequest, 12 makePostBodyRequest,
15 makeUploadRequest, 13 makeUploadRequest,
16 PeerTubeServer, 14 PeerTubeServer,
17 setAccessTokensToServers 15 setAccessTokensToServers
18} from '@shared/extra-utils' 16} from '@shared/server-commands'
19import { HttpStatusCode, VideoPrivacy } from '@shared/models'
20 17
21describe('Test video imports API validator', function () { 18describe('Test video imports API validator', function () {
22 const path = '/api/v1/videos/imports' 19 const path = '/api/v1/videos/imports'
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index e4d541b48..4b17ce7db 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -1,18 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { 4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
8 cleanupTests,
9 createSingleServer,
10 makeGetRequest,
11 PeerTubeServer,
12 PlaylistsCommand,
13 setAccessTokensToServers,
14 setDefaultVideoChannel
15} from '@shared/extra-utils'
16import { 5import {
17 HttpStatusCode, 6 HttpStatusCode,
18 VideoPlaylistCreate, 7 VideoPlaylistCreate,
@@ -23,6 +12,15 @@ import {
23 VideoPlaylistReorder, 12 VideoPlaylistReorder,
24 VideoPlaylistType 13 VideoPlaylistType
25} from '@shared/models' 14} from '@shared/models'
15import {
16 cleanupTests,
17 createSingleServer,
18 makeGetRequest,
19 PeerTubeServer,
20 PlaylistsCommand,
21 setAccessTokensToServers,
22 setDefaultVideoChannel
23} from '@shared/server-commands'
26 24
27describe('Test video playlists API validator', function () { 25describe('Test video playlists API validator', function () {
28 let server: PeerTubeServer 26 let server: PeerTubeServer
diff --git a/server/tests/api/check-params/videos-common-filters.ts b/server/tests/api/check-params/videos-common-filters.ts
index f2b5bee8e..6b3ec917e 100644
--- a/server/tests/api/check-params/videos-common-filters.ts
+++ b/server/tests/api/check-params/videos-common-filters.ts
@@ -8,7 +8,7 @@ import {
8 PeerTubeServer, 8 PeerTubeServer,
9 setAccessTokensToServers, 9 setAccessTokensToServers,
10 setDefaultVideoChannel 10 setDefaultVideoChannel
11} from '@shared/extra-utils' 11} from '@shared/server-commands'
12import { HttpStatusCode, UserRole, VideoInclude, VideoPrivacy } from '@shared/models' 12import { HttpStatusCode, UserRole, VideoInclude, VideoPrivacy } from '@shared/models'
13 13
14describe('Test video filters validators', function () { 14describe('Test video filters validators', function () {
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts
index c3c309ed2..31a0752c7 100644
--- a/server/tests/api/check-params/videos-history.ts
+++ b/server/tests/api/check-params/videos-history.ts
@@ -1,9 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { checkBadCountPagination, checkBadStartPagination } from '@server/tests/shared'
5import { HttpStatusCode } from '@shared/models'
4import { 6import {
5 checkBadCountPagination,
6 checkBadStartPagination,
7 cleanupTests, 7 cleanupTests,
8 createSingleServer, 8 createSingleServer,
9 makeGetRequest, 9 makeGetRequest,
@@ -11,8 +11,7 @@ import {
11 makePutBodyRequest, 11 makePutBodyRequest,
12 PeerTubeServer, 12 PeerTubeServer,
13 setAccessTokensToServers 13 setAccessTokensToServers
14} from '@shared/extra-utils' 14} from '@shared/server-commands'
15import { HttpStatusCode } from '@shared/models'
16 15
17describe('Test videos history API validator', function () { 16describe('Test videos history API validator', function () {
18 const myHistoryPath = '/api/v1/users/me/history/videos' 17 const myHistoryPath = '/api/v1/users/me/history/videos'
diff --git a/server/tests/api/check-params/videos-overviews.ts b/server/tests/api/check-params/videos-overviews.ts
index c2139d74b..1da15dc43 100644
--- a/server/tests/api/check-params/videos-overviews.ts
+++ b/server/tests/api/check-params/videos-overviews.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/extra-utils' 4import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands'
5 5
6describe('Test videos overview', function () { 6describe('Test videos overview', function () {
7 let server: PeerTubeServer 7 let server: PeerTubeServer
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index d02b6e156..4cc70f5cc 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -4,12 +4,10 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { join } from 'path' 6import { join } from 'path'
7import { randomInt } from '@shared/core-utils' 7import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, checkUploadVideoParam } from '@server/tests/shared'
8import { randomInt, root } from '@shared/core-utils'
9import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models'
8import { 10import {
9 checkBadCountPagination,
10 checkBadSortPagination,
11 checkBadStartPagination,
12 checkUploadVideoParam,
13 cleanupTests, 11 cleanupTests,
14 createSingleServer, 12 createSingleServer,
15 makeDeleteRequest, 13 makeDeleteRequest,
@@ -17,10 +15,8 @@ import {
17 makePutBodyRequest, 15 makePutBodyRequest,
18 makeUploadRequest, 16 makeUploadRequest,
19 PeerTubeServer, 17 PeerTubeServer,
20 root,
21 setAccessTokensToServers 18 setAccessTokensToServers
22} from '@shared/extra-utils' 19} from '@shared/server-commands'
23import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models'
24 20
25const expect = chai.expect 21const expect = chai.expect
26 22
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts
index 6a6a11796..909399836 100644
--- a/server/tests/api/live/live-constraints.ts
+++ b/server/tests/api/live/live-constraints.ts
@@ -2,9 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
5import { VideoPrivacy } from '@shared/models' 6import { VideoPrivacy } from '@shared/models'
6import { 7import {
7 checkLiveCleanupAfterSave,
8 cleanupTests, 8 cleanupTests,
9 ConfigCommand, 9 ConfigCommand,
10 createMultipleServers, 10 createMultipleServers,
@@ -12,9 +12,9 @@ import {
12 PeerTubeServer, 12 PeerTubeServer,
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 setDefaultVideoChannel, 14 setDefaultVideoChannel,
15 wait,
16 waitJobs 15 waitJobs
17} from '../../../../shared/extra-utils' 16} from '@shared/server-commands'
17import { checkLiveCleanupAfterSave } from '../../shared'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts
index c5f942901..3e6fec453 100644
--- a/server/tests/api/live/live-permanent.ts
+++ b/server/tests/api/live/live-permanent.ts
@@ -2,6 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
5import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' 6import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
6import { 7import {
7 cleanupTests, 8 cleanupTests,
@@ -12,9 +13,8 @@ import {
12 setAccessTokensToServers, 13 setAccessTokensToServers,
13 setDefaultVideoChannel, 14 setDefaultVideoChannel,
14 stopFfmpeg, 15 stopFfmpeg,
15 wait,
16 waitJobs 16 waitJobs
17} from '../../../../shared/extra-utils' 17} from '@shared/server-commands'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
@@ -140,7 +140,7 @@ describe('Permanent live', function () {
140 }) 140 })
141 141
142 it('Should be able to stream again in the permanent live', async function () { 142 it('Should be able to stream again in the permanent live', async function () {
143 this.timeout(20000) 143 this.timeout(60000)
144 144
145 await servers[0].config.updateCustomSubConfig({ 145 await servers[0].config.updateCustomSubConfig({
146 newConfig: { 146 newConfig: {
diff --git a/server/tests/api/live/live-rtmps.ts b/server/tests/api/live/live-rtmps.ts
index 378e6df3c..935061971 100644
--- a/server/tests/api/live/live-rtmps.ts
+++ b/server/tests/api/live/live-rtmps.ts
@@ -2,9 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { buildAbsoluteFixturePath } from '@shared/core-utils'
5import { VideoPrivacy } from '@shared/models' 6import { VideoPrivacy } from '@shared/models'
6import { 7import {
7 buildAbsoluteFixturePath,
8 cleanupTests, 8 cleanupTests,
9 createSingleServer, 9 createSingleServer,
10 PeerTubeServer, 10 PeerTubeServer,
@@ -14,7 +14,7 @@ import {
14 stopFfmpeg, 14 stopFfmpeg,
15 testFfmpegStreamError, 15 testFfmpegStreamError,
16 waitUntilLivePublishedOnAllServers 16 waitUntilLivePublishedOnAllServers
17} from '../../../../shared/extra-utils' 17} from '@shared/server-commands'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts
index 6c4ea90ca..95a342b01 100644
--- a/server/tests/api/live/live-save-replay.ts
+++ b/server/tests/api/live/live-save-replay.ts
@@ -3,8 +3,10 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg' 5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { checkLiveCleanupAfterSave } from '@server/tests/shared'
7import { wait } from '@shared/core-utils'
8import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
6import { 9import {
7 checkLiveCleanupAfterSave,
8 cleanupTests, 10 cleanupTests,
9 ConfigCommand, 11 ConfigCommand,
10 createMultipleServers, 12 createMultipleServers,
@@ -14,12 +16,10 @@ import {
14 setDefaultVideoChannel, 16 setDefaultVideoChannel,
15 stopFfmpeg, 17 stopFfmpeg,
16 testFfmpegStreamError, 18 testFfmpegStreamError,
17 wait,
18 waitJobs, 19 waitJobs,
19 waitUntilLivePublishedOnAllServers, 20 waitUntilLivePublishedOnAllServers,
20 waitUntilLiveSavedOnAllServers 21 waitUntilLiveSavedOnAllServers
21} from '@shared/extra-utils' 22} from '@shared/server-commands'
22import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
23 23
24const expect = chai.expect 24const expect = chai.expect
25 25
diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts
index 33ee2c051..50b16443e 100644
--- a/server/tests/api/live/live-socket-messages.ts
+++ b/server/tests/api/live/live-socket-messages.ts
@@ -2,6 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
5import { VideoPrivacy, VideoState } from '@shared/models' 6import { VideoPrivacy, VideoState } from '@shared/models'
6import { 7import {
7 cleanupTests, 8 cleanupTests,
@@ -11,10 +12,9 @@ import {
11 setAccessTokensToServers, 12 setAccessTokensToServers,
12 setDefaultVideoChannel, 13 setDefaultVideoChannel,
13 stopFfmpeg, 14 stopFfmpeg,
14 wait,
15 waitJobs, 15 waitJobs,
16 waitUntilLivePublishedOnAllServers 16 waitUntilLivePublishedOnAllServers
17} from '../../../../shared/extra-utils' 17} from '@shared/server-commands'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts
index 9186af8e7..446d0913c 100644
--- a/server/tests/api/live/live-views.ts
+++ b/server/tests/api/live/live-views.ts
@@ -3,6 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg' 5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { wait } from '@shared/core-utils'
6import { VideoPrivacy } from '@shared/models' 7import { VideoPrivacy } from '@shared/models'
7import { 8import {
8 cleanupTests, 9 cleanupTests,
@@ -12,10 +13,9 @@ import {
12 setAccessTokensToServers, 13 setAccessTokensToServers,
13 setDefaultVideoChannel, 14 setDefaultVideoChannel,
14 stopFfmpeg, 15 stopFfmpeg,
15 wait,
16 waitJobs, 16 waitJobs,
17 waitUntilLivePublishedOnAllServers 17 waitUntilLivePublishedOnAllServers
18} from '../../../../shared/extra-utils' 18} from '@shared/server-commands'
19 19
20const expect = chai.expect 20const expect = chai.expect
21 21
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts
index b96c03cf8..3f9355d2d 100644
--- a/server/tests/api/live/live.ts
+++ b/server/tests/api/live/live.ts
@@ -4,10 +4,18 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { basename, join } from 'path' 5import { basename, join } from 'path'
6import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' 6import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
7import { checkLiveCleanupAfterSave, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, testImage } from '@server/tests/shared'
8import { wait } from '@shared/core-utils'
9import {
10 HttpStatusCode,
11 LiveVideo,
12 LiveVideoCreate,
13 VideoDetails,
14 VideoPrivacy,
15 VideoState,
16 VideoStreamingPlaylistType
17} from '@shared/models'
7import { 18import {
8 checkLiveCleanupAfterSave,
9 checkLiveSegmentHash,
10 checkResolutionsInMasterPlaylist,
11 cleanupTests, 19 cleanupTests,
12 createMultipleServers, 20 createMultipleServers,
13 doubleFollow, 21 doubleFollow,
@@ -20,20 +28,9 @@ import {
20 setDefaultVideoChannel, 28 setDefaultVideoChannel,
21 stopFfmpeg, 29 stopFfmpeg,
22 testFfmpegStreamError, 30 testFfmpegStreamError,
23 testImage,
24 wait,
25 waitJobs, 31 waitJobs,
26 waitUntilLivePublishedOnAllServers 32 waitUntilLivePublishedOnAllServers
27} from '@shared/extra-utils' 33} from '@shared/server-commands'
28import {
29 HttpStatusCode,
30 LiveVideo,
31 LiveVideoCreate,
32 VideoDetails,
33 VideoPrivacy,
34 VideoState,
35 VideoStreamingPlaylistType
36} from '@shared/models'
37 34
38const expect = chai.expect 35const expect = chai.expect
39 36
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index c258414ce..9eb84fdec 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -10,7 +10,7 @@ import {
10 PeerTubeServer, 10 PeerTubeServer,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 waitJobs 12 waitJobs
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' 14import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index 75b15c298..87d147998 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -2,8 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6import { UserNotificationType } from '@shared/models' 5import { UserNotificationType } from '@shared/models'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13} from '@shared/server-commands'
7 14
8const expect = chai.expect 15const expect = chai.expect
9 16
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index 089af8b15..b45460bb4 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -11,7 +11,7 @@ import {
11 PeerTubeServer, 11 PeerTubeServer,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 waitJobs 13 waitJobs
14} from '@shared/extra-utils' 14} from '@shared/server-commands'
15import { UserNotificationType } from '@shared/models' 15import { UserNotificationType } from '@shared/models'
16 16
17const expect = chai.expect 17const expect = chai.expect
@@ -254,6 +254,45 @@ describe('Test blocklist', function () {
254 } 254 }
255 }) 255 })
256 256
257 it('Should get blocked status', async function () {
258 const remoteHandle = 'user2@' + servers[1].host
259 const localHandle = 'user1@' + servers[0].host
260 const unknownHandle = 'user5@' + servers[0].host
261
262 {
263 const status = await command.getStatus({ accounts: [ remoteHandle ] })
264 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
265 expect(status.accounts[remoteHandle].blockedByUser).to.be.false
266 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
267
268 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
269 }
270
271 {
272 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] })
273 expect(Object.keys(status.accounts)).to.have.lengthOf(1)
274 expect(status.accounts[remoteHandle].blockedByUser).to.be.true
275 expect(status.accounts[remoteHandle].blockedByServer).to.be.false
276
277 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
278 }
279
280 {
281 const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
282 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
283
284 for (const handle of [ localHandle, remoteHandle ]) {
285 expect(status.accounts[handle].blockedByUser).to.be.true
286 expect(status.accounts[handle].blockedByServer).to.be.false
287 }
288
289 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
290 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
291
292 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
293 }
294 })
295
257 it('Should not allow a remote blocked user to comment my videos', async function () { 296 it('Should not allow a remote blocked user to comment my videos', async function () {
258 this.timeout(60000) 297 this.timeout(60000)
259 298
@@ -434,6 +473,35 @@ describe('Test blocklist', function () {
434 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) 473 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
435 }) 474 })
436 475
476 it('Should get blocklist status', async function () {
477 const blockedServer = servers[1].host
478 const notBlockedServer = 'example.com'
479
480 {
481 const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
482 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
483
484 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
485 expect(status.hosts[blockedServer].blockedByUser).to.be.false
486 expect(status.hosts[blockedServer].blockedByServer).to.be.false
487
488 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
489 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
490 }
491
492 {
493 const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
494 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
495
496 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
497 expect(status.hosts[blockedServer].blockedByUser).to.be.true
498 expect(status.hosts[blockedServer].blockedByServer).to.be.false
499
500 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
501 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
502 }
503 })
504
437 it('Should unblock the remote server', async function () { 505 it('Should unblock the remote server', async function () {
438 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port }) 506 await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port })
439 }) 507 })
@@ -575,6 +643,27 @@ describe('Test blocklist', function () {
575 } 643 }
576 }) 644 })
577 645
646 it('Should get blocked status', async function () {
647 const remoteHandle = 'user2@' + servers[1].host
648 const localHandle = 'user1@' + servers[0].host
649 const unknownHandle = 'user5@' + servers[0].host
650
651 for (const token of [ undefined, servers[0].accessToken ]) {
652 const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] })
653 expect(Object.keys(status.accounts)).to.have.lengthOf(3)
654
655 for (const handle of [ localHandle, remoteHandle ]) {
656 expect(status.accounts[handle].blockedByUser).to.be.false
657 expect(status.accounts[handle].blockedByServer).to.be.true
658 }
659
660 expect(status.accounts[unknownHandle].blockedByUser).to.be.false
661 expect(status.accounts[unknownHandle].blockedByServer).to.be.false
662
663 expect(Object.keys(status.hosts)).to.have.lengthOf(0)
664 }
665 })
666
578 it('Should unblock the remote account', async function () { 667 it('Should unblock the remote account', async function () {
579 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) 668 await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port })
580 }) 669 })
@@ -620,6 +709,7 @@ describe('Test blocklist', function () {
620 }) 709 })
621 710
622 describe('When managing server blocklist', function () { 711 describe('When managing server blocklist', function () {
712
623 it('Should list all videos', async function () { 713 it('Should list all videos', async function () {
624 for (const token of [ userModeratorToken, servers[0].accessToken ]) { 714 for (const token of [ userModeratorToken, servers[0].accessToken ]) {
625 await checkAllVideos(servers[0], token) 715 await checkAllVideos(servers[0], token)
@@ -713,6 +803,23 @@ describe('Test blocklist', function () {
713 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) 803 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
714 }) 804 })
715 805
806 it('Should get blocklist status', async function () {
807 const blockedServer = servers[1].host
808 const notBlockedServer = 'example.com'
809
810 for (const token of [ undefined, servers[0].accessToken ]) {
811 const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] })
812 expect(Object.keys(status.accounts)).to.have.lengthOf(0)
813
814 expect(Object.keys(status.hosts)).to.have.lengthOf(2)
815 expect(status.hosts[blockedServer].blockedByUser).to.be.false
816 expect(status.hosts[blockedServer].blockedByServer).to.be.true
817
818 expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
819 expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
820 }
821 })
822
716 it('Should unblock the remote server', async function () { 823 it('Should unblock the remote server', async function () {
717 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) 824 await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port })
718 }) 825 })
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index d5838191a..322e93815 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -3,18 +3,18 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { orderBy } from 'lodash' 5import { orderBy } from 'lodash'
6import { FIXTURE_URLS } from '@server/tests/shared'
7import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
6import { 8import {
7 BlacklistCommand, 9 BlacklistCommand,
8 cleanupTests, 10 cleanupTests,
9 createMultipleServers, 11 createMultipleServers,
10 doubleFollow, 12 doubleFollow,
11 FIXTURE_URLS,
12 killallServers, 13 killallServers,
13 PeerTubeServer, 14 PeerTubeServer,
14 setAccessTokensToServers, 15 setAccessTokensToServers,
15 waitJobs 16 waitJobs
16} from '@shared/extra-utils' 17} from '@shared/server-commands'
17import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts
index c00d4e257..f037e7aae 100644
--- a/server/tests/api/notifications/admin-notifications.ts
+++ b/server/tests/api/notifications/admin-notifications.ts
@@ -6,14 +6,13 @@ import {
6 CheckerBaseParams, 6 CheckerBaseParams,
7 checkNewPeerTubeVersion, 7 checkNewPeerTubeVersion,
8 checkNewPluginVersion, 8 checkNewPluginVersion,
9 cleanupTests,
10 MockJoinPeerTubeVersions, 9 MockJoinPeerTubeVersions,
11 MockSmtpServer, 10 MockSmtpServer,
12 PeerTubeServer, 11 prepareNotificationsTest
13 prepareNotificationsTest, 12} from '@server/tests/shared'
14 wait 13import { wait } from '@shared/core-utils'
15} from '@shared/extra-utils'
16import { PluginType, UserNotification, UserNotificationType } from '@shared/models' 14import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
15import { cleanupTests, PeerTubeServer } from '@shared/server-commands'
17 16
18describe('Test admin notifications', function () { 17describe('Test admin notifications', function () {
19 let server: PeerTubeServer 18 let server: PeerTubeServer
diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts
index 7cbb21397..b82f1712a 100644
--- a/server/tests/api/notifications/comments-notifications.ts
+++ b/server/tests/api/notifications/comments-notifications.ts
@@ -6,13 +6,11 @@ import {
6 checkCommentMention, 6 checkCommentMention,
7 CheckerBaseParams, 7 CheckerBaseParams,
8 checkNewCommentOnMyVideo, 8 checkNewCommentOnMyVideo,
9 cleanupTests,
10 MockSmtpServer, 9 MockSmtpServer,
11 PeerTubeServer, 10 prepareNotificationsTest
12 prepareNotificationsTest, 11} from '@server/tests/shared'
13 waitJobs
14} from '@shared/extra-utils'
15import { UserNotification } from '@shared/models' 12import { UserNotification } from '@shared/models'
13import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
16 14
17const expect = chai.expect 15const expect = chai.expect
18 16
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index f806fed31..9e330bd61 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -1,7 +1,6 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { buildUUID } from '@server/helpers/uuid'
5import { 4import {
6 checkAbuseStateChange, 5 checkAbuseStateChange,
7 checkAutoInstanceFollowing, 6 checkAutoInstanceFollowing,
@@ -16,19 +15,20 @@ import {
16 checkUserRegistered, 15 checkUserRegistered,
17 checkVideoAutoBlacklistForModerators, 16 checkVideoAutoBlacklistForModerators,
18 checkVideoIsPublished, 17 checkVideoIsPublished,
19 cleanupTests,
20 MockInstancesIndex, 18 MockInstancesIndex,
21 MockSmtpServer, 19 MockSmtpServer,
22 PeerTubeServer, 20 prepareNotificationsTest
23 prepareNotificationsTest, 21} from '@server/tests/shared'
24 wait, 22import { wait } from '@shared/core-utils'
25 waitJobs 23import { buildUUID } from '@shared/extra-utils'
26} from '@shared/extra-utils' 24import { AbuseState, CustomConfig, UserNotification, UserRole, VideoPrivacy } from '@shared/models'
27import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' 25import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
28 26
29describe('Test moderation notifications', function () { 27describe('Test moderation notifications', function () {
30 let servers: PeerTubeServer[] = [] 28 let servers: PeerTubeServer[] = []
31 let userAccessToken: string 29 let userToken1: string
30 let userToken2: string
31
32 let userNotifications: UserNotification[] = [] 32 let userNotifications: UserNotification[] = []
33 let adminNotifications: UserNotification[] = [] 33 let adminNotifications: UserNotification[] = []
34 let adminNotificationsServer2: UserNotification[] = [] 34 let adminNotificationsServer2: UserNotification[] = []
@@ -39,11 +39,13 @@ describe('Test moderation notifications', function () {
39 39
40 const res = await prepareNotificationsTest(3) 40 const res = await prepareNotificationsTest(3)
41 emails = res.emails 41 emails = res.emails
42 userAccessToken = res.userAccessToken 42 userToken1 = res.userAccessToken
43 servers = res.servers 43 servers = res.servers
44 userNotifications = res.userNotifications 44 userNotifications = res.userNotifications
45 adminNotifications = res.adminNotifications 45 adminNotifications = res.adminNotifications
46 adminNotificationsServer2 = res.adminNotificationsServer2 46 adminNotificationsServer2 = res.adminNotificationsServer2
47
48 userToken2 = await servers[1].users.generateUserAndToken('user2', UserRole.USER)
47 }) 49 })
48 50
49 describe('Abuse for moderators notification', function () { 51 describe('Abuse for moderators notification', function () {
@@ -58,15 +60,27 @@ describe('Test moderation notifications', function () {
58 } 60 }
59 }) 61 })
60 62
61 it('Should send a notification to moderators on local video abuse', async function () { 63 it('Should not send a notification to moderators on local abuse reported by an admin', async function () {
62 this.timeout(20000) 64 this.timeout(20000)
63 65
64 const name = 'video for abuse ' + buildUUID() 66 const name = 'video for abuse ' + buildUUID()
65 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 67 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
66 68
67 await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) 69 await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' })
68 70
69 await waitJobs(servers) 71 await waitJobs(servers)
72 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'absence' })
73 })
74
75 it('Should send a notification to moderators on local video abuse', async function () {
76 this.timeout(20000)
77
78 const name = 'video for abuse ' + buildUUID()
79 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
80
81 await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
82
83 await waitJobs(servers)
70 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) 84 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
71 }) 85 })
72 86
@@ -74,12 +88,12 @@ describe('Test moderation notifications', function () {
74 this.timeout(20000) 88 this.timeout(20000)
75 89
76 const name = 'video for abuse ' + buildUUID() 90 const name = 'video for abuse ' + buildUUID()
77 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 91 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
78 92
79 await waitJobs(servers) 93 await waitJobs(servers)
80 94
81 const videoId = await servers[1].videos.getId({ uuid: video.uuid }) 95 const videoId = await servers[1].videos.getId({ uuid: video.uuid })
82 await servers[1].abuses.report({ videoId, reason: 'super reason' }) 96 await servers[1].abuses.report({ token: userToken2, videoId, reason: 'super reason' })
83 97
84 await waitJobs(servers) 98 await waitJobs(servers)
85 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) 99 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
@@ -89,16 +103,16 @@ describe('Test moderation notifications', function () {
89 this.timeout(20000) 103 this.timeout(20000)
90 104
91 const name = 'video for abuse ' + buildUUID() 105 const name = 'video for abuse ' + buildUUID()
92 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 106 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
93 const comment = await servers[0].comments.createThread({ 107 const comment = await servers[0].comments.createThread({
94 token: userAccessToken, 108 token: userToken1,
95 videoId: video.id, 109 videoId: video.id,
96 text: 'comment abuse ' + buildUUID() 110 text: 'comment abuse ' + buildUUID()
97 }) 111 })
98 112
99 await waitJobs(servers) 113 await waitJobs(servers)
100 114
101 await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) 115 await servers[0].abuses.report({ token: userToken1, commentId: comment.id, reason: 'super reason' })
102 116
103 await waitJobs(servers) 117 await waitJobs(servers)
104 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) 118 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
@@ -108,10 +122,10 @@ describe('Test moderation notifications', function () {
108 this.timeout(20000) 122 this.timeout(20000)
109 123
110 const name = 'video for abuse ' + buildUUID() 124 const name = 'video for abuse ' + buildUUID()
111 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 125 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
112 126
113 await servers[0].comments.createThread({ 127 await servers[0].comments.createThread({
114 token: userAccessToken, 128 token: userToken1,
115 videoId: video.id, 129 videoId: video.id,
116 text: 'comment abuse ' + buildUUID() 130 text: 'comment abuse ' + buildUUID()
117 }) 131 })
@@ -120,7 +134,7 @@ describe('Test moderation notifications', function () {
120 134
121 const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) 135 const { data } = await servers[1].comments.listThreads({ videoId: video.uuid })
122 const commentId = data[0].id 136 const commentId = data[0].id
123 await servers[1].abuses.report({ commentId, reason: 'super reason' }) 137 await servers[1].abuses.report({ token: userToken2, commentId, reason: 'super reason' })
124 138
125 await waitJobs(servers) 139 await waitJobs(servers)
126 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) 140 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
@@ -133,7 +147,7 @@ describe('Test moderation notifications', function () {
133 const { account } = await servers[0].users.create({ username, password: 'donald' }) 147 const { account } = await servers[0].users.create({ username, password: 'donald' })
134 const accountId = account.id 148 const accountId = account.id
135 149
136 await servers[0].abuses.report({ accountId, reason: 'super reason' }) 150 await servers[0].abuses.report({ token: userToken1, accountId, reason: 'super reason' })
137 151
138 await waitJobs(servers) 152 await waitJobs(servers)
139 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) 153 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
@@ -149,7 +163,7 @@ describe('Test moderation notifications', function () {
149 await waitJobs(servers) 163 await waitJobs(servers)
150 164
151 const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) 165 const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host })
152 await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) 166 await servers[1].abuses.report({ token: userToken2, accountId: account.id, reason: 'super reason' })
153 167
154 await waitJobs(servers) 168 await waitJobs(servers)
155 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) 169 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
@@ -165,13 +179,13 @@ describe('Test moderation notifications', function () {
165 server: servers[0], 179 server: servers[0],
166 emails, 180 emails,
167 socketNotifications: userNotifications, 181 socketNotifications: userNotifications,
168 token: userAccessToken 182 token: userToken1
169 } 183 }
170 184
171 const name = 'abuse ' + buildUUID() 185 const name = 'abuse ' + buildUUID()
172 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 186 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
173 187
174 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) 188 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
175 abuseId = body.abuse.id 189 abuseId = body.abuse.id
176 }) 190 })
177 191
@@ -205,7 +219,7 @@ describe('Test moderation notifications', function () {
205 server: servers[0], 219 server: servers[0],
206 emails, 220 emails,
207 socketNotifications: userNotifications, 221 socketNotifications: userNotifications,
208 token: userAccessToken 222 token: userToken1
209 } 223 }
210 224
211 baseParamsAdmin = { 225 baseParamsAdmin = {
@@ -216,15 +230,15 @@ describe('Test moderation notifications', function () {
216 } 230 }
217 231
218 const name = 'abuse ' + buildUUID() 232 const name = 'abuse ' + buildUUID()
219 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 233 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
220 234
221 { 235 {
222 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) 236 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
223 abuseId = body.abuse.id 237 abuseId = body.abuse.id
224 } 238 }
225 239
226 { 240 {
227 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) 241 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason 2' })
228 abuseId2 = body.abuse.id 242 abuseId2 = body.abuse.id
229 } 243 }
230 }) 244 })
@@ -254,7 +268,7 @@ describe('Test moderation notifications', function () {
254 this.timeout(10000) 268 this.timeout(10000)
255 269
256 const message = 'my super message to moderators' 270 const message = 'my super message to moderators'
257 await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) 271 await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message })
258 await waitJobs(servers) 272 await waitJobs(servers)
259 273
260 const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' 274 const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com'
@@ -265,7 +279,7 @@ describe('Test moderation notifications', function () {
265 this.timeout(10000) 279 this.timeout(10000)
266 280
267 const message = 'my super message that should not be sent to reporter' 281 const message = 'my super message that should not be sent to reporter'
268 await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) 282 await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message })
269 await waitJobs(servers) 283 await waitJobs(servers)
270 284
271 const toEmail = 'user_1@example.com' 285 const toEmail = 'user_1@example.com'
@@ -281,7 +295,7 @@ describe('Test moderation notifications', function () {
281 server: servers[0], 295 server: servers[0],
282 emails, 296 emails,
283 socketNotifications: userNotifications, 297 socketNotifications: userNotifications,
284 token: userAccessToken 298 token: userToken1
285 } 299 }
286 }) 300 })
287 301
@@ -289,7 +303,7 @@ describe('Test moderation notifications', function () {
289 this.timeout(10000) 303 this.timeout(10000)
290 304
291 const name = 'video for abuse ' + buildUUID() 305 const name = 'video for abuse ' + buildUUID()
292 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 306 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
293 307
294 await servers[0].blacklist.add({ videoId: uuid }) 308 await servers[0].blacklist.add({ videoId: uuid })
295 309
@@ -301,7 +315,7 @@ describe('Test moderation notifications', function () {
301 this.timeout(10000) 315 this.timeout(10000)
302 316
303 const name = 'video for abuse ' + buildUUID() 317 const name = 'video for abuse ' + buildUUID()
304 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 318 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
305 319
306 await servers[0].blacklist.add({ videoId: uuid }) 320 await servers[0].blacklist.add({ videoId: uuid })
307 321
@@ -335,7 +349,7 @@ describe('Test moderation notifications', function () {
335 349
336 await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) 350 await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' })
337 351
338 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 352 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
339 await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) 353 await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' })
340 }) 354 })
341 }) 355 })
@@ -377,7 +391,7 @@ describe('Test moderation notifications', function () {
377 391
378 await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) 392 await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' })
379 393
380 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 394 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
381 await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) 395 await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' })
382 }) 396 })
383 397
@@ -404,7 +418,7 @@ describe('Test moderation notifications', function () {
404 const followingHost = servers[2].host 418 const followingHost = servers[2].host
405 await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) 419 await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' })
406 420
407 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 421 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
408 await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) 422 await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' })
409 423
410 config.followings.instance.autoFollowBack.enabled = false 424 config.followings.instance.autoFollowBack.enabled = false
@@ -461,7 +475,7 @@ describe('Test moderation notifications', function () {
461 server: servers[0], 475 server: servers[0],
462 emails, 476 emails,
463 socketNotifications: userNotifications, 477 socketNotifications: userNotifications,
464 token: userAccessToken 478 token: userToken1
465 } 479 }
466 480
467 currentCustomConfig = await servers[0].config.getCustomConfig() 481 currentCustomConfig = await servers[0].config.getCustomConfig()
@@ -490,7 +504,7 @@ describe('Test moderation notifications', function () {
490 this.timeout(120000) 504 this.timeout(120000)
491 505
492 videoName = 'video with auto-blacklist ' + buildUUID() 506 videoName = 'video with auto-blacklist ' + buildUUID()
493 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) 507 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name: videoName } })
494 shortUUID = video.shortUUID 508 shortUUID = video.shortUUID
495 uuid = video.uuid 509 uuid = video.uuid
496 510
@@ -547,7 +561,7 @@ describe('Test moderation notifications', function () {
547 } 561 }
548 } 562 }
549 563
550 const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) 564 const { shortUUID, uuid } = await servers[0].videos.upload({ token: userToken1, attributes })
551 565
552 await servers[0].blacklist.remove({ videoId: uuid }) 566 await servers[0].blacklist.remove({ videoId: uuid })
553 567
@@ -579,7 +593,7 @@ describe('Test moderation notifications', function () {
579 } 593 }
580 } 594 }
581 595
582 const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes }) 596 const { shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes })
583 597
584 await wait(6000) 598 await wait(6000)
585 await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) 599 await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' })
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index a529a9bf7..ac08449f8 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -5,14 +5,12 @@ import * as chai from 'chai'
5import { 5import {
6 CheckerBaseParams, 6 CheckerBaseParams,
7 checkNewVideoFromSubscription, 7 checkNewVideoFromSubscription,
8 cleanupTests,
9 getAllNotificationsSettings, 8 getAllNotificationsSettings,
10 MockSmtpServer, 9 MockSmtpServer,
11 PeerTubeServer, 10 prepareNotificationsTest
12 prepareNotificationsTest, 11} from '@server/tests/shared'
13 waitJobs
14} from '@shared/extra-utils'
15import { UserNotification, UserNotificationSettingValue } from '@shared/models' 12import { UserNotification, UserNotificationSettingValue } from '@shared/models'
13import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
16 14
17const expect = chai.expect 15const expect = chai.expect
18 16
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 468efdf35..f9f3e0e0e 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -2,23 +2,21 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { buildUUID } from '@server/helpers/uuid'
6import { 5import {
7 CheckerBaseParams, 6 CheckerBaseParams,
8 checkMyVideoImportIsFinished, 7 checkMyVideoImportIsFinished,
9 checkNewActorFollow, 8 checkNewActorFollow,
10 checkNewVideoFromSubscription, 9 checkNewVideoFromSubscription,
11 checkVideoIsPublished, 10 checkVideoIsPublished,
12 cleanupTests,
13 FIXTURE_URLS, 11 FIXTURE_URLS,
14 MockSmtpServer, 12 MockSmtpServer,
15 PeerTubeServer,
16 prepareNotificationsTest, 13 prepareNotificationsTest,
17 uploadRandomVideoOnServers, 14 uploadRandomVideoOnServers
18 wait, 15} from '@server/tests/shared'
19 waitJobs 16import { wait } from '@shared/core-utils'
20} from '@shared/extra-utils' 17import { buildUUID } from '@shared/extra-utils'
21import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' 18import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
19import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
22 20
23const expect = chai.expect 21const expect = chai.expect
24 22
@@ -128,7 +126,7 @@ describe('Test user notifications', function () {
128 }) 126 })
129 127
130 it('Should not send a notification before the video is published', async function () { 128 it('Should not send a notification before the video is published', async function () {
131 this.timeout(50000) 129 this.timeout(150000)
132 130
133 const updateAt = new Date(new Date().getTime() + 1000000) 131 const updateAt = new Date(new Date().getTime() + 1000000)
134 132
@@ -267,7 +265,7 @@ describe('Test user notifications', function () {
267 }) 265 })
268 266
269 it('Should send a notification when an imported video is transcoded', async function () { 267 it('Should send a notification when an imported video is transcoded', async function () {
270 this.timeout(50000) 268 this.timeout(120000)
271 269
272 const name = 'video import ' + buildUUID() 270 const name = 'video import ' + buildUUID()
273 271
diff --git a/server/tests/api/object-storage/live.ts b/server/tests/api/object-storage/live.ts
index 3726a717b..0cb0a6e34 100644
--- a/server/tests/api/object-storage/live.ts
+++ b/server/tests/api/object-storage/live.ts
@@ -3,11 +3,12 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg' 5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { expectStartWith } from '@server/tests/shared'
7import { areObjectStorageTestsDisabled } from '@shared/core-utils'
8import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models'
6import { 9import {
7 areObjectStorageTestsDisabled,
8 createMultipleServers, 10 createMultipleServers,
9 doubleFollow, 11 doubleFollow,
10 expectStartWith,
11 killallServers, 12 killallServers,
12 makeRawRequest, 13 makeRawRequest,
13 ObjectStorageCommand, 14 ObjectStorageCommand,
@@ -18,8 +19,7 @@ import {
18 waitJobs, 19 waitJobs,
19 waitUntilLivePublishedOnAllServers, 20 waitUntilLivePublishedOnAllServers,
20 waitUntilLiveSavedOnAllServers 21 waitUntilLiveSavedOnAllServers
21} from '@shared/extra-utils' 22} from '@shared/server-commands'
22import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models'
23 23
24const expect = chai.expect 24const expect = chai.expect
25 25
diff --git a/server/tests/api/object-storage/video-imports.ts b/server/tests/api/object-storage/video-imports.ts
index 363fe3b5b..fb81832af 100644
--- a/server/tests/api/object-storage/video-imports.ts
+++ b/server/tests/api/object-storage/video-imports.ts
@@ -2,11 +2,11 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { expectStartWith, FIXTURE_URLS } from '@server/tests/shared'
6import { areObjectStorageTestsDisabled } from '@shared/core-utils'
7import { HttpStatusCode, VideoPrivacy } from '@shared/models'
5import { 8import {
6 areObjectStorageTestsDisabled,
7 createSingleServer, 9 createSingleServer,
8 expectStartWith,
9 FIXTURE_URLS,
10 killallServers, 10 killallServers,
11 makeRawRequest, 11 makeRawRequest,
12 ObjectStorageCommand, 12 ObjectStorageCommand,
@@ -14,8 +14,7 @@ import {
14 setAccessTokensToServers, 14 setAccessTokensToServers,
15 setDefaultVideoChannel, 15 setDefaultVideoChannel,
16 waitJobs 16 waitJobs
17} from '@shared/extra-utils' 17} from '@shared/server-commands'
18import { HttpStatusCode, VideoPrivacy } from '@shared/models'
19 18
20const expect = chai.expect 19const expect = chai.expect
21 20
diff --git a/server/tests/api/object-storage/videos.ts b/server/tests/api/object-storage/videos.ts
index 35a5f19ed..498efcb17 100644
--- a/server/tests/api/object-storage/videos.ts
+++ b/server/tests/api/object-storage/videos.ts
@@ -3,25 +3,22 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { merge } from 'lodash' 5import { merge } from 'lodash'
6import { checkTmpIsEmpty, expectLogDoesNotContain, expectStartWith, MockObjectStorage } from '@server/tests/shared'
7import { areObjectStorageTestsDisabled } from '@shared/core-utils'
8import { HttpStatusCode, VideoDetails } from '@shared/models'
6import { 9import {
7 areObjectStorageTestsDisabled,
8 checkTmpIsEmpty,
9 cleanupTests, 10 cleanupTests,
10 createMultipleServers, 11 createMultipleServers,
11 createSingleServer, 12 createSingleServer,
12 doubleFollow, 13 doubleFollow,
13 expectLogDoesNotContain,
14 expectStartWith,
15 killallServers, 14 killallServers,
16 makeRawRequest, 15 makeRawRequest,
17 MockObjectStorage,
18 ObjectStorageCommand, 16 ObjectStorageCommand,
19 PeerTubeServer, 17 PeerTubeServer,
20 setAccessTokensToServers, 18 setAccessTokensToServers,
21 waitJobs, 19 waitJobs,
22 webtorrentAdd 20 webtorrentAdd
23} from '@shared/extra-utils' 21} from '@shared/server-commands'
24import { HttpStatusCode, VideoDetails } from '@shared/models'
25 22
26const expect = chai.expect 23const expect = chai.expect
27 24
diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts
index 5fd464ded..cbf3106bd 100644
--- a/server/tests/api/redundancy/manage-redundancy.ts
+++ b/server/tests/api/redundancy/manage-redundancy.ts
@@ -10,7 +10,7 @@ import {
10 RedundancyCommand, 10 RedundancyCommand,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 waitJobs 12 waitJobs
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' 14import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts
index 933a2c776..17c6b25a5 100644
--- a/server/tests/api/redundancy/redundancy-constraints.ts
+++ b/server/tests/api/redundancy/redundancy-constraints.ts
@@ -2,8 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6import { VideoPrivacy } from '@shared/models' 5import { VideoPrivacy } from '@shared/models'
6import {
7 cleanupTests,
8 createSingleServer,
9 killallServers,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13} from '@shared/server-commands'
7 14
8describe('Test redundancy constraints', function () { 15describe('Test redundancy constraints', function () {
9 let remoteServer: PeerTubeServer 16 let remoteServer: PeerTubeServer
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index 86b40cfe6..3f2286278 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -5,29 +5,26 @@ import * as chai from 'chai'
5import { readdir } from 'fs-extra' 5import { readdir } from 'fs-extra'
6import magnetUtil from 'magnet-uri' 6import magnetUtil from 'magnet-uri'
7import { basename, join } from 'path' 7import { basename, join } from 'path'
8import { checkSegmentHash, checkVideoFilesWereRemoved, saveVideoInServers } from '@server/tests/shared'
9import { root, wait } from '@shared/core-utils'
10import {
11 HttpStatusCode,
12 VideoDetails,
13 VideoFile,
14 VideoPrivacy,
15 VideoRedundancyStrategy,
16 VideoRedundancyStrategyWithManual
17} from '@shared/models'
8import { 18import {
9 checkSegmentHash,
10 checkVideoFilesWereRemoved,
11 cleanupTests, 19 cleanupTests,
12 createMultipleServers, 20 createMultipleServers,
13 doubleFollow, 21 doubleFollow,
14 killallServers, 22 killallServers,
15 makeRawRequest, 23 makeRawRequest,
16 PeerTubeServer, 24 PeerTubeServer,
17 root,
18 saveVideoInServers,
19 setAccessTokensToServers, 25 setAccessTokensToServers,
20 wait,
21 waitJobs 26 waitJobs
22} from '@shared/extra-utils' 27} from '@shared/server-commands'
23import {
24 HttpStatusCode,
25 VideoDetails,
26 VideoFile,
27 VideoPrivacy,
28 VideoRedundancyStrategy,
29 VideoRedundancyStrategyWithManual
30} from '@shared/models'
31 28
32const expect = chai.expect 29const expect = chai.expect
33 30
@@ -307,7 +304,7 @@ describe('Test videos redundancy', function () {
307 const strategy = 'most-views' 304 const strategy = 'most-views'
308 305
309 before(function () { 306 before(function () {
310 this.timeout(120000) 307 this.timeout(240000)
311 308
312 return createServers(strategy) 309 return createServers(strategy)
313 }) 310 })
@@ -357,7 +354,7 @@ describe('Test videos redundancy', function () {
357 const strategy = 'trending' 354 const strategy = 'trending'
358 355
359 before(function () { 356 before(function () {
360 this.timeout(120000) 357 this.timeout(240000)
361 358
362 return createServers(strategy) 359 return createServers(strategy)
363 }) 360 })
@@ -420,7 +417,7 @@ describe('Test videos redundancy', function () {
420 const strategy = 'recently-added' 417 const strategy = 'recently-added'
421 418
422 before(function () { 419 before(function () {
423 this.timeout(120000) 420 this.timeout(240000)
424 421
425 return createServers(strategy, { min_views: 3 }) 422 return createServers(strategy, { min_views: 3 })
426 }) 423 })
@@ -491,7 +488,7 @@ describe('Test videos redundancy', function () {
491 const strategy = 'recently-added' 488 const strategy = 'recently-added'
492 489
493 before(async function () { 490 before(async function () {
494 this.timeout(120000) 491 this.timeout(240000)
495 492
496 await createServers(strategy, { min_views: 3 }, false) 493 await createServers(strategy, { min_views: 3 }, false)
497 }) 494 })
@@ -553,7 +550,7 @@ describe('Test videos redundancy', function () {
553 550
554 describe('With manual strategy', function () { 551 describe('With manual strategy', function () {
555 before(function () { 552 before(function () {
556 this.timeout(120000) 553 this.timeout(240000)
557 554
558 return createServers(null) 555 return createServers(null)
559 }) 556 })
@@ -632,7 +629,7 @@ describe('Test videos redundancy', function () {
632 } 629 }
633 630
634 before(async function () { 631 before(async function () {
635 this.timeout(120000) 632 this.timeout(240000)
636 633
637 await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) 634 await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
638 635
@@ -674,7 +671,7 @@ describe('Test videos redundancy', function () {
674 const strategy = 'recently-added' 671 const strategy = 'recently-added'
675 672
676 before(async function () { 673 before(async function () {
677 this.timeout(120000) 674 this.timeout(240000)
678 675
679 await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) 676 await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
680 677
@@ -698,7 +695,7 @@ describe('Test videos redundancy', function () {
698 }) 695 })
699 696
700 it('Should cache video 2 webseeds on the first video', async function () { 697 it('Should cache video 2 webseeds on the first video', async function () {
701 this.timeout(120000) 698 this.timeout(240000)
702 699
703 await waitJobs(servers) 700 await waitJobs(servers)
704 701
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
index efcdb33dc..2e0abc6ba 100644
--- a/server/tests/api/search/search-activitypub-video-channels.ts
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -2,16 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
6import { VideoChannel } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
8 PeerTubeServer, 10 PeerTubeServer,
9 SearchCommand, 11 SearchCommand,
10 setAccessTokensToServers, 12 setAccessTokensToServers,
11 wait,
12 waitJobs 13 waitJobs
13} from '@shared/extra-utils' 14} from '@shared/server-commands'
14import { VideoChannel } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts
index 34b318268..d9243ac53 100644
--- a/server/tests/api/search/search-activitypub-video-playlists.ts
+++ b/server/tests/api/search/search-activitypub-video-playlists.ts
@@ -2,6 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
6import { VideoPlaylistPrivacy } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
@@ -9,10 +11,8 @@ import {
9 SearchCommand, 11 SearchCommand,
10 setAccessTokensToServers, 12 setAccessTokensToServers,
11 setDefaultVideoChannel, 13 setDefaultVideoChannel,
12 wait,
13 waitJobs 14 waitJobs
14} from '@shared/extra-utils' 15} from '@shared/server-commands'
15import { VideoPlaylistPrivacy } from '@shared/models'
16 16
17const expect = chai.expect 17const expect = chai.expect
18 18
diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts
index a2e6e70fe..60b95ae4c 100644
--- a/server/tests/api/search/search-activitypub-videos.ts
+++ b/server/tests/api/search/search-activitypub-videos.ts
@@ -2,16 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
6import { VideoPrivacy } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
8 PeerTubeServer, 10 PeerTubeServer,
9 SearchCommand, 11 SearchCommand,
10 setAccessTokensToServers, 12 setAccessTokensToServers,
11 wait,
12 waitJobs 13 waitJobs
13} from '@shared/extra-utils' 14} from '@shared/server-commands'
14import { VideoPrivacy } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts
index 67612537c..8a92def61 100644
--- a/server/tests/api/search/search-channels.ts
+++ b/server/tests/api/search/search-channels.ts
@@ -9,7 +9,7 @@ import {
9 PeerTubeServer, 9 PeerTubeServer,
10 SearchCommand, 10 SearchCommand,
11 setAccessTokensToServers 11 setAccessTokensToServers
12} from '@shared/extra-utils' 12} from '@shared/server-commands'
13import { VideoChannel } from '@shared/models' 13import { VideoChannel } from '@shared/models'
14 14
15const expect = chai.expect 15const expect = chai.expect
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index 1845c2069..f84d03345 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' 5import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/server-commands'
6import { 6import {
7 BooleanBothQuery, 7 BooleanBothQuery,
8 VideoChannelsSearchQuery, 8 VideoChannelsSearchQuery,
diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts
index 15aac029a..1e9c8d4bb 100644
--- a/server/tests/api/search/search-playlists.ts
+++ b/server/tests/api/search/search-playlists.ts
@@ -10,7 +10,7 @@ import {
10 SearchCommand, 10 SearchCommand,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 setDefaultVideoChannel 12 setDefaultVideoChannel
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14import { VideoPlaylistPrivacy } from '@shared/models' 14import { VideoPlaylistPrivacy } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts
index ad2a2fddc..c544705d3 100644
--- a/server/tests/api/search/search-videos.ts
+++ b/server/tests/api/search/search-videos.ts
@@ -10,10 +10,10 @@ import {
10 SearchCommand, 10 SearchCommand,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 setDefaultVideoChannel, 12 setDefaultVideoChannel,
13 stopFfmpeg, 13 stopFfmpeg
14 wait 14} from '@shared/server-commands'
15} from '@shared/extra-utils'
16import { VideoPrivacy } from '@shared/models' 15import { VideoPrivacy } from '@shared/models'
16import { wait } from '@shared/core-utils'
17 17
18const expect = chai.expect 18const expect = chai.expect
19 19
diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts
index 90a668edb..6d2333a6b 100644
--- a/server/tests/api/server/auto-follows.ts
+++ b/server/tests/api/server/auto-follows.ts
@@ -2,15 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { MockInstancesIndex } from '@server/tests/shared'
6 cleanupTests, 6import { wait } from '@shared/core-utils'
7 createMultipleServers, 7import { cleanupTests, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
8 MockInstancesIndex,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 wait,
12 waitJobs
13} from '@shared/extra-utils'
14 8
15const expect = chai.expect 9const expect = chai.expect
16 10
diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts
index 16cbcd5c3..1b81a6954 100644
--- a/server/tests/api/server/bulk.ts
+++ b/server/tests/api/server/bulk.ts
@@ -10,7 +10,7 @@ import {
10 PeerTubeServer, 10 PeerTubeServer,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 waitJobs 12 waitJobs
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14 14
15const expect = chai.expect 15const expect = chai.expect
16 16
diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts
new file mode 100644
index 000000000..3ff09bf7e
--- /dev/null
+++ b/server/tests/api/server/config-defaults.ts
@@ -0,0 +1,213 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { FIXTURE_URLS } from '@server/tests/shared'
6import { VideoDetails, VideoPrivacy } from '@shared/models'
7import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands'
8
9const expect = chai.expect
10
11describe('Test config defaults', function () {
12 let server: PeerTubeServer
13 let channelId: number
14
15 before(async function () {
16 this.timeout(30000)
17
18 server = await createSingleServer(1)
19 await setAccessTokensToServers([ server ])
20 await setDefaultVideoChannel([ server ])
21
22 channelId = server.store.channel.id
23 })
24
25 describe('Default publish values', function () {
26
27 before(async function () {
28 const overrideConfig = {
29 defaults: {
30 publish: {
31 comments_enabled: false,
32 download_enabled: false,
33 privacy: VideoPrivacy.INTERNAL,
34 licence: 4
35 }
36 }
37 }
38
39 await server.kill()
40 await server.run(overrideConfig)
41 })
42
43 const attributes = {
44 name: 'video',
45 downloadEnabled: undefined,
46 commentsEnabled: undefined,
47 licence: undefined,
48 privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server
49 }
50
51 function checkVideo (video: VideoDetails) {
52 expect(video.downloadEnabled).to.be.false
53 expect(video.commentsEnabled).to.be.false
54 expect(video.licence.id).to.equal(4)
55 }
56
57 before(async function () {
58 await server.config.disableTranscoding()
59 await server.config.enableImports()
60 await server.config.enableLive({ allowReplay: false, transcoding: false })
61 })
62
63 it('Should have the correct server configuration', async function () {
64 const config = await server.config.getConfig()
65
66 expect(config.defaults.publish.commentsEnabled).to.be.false
67 expect(config.defaults.publish.downloadEnabled).to.be.false
68 expect(config.defaults.publish.licence).to.equal(4)
69 expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL)
70 })
71
72 it('Should respect default values when uploading a video', async function () {
73 for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
74 const { id } = await server.videos.upload({ attributes, mode })
75
76 const video = await server.videos.get({ id })
77 checkVideo(video)
78 }
79 })
80
81 it('Should respect default values when importing a video using URL', async function () {
82 const { video: { id } } = await server.imports.importVideo({
83 attributes: {
84 ...attributes,
85 channelId,
86 targetUrl: FIXTURE_URLS.goodVideo
87 }
88 })
89
90 const video = await server.videos.get({ id })
91 checkVideo(video)
92 })
93
94 it('Should respect default values when importing a video using magnet URI', async function () {
95 const { video: { id } } = await server.imports.importVideo({
96 attributes: {
97 ...attributes,
98 channelId,
99 magnetUri: FIXTURE_URLS.magnet
100 }
101 })
102
103 const video = await server.videos.get({ id })
104 checkVideo(video)
105 })
106
107 it('Should respect default values when creating a live', async function () {
108 const { id } = await server.live.create({
109 fields: {
110 ...attributes,
111 channelId
112 }
113 })
114
115 const video = await server.videos.get({ id })
116 checkVideo(video)
117 })
118 })
119
120 describe('Default P2P values', function () {
121
122 describe('Webapp default value', function () {
123
124 before(async function () {
125 const overrideConfig = {
126 defaults: {
127 p2p: {
128 webapp: {
129 enabled: false
130 }
131 }
132 }
133 }
134
135 await server.kill()
136 await server.run(overrideConfig)
137 })
138
139 it('Should have appropriate P2P config', async function () {
140 const config = await server.config.getConfig()
141
142 expect(config.defaults.p2p.webapp.enabled).to.be.false
143 expect(config.defaults.p2p.embed.enabled).to.be.true
144 })
145
146 it('Should create a user with this default setting', async function () {
147 await server.users.create({ username: 'user_p2p_1' })
148 const userToken = await server.login.getAccessToken('user_p2p_1')
149
150 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
151 expect(p2pEnabled).to.be.false
152 })
153
154 it('Should register a user with this default setting', async function () {
155 await server.users.register({ username: 'user_p2p_2' })
156
157 const userToken = await server.login.getAccessToken('user_p2p_2')
158
159 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
160 expect(p2pEnabled).to.be.false
161 })
162 })
163
164 describe('Embed default value', function () {
165
166 before(async function () {
167 const overrideConfig = {
168 defaults: {
169 p2p: {
170 embed: {
171 enabled: false
172 }
173 }
174 },
175 signup: {
176 limit: 15
177 }
178 }
179
180 await server.kill()
181 await server.run(overrideConfig)
182 })
183
184 it('Should have appropriate P2P config', async function () {
185 const config = await server.config.getConfig()
186
187 expect(config.defaults.p2p.webapp.enabled).to.be.true
188 expect(config.defaults.p2p.embed.enabled).to.be.false
189 })
190
191 it('Should create a user with this default setting', async function () {
192 await server.users.create({ username: 'user_p2p_3' })
193 const userToken = await server.login.getAccessToken('user_p2p_3')
194
195 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
196 expect(p2pEnabled).to.be.true
197 })
198
199 it('Should register a user with this default setting', async function () {
200 await server.users.register({ username: 'user_p2p_4' })
201
202 const userToken = await server.login.getAccessToken('user_p2p_4')
203
204 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
205 expect(p2pEnabled).to.be.true
206 })
207 })
208 })
209
210 after(async function () {
211 await cleanupTests([ server ])
212 })
213})
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index ea524723c..2356f701c 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -2,16 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { parallelTests } from '@shared/core-utils'
6import { CustomConfig, HttpStatusCode } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createSingleServer, 9 createSingleServer,
8 killallServers, 10 killallServers,
9 makeGetRequest, 11 makeGetRequest,
10 parallelTests,
11 PeerTubeServer, 12 PeerTubeServer,
12 setAccessTokensToServers 13 setAccessTokensToServers
13} from '@shared/extra-utils' 14} from '@shared/server-commands'
14import { CustomConfig, HttpStatusCode } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
@@ -43,6 +43,9 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
43 expect(data.services.twitter.username).to.equal('@Chocobozzz') 43 expect(data.services.twitter.username).to.equal('@Chocobozzz')
44 expect(data.services.twitter.whitelisted).to.be.false 44 expect(data.services.twitter.whitelisted).to.be.false
45 45
46 expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.false
47 expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.false
48
46 expect(data.cache.previews.size).to.equal(1) 49 expect(data.cache.previews.size).to.equal(1)
47 expect(data.cache.captions.size).to.equal(1) 50 expect(data.cache.captions.size).to.equal(1)
48 expect(data.cache.torrents.size).to.equal(1) 51 expect(data.cache.torrents.size).to.equal(1)
@@ -138,6 +141,9 @@ function checkUpdatedConfig (data: CustomConfig) {
138 expect(data.services.twitter.username).to.equal('@Kuja') 141 expect(data.services.twitter.username).to.equal('@Kuja')
139 expect(data.services.twitter.whitelisted).to.be.true 142 expect(data.services.twitter.whitelisted).to.be.true
140 143
144 expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.true
145 expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.true
146
141 expect(data.cache.previews.size).to.equal(2) 147 expect(data.cache.previews.size).to.equal(2)
142 expect(data.cache.captions.size).to.equal(3) 148 expect(data.cache.captions.size).to.equal(3)
143 expect(data.cache.torrents.size).to.equal(4) 149 expect(data.cache.torrents.size).to.equal(4)
@@ -246,6 +252,18 @@ const newCustomConfig: CustomConfig = {
246 whitelisted: true 252 whitelisted: true
247 } 253 }
248 }, 254 },
255 client: {
256 videos: {
257 miniature: {
258 preferAuthorDisplayName: true
259 }
260 },
261 menu: {
262 login: {
263 redirectOnSingleExternalAuth: true
264 }
265 }
266 },
249 cache: { 267 cache: {
250 previews: { 268 previews: {
251 size: 2 269 size: 2
diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts
index c555661ad..f3facb04a 100644
--- a/server/tests/api/server/contact-form.ts
+++ b/server/tests/api/server/contact-form.ts
@@ -2,17 +2,17 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { MockSmtpServer } from '@server/tests/shared'
6import { wait } from '@shared/core-utils'
7import { HttpStatusCode } from '@shared/models'
5import { 8import {
6 cleanupTests, 9 cleanupTests,
7 ContactFormCommand, 10 ContactFormCommand,
8 createSingleServer, 11 createSingleServer,
9 MockSmtpServer,
10 PeerTubeServer, 12 PeerTubeServer,
11 setAccessTokensToServers, 13 setAccessTokensToServers,
12 wait,
13 waitJobs 14 waitJobs
14} from '@shared/extra-utils' 15} from '@shared/server-commands'
15import { HttpStatusCode } from '@shared/models'
16 16
17const expect = chai.expect 17const expect = chai.expect
18 18
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index 5f97edbc2..20b5e378c 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 5import { MockSmtpServer } from '@server/tests/shared'
6import { HttpStatusCode } from '@shared/models' 6import { HttpStatusCode } from '@shared/models'
7import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
7 8
8const expect = chai.expect 9const expect = chai.expect
9 10
@@ -185,7 +186,7 @@ describe('Test emails', function () {
185 this.timeout(10000) 186 this.timeout(10000)
186 187
187 const reason = 'my super bad reason' 188 const reason = 'my super bad reason'
188 await server.abuses.report({ videoId, reason }) 189 await server.abuses.report({ token: userAccessToken, videoId, reason })
189 190
190 await waitJobs(server) 191 await waitJobs(server)
191 expect(emails).to.have.lengthOf(3) 192 expect(emails).to.have.lengthOf(3)
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts
index 471f5d8d0..455fbc762 100644
--- a/server/tests/api/server/follow-constraints.ts
+++ b/server/tests/api/server/follow-constraints.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
6import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' 6import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
7 7
8const expect = chai.expect 8const expect = chai.expect
@@ -14,7 +14,7 @@ describe('Test follow constraints', function () {
14 let userToken: string 14 let userToken: string
15 15
16 before(async function () { 16 before(async function () {
17 this.timeout(90000) 17 this.timeout(240000)
18 18
19 servers = await createMultipleServers(2) 19 servers = await createMultipleServers(2)
20 20
diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts
index 921f51043..120bd7f88 100644
--- a/server/tests/api/server/follows-moderation.ts
+++ b/server/tests/api/server/follows-moderation.ts
@@ -9,7 +9,7 @@ import {
9 PeerTubeServer, 9 PeerTubeServer,
10 setAccessTokensToServers, 10 setAccessTokensToServers,
11 waitJobs 11 waitJobs
12} from '@shared/extra-utils' 12} from '@shared/server-commands'
13 13
14const expect = chai.expect 14const expect = chai.expect
15 15
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index 832ba561a..c588cf664 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -2,19 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { completeVideoCheck, dateIsValid, expectAccountFollows, expectChannelsFollows, testCaptionFile } from '@server/tests/shared'
6 cleanupTests,
7 completeVideoCheck,
8 createMultipleServers,
9 dateIsValid,
10 expectAccountFollows,
11 expectChannelsFollows,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 testCaptionFile,
15 waitJobs
16} from '@shared/extra-utils'
17import { VideoCreateResult, VideoPrivacy } from '@shared/models' 6import { VideoCreateResult, VideoPrivacy } from '@shared/models'
7import { cleanupTests, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
18 8
19const expect = chai.expect 9const expect = chai.expect
20 10
@@ -22,7 +12,7 @@ describe('Test follows', function () {
22 let servers: PeerTubeServer[] = [] 12 let servers: PeerTubeServer[] = []
23 13
24 before(async function () { 14 before(async function () {
25 this.timeout(30000) 15 this.timeout(120000)
26 16
27 servers = await createMultipleServers(3) 17 servers = await createMultipleServers(3)
28 18
@@ -292,7 +282,7 @@ describe('Test follows', function () {
292 }) 282 })
293 283
294 it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { 284 it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () {
295 this.timeout(60000) 285 this.timeout(120000)
296 286
297 await servers[1].videos.upload({ attributes: { name: 'server2' } }) 287 await servers[1].videos.upload({ attributes: { name: 'server2' } })
298 await servers[2].videos.upload({ attributes: { name: 'server3' } }) 288 await servers[2].videos.upload({ attributes: { name: 'server3' } })
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts
index fa1da8fe0..3dcd076f5 100644
--- a/server/tests/api/server/handle-down.ts
+++ b/server/tests/api/server/handle-down.ts
@@ -2,18 +2,18 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { completeVideoCheck } from '@server/tests/shared'
6import { wait } from '@shared/core-utils'
7import { HttpStatusCode, JobState, VideoCreateResult, VideoPrivacy } from '@shared/models'
5import { 8import {
6 cleanupTests, 9 cleanupTests,
7 CommentsCommand, 10 CommentsCommand,
8 completeVideoCheck,
9 createMultipleServers, 11 createMultipleServers,
10 killallServers, 12 killallServers,
11 PeerTubeServer, 13 PeerTubeServer,
12 setAccessTokensToServers, 14 setAccessTokensToServers,
13 wait,
14 waitJobs 15 waitJobs
15} from '@shared/extra-utils' 16} from '@shared/server-commands'
16import { HttpStatusCode, JobState, VideoCreateResult, VideoPrivacy } from '@shared/models'
17 17
18const expect = chai.expect 18const expect = chai.expect
19 19
@@ -50,7 +50,7 @@ describe('Test handle downs', function () {
50 let commentCommands: CommentsCommand[] 50 let commentCommands: CommentsCommand[]
51 51
52 before(async function () { 52 before(async function () {
53 this.timeout(30000) 53 this.timeout(120000)
54 54
55 servers = await createMultipleServers(3) 55 servers = await createMultipleServers(3)
56 commentCommands = servers.map(s => s.comments) 56 commentCommands = servers.map(s => s.comments)
diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts
index cb3ba5677..552ee98cf 100644
--- a/server/tests/api/server/homepage.ts
+++ b/server/tests/api/server/homepage.ts
@@ -10,7 +10,7 @@ import {
10 killallServers, 10 killallServers,
11 PeerTubeServer, 11 PeerTubeServer,
12 setAccessTokensToServers 12 setAccessTokensToServers
13} from '../../../../shared/extra-utils/index' 13} from '../../../../shared/server-commands/index'
14 14
15const expect = chai.expect 15const expect = chai.expect
16 16
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts
index 8136fc3c6..45be107ce 100644
--- a/server/tests/api/server/index.ts
+++ b/server/tests/api/server/index.ts
@@ -1,4 +1,6 @@
1import './auto-follows' 1import './auto-follows'
2import './bulk'
3import './config-defaults'
2import './config' 4import './config'
3import './contact-form' 5import './contact-form'
4import './email' 6import './email'
diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts
index 5d946f5e8..4294e1fd5 100644
--- a/server/tests/api/server/jobs.ts
+++ b/server/tests/api/server/jobs.ts
@@ -2,15 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { dateIsValid } from '@server/tests/shared'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 createMultipleServers, 8 createMultipleServers,
8 dateIsValid,
9 doubleFollow, 9 doubleFollow,
10 PeerTubeServer, 10 PeerTubeServer,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 waitJobs 12 waitJobs
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14 14
15const expect = chai.expect 15const expect = chai.expect
16 16
diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts
index 4fa13886e..697f10337 100644
--- a/server/tests/api/server/logs.ts
+++ b/server/tests/api/server/logs.ts
@@ -10,7 +10,7 @@ import {
10 PeerTubeServer, 10 PeerTubeServer,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 waitJobs 12 waitJobs
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14 14
15const expect = chai.expect 15const expect = chai.expect
16 16
diff --git a/server/tests/api/server/no-client.ts b/server/tests/api/server/no-client.ts
index 1e0c95a3b..913907788 100644
--- a/server/tests/api/server/no-client.ts
+++ b/server/tests/api/server/no-client.ts
@@ -1,6 +1,6 @@
1import 'mocha' 1import 'mocha'
2import request from 'supertest' 2import request from 'supertest'
3import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/extra-utils' 3import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands'
4import { HttpStatusCode } from '@shared/models' 4import { HttpStatusCode } from '@shared/models'
5 5
6describe('Start and stop server without web client routes', function () { 6describe('Start and stop server without web client routes', function () {
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts
index 5f9f4ffdd..76d3e2481 100644
--- a/server/tests/api/server/plugins.ts
+++ b/server/tests/api/server/plugins.ts
@@ -2,17 +2,17 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { testHelloWorldRegisteredSettings } from '@server/tests/shared'
6import { wait } from '@shared/core-utils'
7import { HttpStatusCode, PluginType } from '@shared/models'
5import { 8import {
6 cleanupTests, 9 cleanupTests,
7 createSingleServer, 10 createSingleServer,
8 killallServers, 11 killallServers,
9 PeerTubeServer, 12 PeerTubeServer,
10 PluginsCommand, 13 PluginsCommand,
11 setAccessTokensToServers, 14 setAccessTokensToServers
12 testHelloWorldRegisteredSettings, 15} from '@shared/server-commands'
13 wait
14} from '@shared/extra-utils'
15import { HttpStatusCode, PluginType } from '@shared/models'
16 16
17const expect = chai.expect 17const expect = chai.expect
18 18
@@ -99,9 +99,11 @@ describe('Test plugins', function () {
99 99
100 const theme = config.theme.registered.find(r => r.name === 'background-red') 100 const theme = config.theme.registered.find(r => r.name === 'background-red')
101 expect(theme).to.not.be.undefined 101 expect(theme).to.not.be.undefined
102 expect(theme.npmName).to.equal('peertube-theme-background-red')
102 103
103 const plugin = config.plugin.registered.find(r => r.name === 'hello-world') 104 const plugin = config.plugin.registered.find(r => r.name === 'hello-world')
104 expect(plugin).to.not.be.undefined 105 expect(plugin).to.not.be.undefined
106 expect(plugin.npmName).to.equal('peertube-plugin-hello-world')
105 }) 107 })
106 108
107 it('Should update the default theme in the configuration', async function () { 109 it('Should update the default theme in the configuration', async function () {
diff --git a/server/tests/api/server/proxy.ts b/server/tests/api/server/proxy.ts
index 29f3e10d8..2a8ff56d2 100644
--- a/server/tests/api/server/proxy.ts
+++ b/server/tests/api/server/proxy.ts
@@ -2,18 +2,17 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FIXTURE_URLS, MockProxy } from '@server/tests/shared'
6import { HttpStatusCode, VideoPrivacy } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
8 doubleFollow, 10 doubleFollow,
9 FIXTURE_URLS,
10 PeerTubeServer, 11 PeerTubeServer,
11 setAccessTokensToServers, 12 setAccessTokensToServers,
12 setDefaultVideoChannel, 13 setDefaultVideoChannel,
13 waitJobs 14 waitJobs
14} from '@shared/extra-utils' 15} from '@shared/server-commands'
15import { MockProxy } from '@shared/extra-utils/mock-servers/mock-proxy'
16import { HttpStatusCode, VideoPrivacy } from '@shared/models'
17 16
18const expect = chai.expect 17const expect = chai.expect
19 18
@@ -97,7 +96,7 @@ describe('Test proxy', function () {
97 } 96 }
98 97
99 it('Should succeed import with the appropriate proxy config', async function () { 98 it('Should succeed import with the appropriate proxy config', async function () {
100 this.timeout(40000) 99 this.timeout(120000)
101 100
102 await servers[0].kill() 101 await servers[0].kill()
103 await servers[0].run({}, { env: goodEnv }) 102 await servers[0].run({}, { env: goodEnv })
@@ -112,7 +111,7 @@ describe('Test proxy', function () {
112 }) 111 })
113 112
114 it('Should fail import with a wrong proxy config', async function () { 113 it('Should fail import with a wrong proxy config', async function () {
115 this.timeout(40000) 114 this.timeout(120000)
116 115
117 await servers[0].kill() 116 await servers[0].kill()
118 await servers[0].run({}, { env: badEnv }) 117 await servers[0].run({}, { env: badEnv })
diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts
index 484f88d67..968d98e96 100644
--- a/server/tests/api/server/reverse-proxy.ts
+++ b/server/tests/api/server/reverse-proxy.ts
@@ -1,8 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' 4import { wait } from '@shared/core-utils'
5import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
6 7
7describe('Test application behind a reverse proxy', function () { 8describe('Test application behind a reverse proxy', function () {
8 let server: PeerTubeServer 9 let server: PeerTubeServer
diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts
index 823630ae4..5fd2abda4 100644
--- a/server/tests/api/server/services.ts
+++ b/server/tests/api/server/services.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' 5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands'
6import { Video, VideoPlaylistPrivacy } from '@shared/models' 6import { Video, VideoPlaylistPrivacy } from '@shared/models'
7 7
8const expect = chai.expect 8const expect = chai.expect
diff --git a/server/tests/api/server/slow-follows.ts b/server/tests/api/server/slow-follows.ts
index 2bef0c9f2..666a7c2e6 100644
--- a/server/tests/api/server/slow-follows.ts
+++ b/server/tests/api/server/slow-follows.ts
@@ -2,8 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6import { Job } from '@shared/models' 5import { Job } from '@shared/models'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13} from '@shared/server-commands'
7 14
8const expect = chai.expect 15const expect = chai.expect
9 16
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index efc80463c..f0334532b 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -2,16 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
6import { ActivityType, VideoPlaylistPrivacy } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
8 doubleFollow, 10 doubleFollow,
9 PeerTubeServer, 11 PeerTubeServer,
10 setAccessTokensToServers, 12 setAccessTokensToServers,
11 wait,
12 waitJobs 13 waitJobs
13} from '@shared/extra-utils' 14} from '@shared/server-commands'
14import { ActivityType, VideoPlaylistPrivacy } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts
index 30a9618b3..712bb485f 100644
--- a/server/tests/api/server/tracker.ts
+++ b/server/tests/api/server/tracker.ts
@@ -3,7 +3,7 @@
3import 'mocha' 3import 'mocha'
4import magnetUtil from 'magnet-uri' 4import magnetUtil from 'magnet-uri'
5import WebTorrent from 'webtorrent' 5import WebTorrent from 'webtorrent'
6import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 6import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
7 7
8describe('Test tracker', function () { 8describe('Test tracker', function () {
9 let server: PeerTubeServer 9 let server: PeerTubeServer
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index d1d192238..57cca6ad4 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -2,6 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPrivacy } from '@shared/models'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 createMultipleServers, 8 createMultipleServers,
@@ -10,7 +11,7 @@ import {
10 setAccessTokensToServers, 11 setAccessTokensToServers,
11 SubscriptionsCommand, 12 SubscriptionsCommand,
12 waitJobs 13 waitJobs
13} from '@shared/extra-utils' 14} from '@shared/server-commands'
14 15
15const expect = chai.expect 16const expect = chai.expect
16 17
@@ -32,20 +33,18 @@ describe('Test users subscriptions', function () {
32 // Server 1 and server 2 follow each other 33 // Server 1 and server 2 follow each other
33 await doubleFollow(servers[0], servers[1]) 34 await doubleFollow(servers[0], servers[1])
34 35
35 { 36 for (const server of servers) {
36 for (const server of servers) { 37 const user = { username: 'user' + server.serverNumber, password: 'password' }
37 const user = { username: 'user' + server.serverNumber, password: 'password' } 38 await server.users.create({ username: user.username, password: user.password })
38 await server.users.create({ username: user.username, password: user.password })
39 39
40 const accessToken = await server.login.getAccessToken(user) 40 const accessToken = await server.login.getAccessToken(user)
41 users.push({ accessToken }) 41 users.push({ accessToken })
42 42
43 const videoName1 = 'video 1-' + server.serverNumber 43 const videoName1 = 'video 1-' + server.serverNumber
44 await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } }) 44 await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } })
45 45
46 const videoName2 = 'video 2-' + server.serverNumber 46 const videoName2 = 'video 2-' + server.serverNumber
47 await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } }) 47 await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } })
48 }
49 } 48 }
50 49
51 await waitJobs(servers) 50 await waitJobs(servers)
@@ -540,6 +539,40 @@ describe('Test users subscriptions', function () {
540 } 539 }
541 }) 540 })
542 541
542 it('Should update video as internal and not see from remote server', async function () {
543 this.timeout(30000)
544
545 await servers[2].videos.update({ id: video3UUID, attributes: { name: 'internal', privacy: VideoPrivacy.INTERNAL } })
546 await waitJobs(servers)
547
548 {
549 const { data } = await command.listVideos({ token: users[0].accessToken })
550 expect(data.find(v => v.name === 'internal')).to.not.exist
551 }
552 })
553
554 it('Should see internal from local user', async function () {
555 const { data } = await servers[2].subscriptions.listVideos({ token: servers[2].accessToken })
556 expect(data.find(v => v.name === 'internal')).to.exist
557 })
558
559 it('Should update video as private and not see from anyone server', async function () {
560 this.timeout(30000)
561
562 await servers[2].videos.update({ id: video3UUID, attributes: { name: 'private', privacy: VideoPrivacy.PRIVATE } })
563 await waitJobs(servers)
564
565 {
566 const { data } = await command.listVideos({ token: users[0].accessToken })
567 expect(data.find(v => v.name === 'private')).to.not.exist
568 }
569
570 {
571 const { data } = await servers[2].subscriptions.listVideos({ token: servers[2].accessToken })
572 expect(data.find(v => v.name === 'private')).to.not.exist
573 }
574 })
575
543 after(async function () { 576 after(async function () {
544 await cleanupTests(servers) 577 await cleanupTests(servers)
545 }) 578 })
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index d0ca82b07..5b2bbc520 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -6,16 +6,18 @@ import {
6 checkActorFilesWereRemoved, 6 checkActorFilesWereRemoved,
7 checkTmpIsEmpty, 7 checkTmpIsEmpty,
8 checkVideoFilesWereRemoved, 8 checkVideoFilesWereRemoved,
9 saveVideoInServers,
10 testImage
11} from '@server/tests/shared'
12import { MyUser } from '@shared/models'
13import {
9 cleanupTests, 14 cleanupTests,
10 createMultipleServers, 15 createMultipleServers,
11 doubleFollow, 16 doubleFollow,
12 PeerTubeServer, 17 PeerTubeServer,
13 saveVideoInServers,
14 setAccessTokensToServers, 18 setAccessTokensToServers,
15 testImage,
16 waitJobs 19 waitJobs
17} from '@shared/extra-utils' 20} from '@shared/server-commands'
18import { MyUser } from '@shared/models'
19 21
20const expect = chai.expect 22const expect = chai.expect
21 23
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index f54463359..0f3cc401a 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 5import { MockSmtpServer } from '@server/tests/shared'
6import { HttpStatusCode } from '@shared/models' 6import { HttpStatusCode } from '@shared/models'
7import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
7 8
8const expect = chai.expect 9const expect = chai.expect
9 10
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 6c41e7d56..7023b3f08 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -2,6 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { testImage } from '@server/tests/shared'
6import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createSingleServer, 9 createSingleServer,
@@ -9,10 +11,8 @@ import {
9 makePutBodyRequest, 11 makePutBodyRequest,
10 PeerTubeServer, 12 PeerTubeServer,
11 setAccessTokensToServers, 13 setAccessTokensToServers,
12 testImage,
13 waitJobs 14 waitJobs
14} from '@shared/extra-utils' 15} from '@shared/server-commands'
15import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
16 16
17const expect = chai.expect 17const expect = chai.expect
18 18
@@ -230,7 +230,7 @@ describe('Test users', function () {
230 }) 230 })
231 231
232 it('Should have an expired access token', async function () { 232 it('Should have an expired access token', async function () {
233 this.timeout(15000) 233 this.timeout(60000)
234 234
235 await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) 235 await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString())
236 await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) 236 await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString())
@@ -559,6 +559,28 @@ describe('Test users', function () {
559 expect(user.autoPlayNextVideo).to.be.true 559 expect(user.autoPlayNextVideo).to.be.true
560 }) 560 })
561 561
562 it('Should be able to change the p2p attribute', async function () {
563 {
564 await server.users.updateMe({
565 token: userToken,
566 webTorrentEnabled: false
567 })
568
569 const user = await server.users.getMyInfo({ token: userToken })
570 expect(user.p2pEnabled).to.be.false
571 }
572
573 {
574 await server.users.updateMe({
575 token: userToken,
576 p2pEnabled: true
577 })
578
579 const user = await server.users.getMyInfo({ token: userToken })
580 expect(user.p2pEnabled).to.be.true
581 }
582 })
583
562 it('Should be able to change the email attribute', async function () { 584 it('Should be able to change the email attribute', async function () {
563 await server.users.updateMe({ 585 await server.users.updateMe({
564 token: userToken, 586 token: userToken,
diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts
index f4b635bd5..e58360ffe 100644
--- a/server/tests/api/videos/audio-only.ts
+++ b/server/tests/api/videos/audio-only.ts
@@ -3,7 +3,14 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' 5import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils'
6import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13} from '@shared/server-commands'
7 14
8const expect = chai.expect 15const expect = chai.expect
9 16
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index c6c279064..ecdd36613 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -4,23 +4,24 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import request from 'supertest' 5import request from 'supertest'
6import { 6import {
7 buildAbsoluteFixturePath,
8 checkTmpIsEmpty, 7 checkTmpIsEmpty,
9 checkVideoFilesWereRemoved, 8 checkVideoFilesWereRemoved,
10 cleanupTests,
11 completeVideoCheck, 9 completeVideoCheck,
12 createMultipleServers,
13 dateIsValid, 10 dateIsValid,
11 saveVideoInServers,
12 testImage
13} from '@server/tests/shared'
14import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
15import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
16import {
17 cleanupTests,
18 createMultipleServers,
14 doubleFollow, 19 doubleFollow,
15 PeerTubeServer, 20 PeerTubeServer,
16 saveVideoInServers,
17 setAccessTokensToServers, 21 setAccessTokensToServers,
18 testImage,
19 wait,
20 waitJobs, 22 waitJobs,
21 webtorrentAdd 23 webtorrentAdd
22} from '@shared/extra-utils' 24} from '@shared/server-commands'
23import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
24 25
25const expect = chai.expect 26const expect = chai.expect
26 27
@@ -379,7 +380,7 @@ describe('Test multiple servers', function () {
379 380
380 describe('Should seed the uploaded video', function () { 381 describe('Should seed the uploaded video', function () {
381 it('Should add the file 1 by asking server 3', async function () { 382 it('Should add the file 1 by asking server 3', async function () {
382 this.timeout(10000) 383 this.timeout(30000)
383 384
384 const { data } = await servers[2].videos.list() 385 const { data } = await servers[2].videos.list()
385 386
@@ -395,7 +396,7 @@ describe('Test multiple servers', function () {
395 }) 396 })
396 397
397 it('Should add the file 2 by asking server 1', async function () { 398 it('Should add the file 2 by asking server 1', async function () {
398 this.timeout(10000) 399 this.timeout(30000)
399 400
400 const { data } = await servers[0].videos.list() 401 const { data } = await servers[0].videos.list()
401 402
@@ -409,7 +410,7 @@ describe('Test multiple servers', function () {
409 }) 410 })
410 411
411 it('Should add the file 3 by asking server 2', async function () { 412 it('Should add the file 3 by asking server 2', async function () {
412 this.timeout(10000) 413 this.timeout(30000)
413 414
414 const { data } = await servers[1].videos.list() 415 const { data } = await servers[1].videos.list()
415 416
@@ -423,7 +424,7 @@ describe('Test multiple servers', function () {
423 }) 424 })
424 425
425 it('Should add the file 3-2 by asking server 1', async function () { 426 it('Should add the file 3-2 by asking server 1', async function () {
426 this.timeout(10000) 427 this.timeout(30000)
427 428
428 const { data } = await servers[0].videos.list() 429 const { data } = await servers[0].videos.list()
429 430
@@ -437,7 +438,7 @@ describe('Test multiple servers', function () {
437 }) 438 })
438 439
439 it('Should add the file 2 in 360p by asking server 1', async function () { 440 it('Should add the file 2 in 360p by asking server 1', async function () {
440 this.timeout(10000) 441 this.timeout(30000)
441 442
442 const { data } = await servers[0].videos.list() 443 const { data } = await servers[0].videos.list()
443 444
@@ -594,7 +595,7 @@ describe('Test multiple servers', function () {
594 let updatedAtMin: Date 595 let updatedAtMin: Date
595 596
596 it('Should update video 3', async function () { 597 it('Should update video 3', async function () {
597 this.timeout(10000) 598 this.timeout(30000)
598 599
599 const attributes = { 600 const attributes = {
600 name: 'my super video updated', 601 name: 'my super video updated',
@@ -617,7 +618,7 @@ describe('Test multiple servers', function () {
617 }) 618 })
618 619
619 it('Should have the video 3 updated on each server', async function () { 620 it('Should have the video 3 updated on each server', async function () {
620 this.timeout(10000) 621 this.timeout(30000)
621 622
622 for (const server of servers) { 623 for (const server of servers) {
623 const { data } = await server.videos.list() 624 const { data } = await server.videos.list()
@@ -668,7 +669,7 @@ describe('Test multiple servers', function () {
668 }) 669 })
669 670
670 it('Should only update thumbnail and update updatedAt attribute', async function () { 671 it('Should only update thumbnail and update updatedAt attribute', async function () {
671 this.timeout(10000) 672 this.timeout(30000)
672 673
673 const attributes = { 674 const attributes = {
674 thumbnailfile: 'thumbnail.jpg' 675 thumbnailfile: 'thumbnail.jpg'
@@ -860,7 +861,7 @@ describe('Test multiple servers', function () {
860 }) 861 })
861 862
862 it('Should delete a reply', async function () { 863 it('Should delete a reply', async function () {
863 this.timeout(10000) 864 this.timeout(30000)
864 865
865 await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id }) 866 await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id })
866 867
@@ -891,7 +892,7 @@ describe('Test multiple servers', function () {
891 }) 892 })
892 893
893 it('Should delete the thread comments', async function () { 894 it('Should delete the thread comments', async function () {
894 this.timeout(10000) 895 this.timeout(30000)
895 896
896 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) 897 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
897 const commentId = data.find(c => c.text === 'my super first comment').id 898 const commentId = data.find(c => c.text === 'my super first comment').id
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index 1ba7cdbcc..d6f4da630 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -4,15 +4,9 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { pathExists, readdir, stat } from 'fs-extra' 5import { pathExists, readdir, stat } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { 7import { buildAbsoluteFixturePath } from '@shared/core-utils'
8 buildAbsoluteFixturePath,
9 cleanupTests,
10 createSingleServer,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 setDefaultVideoChannel
14} from '@shared/extra-utils'
15import { HttpStatusCode, VideoPrivacy } from '@shared/models' 8import { HttpStatusCode, VideoPrivacy } from '@shared/models'
9import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands'
16 10
17const expect = chai.expect 11const expect = chai.expect
18 12
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index a0e4a156c..28bf018c5 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -2,17 +2,10 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { checkVideoFilesWereRemoved, completeVideoCheck, testImage } from '@server/tests/shared'
6 checkVideoFilesWereRemoved, 6import { wait } from '@shared/core-utils'
7 cleanupTests,
8 completeVideoCheck,
9 createSingleServer,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 testImage,
13 wait
14} from '@shared/extra-utils'
15import { Video, VideoPrivacy } from '@shared/models' 7import { Video, VideoPrivacy } from '@shared/models'
8import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
16 9
17const expect = chai.expect 10const expect = chai.expect
18 11
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index 3bb0d131c..b7f26c35f 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -2,17 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { checkVideoFilesWereRemoved, testCaptionFile } from '@server/tests/shared'
6import { wait } from '@shared/core-utils'
5import { 7import {
6 checkVideoFilesWereRemoved,
7 cleanupTests, 8 cleanupTests,
8 createMultipleServers, 9 createMultipleServers,
9 doubleFollow, 10 doubleFollow,
10 PeerTubeServer, 11 PeerTubeServer,
11 setAccessTokensToServers, 12 setAccessTokensToServers,
12 testCaptionFile,
13 wait,
14 waitJobs 13 waitJobs
15} from '@shared/extra-utils' 14} from '@shared/server-commands'
16 15
17const expect = chai.expect 16const expect = chai.expect
18 17
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index d6665fe4e..6c229c6cf 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -12,7 +12,7 @@ import {
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 setDefaultVideoChannel, 13 setDefaultVideoChannel,
14 waitJobs 14 waitJobs
15} from '@shared/extra-utils' 15} from '@shared/server-commands'
16import { HttpStatusCode, VideoPrivacy } from '@shared/models' 16import { HttpStatusCode, VideoPrivacy } from '@shared/models'
17 17
18const expect = chai.expect 18const expect = chai.expect
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index c25754eb6..d435f3682 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -4,6 +4,9 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { basename } from 'path' 5import { basename } from 'path'
6import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' 6import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
7import { testFileExistsOrNot, testImage } from '@server/tests/shared'
8import { wait } from '@shared/core-utils'
9import { User, VideoChannel } from '@shared/models'
7import { 10import {
8 cleanupTests, 11 cleanupTests,
9 createMultipleServers, 12 createMultipleServers,
@@ -11,12 +14,8 @@ import {
11 PeerTubeServer, 14 PeerTubeServer,
12 setAccessTokensToServers, 15 setAccessTokensToServers,
13 setDefaultVideoChannel, 16 setDefaultVideoChannel,
14 testFileExistsOrNot,
15 testImage,
16 wait,
17 waitJobs 17 waitJobs
18} from '@shared/extra-utils' 18} from '@shared/server-commands'
19import { User, VideoChannel } from '@shared/models'
20 19
21const expect = chai.expect 20const expect = chai.expect
22 21
@@ -33,6 +32,7 @@ describe('Test video channels', function () {
33 let totoChannel: number 32 let totoChannel: number
34 let videoUUID: string 33 let videoUUID: string
35 let accountName: string 34 let accountName: string
35 let secondUserChannelName: string
36 36
37 const avatarPaths: { [ port: number ]: string } = {} 37 const avatarPaths: { [ port: number ]: string } = {}
38 const bannerPaths: { [ port: number ]: string } = {} 38 const bannerPaths: { [ port: number ]: string } = {}
@@ -219,6 +219,35 @@ describe('Test video channels', function () {
219 } 219 }
220 }) 220 })
221 221
222 it('Should update another accounts video channel', async function () {
223 this.timeout(15000)
224
225 const result = await servers[0].users.generate('second_user')
226 secondUserChannelName = result.userChannelName
227
228 await servers[0].videos.quickUpload({ name: 'video', token: result.token })
229
230 const videoChannelAttributes = {
231 displayName: 'video channel updated',
232 description: 'video channel description updated',
233 support: 'support updated'
234 }
235
236 await servers[0].channels.update({ channelName: secondUserChannelName, attributes: videoChannelAttributes })
237
238 await waitJobs(servers)
239 })
240
241 it('Should have another accounts video channel updated', async function () {
242 for (const server of servers) {
243 const body = await server.channels.get({ channelName: `${secondUserChannelName}@${servers[0].host}` })
244
245 expect(body.displayName).to.equal('video channel updated')
246 expect(body.description).to.equal('video channel description updated')
247 expect(body.support).to.equal('support updated')
248 }
249 })
250
222 it('Should update the channel support field and update videos too', async function () { 251 it('Should update the channel support field and update videos too', async function () {
223 this.timeout(35000) 252 this.timeout(35000)
224 253
@@ -368,12 +397,13 @@ describe('Test video channels', function () {
368 }) 397 })
369 398
370 it('Should have video channel deleted', async function () { 399 it('Should have video channel deleted', async function () {
371 const body = await servers[0].channels.list({ start: 0, count: 10 }) 400 const body = await servers[0].channels.list({ start: 0, count: 10, sort: 'createdAt' })
372 401
373 expect(body.total).to.equal(1) 402 expect(body.total).to.equal(2)
374 expect(body.data).to.be.an('array') 403 expect(body.data).to.be.an('array')
375 expect(body.data).to.have.lengthOf(1) 404 expect(body.data).to.have.lengthOf(2)
376 expect(body.data[0].displayName).to.equal('Main root channel') 405 expect(body.data[0].displayName).to.equal('Main root channel')
406 expect(body.data[1].displayName).to.equal('video channel updated')
377 }) 407 })
378 408
379 it('Should create the main channel with an uuid if there is a conflict', async function () { 409 it('Should create the main channel with an uuid if there is a conflict', async function () {
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index 61ee54540..2ae523970 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -2,15 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { dateIsValid, testImage } from '@server/tests/shared'
6 cleanupTests, 6import { cleanupTests, CommentsCommand, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
7 CommentsCommand,
8 createSingleServer,
9 dateIsValid,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 testImage
13} from '@shared/extra-utils'
14 7
15const expect = chai.expect 8const expect = chai.expect
16 9
diff --git a/server/tests/api/videos/video-create-transcoding.ts b/server/tests/api/videos/video-create-transcoding.ts
index c4627e0c1..62a6bab0d 100644
--- a/server/tests/api/videos/video-create-transcoding.ts
+++ b/server/tests/api/videos/video-create-transcoding.ts
@@ -2,20 +2,20 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { expectStartWith } from '@server/tests/shared'
6import { areObjectStorageTestsDisabled } from '@shared/core-utils'
7import { HttpStatusCode, VideoDetails } from '@shared/models'
5import { 8import {
6 areObjectStorageTestsDisabled,
7 cleanupTests, 9 cleanupTests,
8 createMultipleServers, 10 createMultipleServers,
9 doubleFollow, 11 doubleFollow,
10 expectNoFailedTranscodingJob, 12 expectNoFailedTranscodingJob,
11 expectStartWith,
12 makeRawRequest, 13 makeRawRequest,
13 ObjectStorageCommand, 14 ObjectStorageCommand,
14 PeerTubeServer, 15 PeerTubeServer,
15 setAccessTokensToServers, 16 setAccessTokensToServers,
16 waitJobs 17 waitJobs
17} from '@shared/extra-utils' 18} from '@shared/server-commands'
18import { HttpStatusCode, VideoDetails } from '@shared/models'
19 19
20const expect = chai.expect 20const expect = chai.expect
21 21
diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts
index d22b4ed96..20b20488f 100644
--- a/server/tests/api/videos/video-description.ts
+++ b/server/tests/api/videos/video-description.ts
@@ -2,7 +2,14 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12} from '@shared/server-commands'
6 13
7const expect = chai.expect 14const expect = chai.expect
8 15
diff --git a/server/tests/api/videos/video-files.ts b/server/tests/api/videos/video-files.ts
index fcb2ca2e4..b0ef4a2e9 100644
--- a/server/tests/api/videos/video-files.ts
+++ b/server/tests/api/videos/video-files.ts
@@ -2,7 +2,14 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12} from '@shared/server-commands'
6 13
7describe('Test videos files', function () { 14describe('Test videos files', function () {
8 let servers: PeerTubeServer[] 15 let servers: PeerTubeServer[]
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts
index a18c3d672..218ec08ae 100644
--- a/server/tests/api/videos/video-hls.ts
+++ b/server/tests/api/videos/video-hls.ts
@@ -3,26 +3,27 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { basename, join } from 'path' 5import { basename, join } from 'path'
6import { removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils'
7import { 6import {
8 areObjectStorageTestsDisabled,
9 checkDirectoryIsEmpty, 7 checkDirectoryIsEmpty,
10 checkResolutionsInMasterPlaylist, 8 checkResolutionsInMasterPlaylist,
11 checkSegmentHash, 9 checkSegmentHash,
12 checkTmpIsEmpty, 10 checkTmpIsEmpty,
11 expectStartWith,
12 hlsInfohashExist
13} from '@server/tests/shared'
14import { areObjectStorageTestsDisabled, removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils'
15import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models'
16import {
13 cleanupTests, 17 cleanupTests,
14 createMultipleServers, 18 createMultipleServers,
15 doubleFollow, 19 doubleFollow,
16 expectStartWith,
17 hlsInfohashExist,
18 makeRawRequest, 20 makeRawRequest,
19 ObjectStorageCommand, 21 ObjectStorageCommand,
20 PeerTubeServer, 22 PeerTubeServer,
21 setAccessTokensToServers, 23 setAccessTokensToServers,
22 waitJobs, 24 waitJobs,
23 webtorrentAdd 25 webtorrentAdd
24} from '@shared/extra-utils' 26} from '@shared/server-commands'
25import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models'
26import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' 27import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
27 28
28const expect = chai.expect 29const expect = chai.expect
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index b6168b54e..e8e0f01f1 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -4,21 +4,19 @@ import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { pathExists, readdir, remove } from 'fs-extra' 5import { pathExists, readdir, remove } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { FIXTURE_URLS, testCaptionFile, testImage } from '@server/tests/shared'
8import { areHttpImportTestsDisabled } from '@shared/core-utils'
9import { VideoPrivacy, VideoResolution } from '@shared/models'
7import { 10import {
8 areHttpImportTestsDisabled,
9 cleanupTests, 11 cleanupTests,
10 createMultipleServers, 12 createMultipleServers,
11 createSingleServer, 13 createSingleServer,
12 doubleFollow, 14 doubleFollow,
13 FIXTURE_URLS,
14 PeerTubeServer, 15 PeerTubeServer,
15 setAccessTokensToServers, 16 setAccessTokensToServers,
16 setDefaultVideoChannel, 17 setDefaultVideoChannel,
17 testCaptionFile,
18 testImage,
19 waitJobs 18 waitJobs
20} from '@shared/extra-utils' 19} from '@shared/server-commands'
21import { VideoPrivacy, VideoResolution } from '@shared/models'
22 20
23async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) { 21async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) {
24 const videoHttp = await server.videos.get({ id: idHttp }) 22 const videoHttp = await server.videos.get({ id: idHttp })
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index b5d183d62..99ea67a0f 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
6import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' 6import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models'
7 7
8const expect = chai.expect 8const expect = chai.expect
diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts
index f0b2ca169..5fdb0fc03 100644
--- a/server/tests/api/videos/video-playlist-thumbnails.ts
+++ b/server/tests/api/videos/video-playlist-thumbnails.ts
@@ -2,6 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { testImage } from '@server/tests/shared'
6import { VideoPlaylistPrivacy } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
@@ -9,10 +11,8 @@ import {
9 PeerTubeServer, 11 PeerTubeServer,
10 setAccessTokensToServers, 12 setAccessTokensToServers,
11 setDefaultVideoChannel, 13 setDefaultVideoChannel,
12 testImage,
13 waitJobs 14 waitJobs
14} from '../../../../shared/extra-utils' 15} from '@shared/server-commands'
15import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
16 16
17const expect = chai.expect 17const expect = chai.expect
18 18
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index f42aee2ff..34327334f 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -2,19 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared'
6 checkPlaylistFilesWereRemoved, 6import { wait } from '@shared/core-utils'
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 PeerTubeServer,
11 PlaylistsCommand,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
14 testImage,
15 wait,
16 waitJobs
17} from '@shared/extra-utils'
18import { 7import {
19 HttpStatusCode, 8 HttpStatusCode,
20 VideoPlaylist, 9 VideoPlaylist,
@@ -24,6 +13,16 @@ import {
24 VideoPlaylistType, 13 VideoPlaylistType,
25 VideoPrivacy 14 VideoPrivacy
26} from '@shared/models' 15} from '@shared/models'
16import {
17 cleanupTests,
18 createMultipleServers,
19 doubleFollow,
20 PeerTubeServer,
21 PlaylistsCommand,
22 setAccessTokensToServers,
23 setDefaultVideoChannel,
24 waitJobs
25} from '@shared/server-commands'
27 26
28const expect = chai.expect 27const expect = chai.expect
29 28
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index b51b3bcdd..3051a443d 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' 5import { wait } from '@shared/core-utils'
6import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' 6import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
7import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
7 8
8const expect = chai.expect 9const expect = chai.expect
9 10
@@ -209,7 +210,7 @@ describe('Test video privacy', function () {
209 describe('Privacy update', function () { 210 describe('Privacy update', function () {
210 211
211 it('Should update the private and internal videos to public on server 1', async function () { 212 it('Should update the private and internal videos to public on server 1', async function () {
212 this.timeout(10000) 213 this.timeout(100000)
213 214
214 now = Date.now() 215 now = Date.now()
215 216
@@ -230,6 +231,7 @@ describe('Test video privacy', function () {
230 await servers[0].videos.update({ id: internalVideoId, attributes }) 231 await servers[0].videos.update({ id: internalVideoId, attributes })
231 } 232 }
232 233
234 await wait(10000)
233 await waitJobs(servers) 235 await waitJobs(servers)
234 }) 236 })
235 237
diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts
index 3f7738784..00b4f6cbc 100644
--- a/server/tests/api/videos/video-schedule-update.ts
+++ b/server/tests/api/videos/video-schedule-update.ts
@@ -2,16 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
6import { VideoPrivacy } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
8 doubleFollow, 10 doubleFollow,
9 PeerTubeServer, 11 PeerTubeServer,
10 setAccessTokensToServers, 12 setAccessTokensToServers,
11 wait,
12 waitJobs 13 waitJobs
13} from '@shared/extra-utils' 14} from '@shared/server-commands'
14import { VideoPrivacy } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index 7ed55b8e8..d24a8f4e1 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -3,29 +3,21 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { getMaxBitrate, getMinLimitBitrate } from '@shared/core-utils' 6import { canDoQuickTranscode } from '@server/helpers/ffprobe-utils'
7import { generateHighBitrateVideo, generateVideoWithFramerate } from '@server/tests/shared'
8import { buildAbsoluteFixturePath, getMaxBitrate, getMinLimitBitrate } from '@shared/core-utils'
9import { getAudioStream, getMetadataFromFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '@shared/extra-utils'
10import { HttpStatusCode, VideoState } from '@shared/models'
7import { 11import {
8 buildAbsoluteFixturePath,
9 cleanupTests, 12 cleanupTests,
10 createMultipleServers, 13 createMultipleServers,
11 doubleFollow, 14 doubleFollow,
12 generateHighBitrateVideo,
13 generateVideoWithFramerate,
14 makeGetRequest, 15 makeGetRequest,
15 PeerTubeServer, 16 PeerTubeServer,
16 setAccessTokensToServers, 17 setAccessTokensToServers,
17 waitJobs, 18 waitJobs,
18 webtorrentAdd 19 webtorrentAdd
19} from '@shared/extra-utils' 20} from '@shared/server-commands'
20import { HttpStatusCode, VideoState } from '@shared/models'
21import {
22 canDoQuickTranscode,
23 getAudioStream,
24 getMetadataFromFile,
25 getVideoFileBitrate,
26 getVideoFileFPS,
27 getVideoFileResolution
28} from '../../../helpers/ffprobe-utils'
29 21
30const expect = chai.expect 22const expect = chai.expect
31 23
diff --git a/server/tests/api/videos/videos-common-filters.ts b/server/tests/api/videos/videos-common-filters.ts
index ca5f42173..0254662c5 100644
--- a/server/tests/api/videos/videos-common-filters.ts
+++ b/server/tests/api/videos/videos-common-filters.ts
@@ -12,7 +12,7 @@ import {
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 setDefaultVideoChannel, 13 setDefaultVideoChannel,
14 waitJobs 14 waitJobs
15} from '@shared/extra-utils' 15} from '@shared/server-commands'
16import { HttpStatusCode, UserRole, Video, VideoDetails, VideoInclude, VideoPrivacy } from '@shared/models' 16import { HttpStatusCode, UserRole, Video, VideoDetails, VideoInclude, VideoPrivacy } from '@shared/models'
17 17
18describe('Test videos filter', function () { 18describe('Test videos filter', function () {
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index e4bc0bb3a..4e5ba13aa 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -2,16 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
6import { HttpStatusCode, Video } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createSingleServer, 9 createSingleServer,
8 HistoryCommand, 10 HistoryCommand,
9 killallServers, 11 killallServers,
10 PeerTubeServer, 12 PeerTubeServer,
11 setAccessTokensToServers, 13 setAccessTokensToServers
12 wait 14} from '@shared/server-commands'
13} from '@shared/extra-utils'
14import { HttpStatusCode, Video } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts
index 70aa66549..61fc0cb20 100644
--- a/server/tests/api/videos/videos-overview.ts
+++ b/server/tests/api/videos/videos-overview.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' 5import { wait } from '@shared/core-utils'
6import { VideosOverview } from '@shared/models' 6import { VideosOverview } from '@shared/models'
7import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
7 8
8const expect = chai.expect 9const expect = chai.expect
9 10
diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts
index 82268b1be..e6815a4a8 100644
--- a/server/tests/api/videos/videos-views-cleaner.ts
+++ b/server/tests/api/videos/videos-views-cleaner.ts
@@ -2,6 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 createMultipleServers, 8 createMultipleServers,
@@ -9,9 +10,8 @@ import {
9 killallServers, 10 killallServers,
10 PeerTubeServer, 11 PeerTubeServer,
11 setAccessTokensToServers, 12 setAccessTokensToServers,
12 wait,
13 waitJobs 13 waitJobs
14} from '../../../../shared/extra-utils' 14} from '@shared/server-commands'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts
index c06b9550c..8ef0545d0 100644
--- a/server/tests/cli/create-import-video-file-job.ts
+++ b/server/tests/cli/create-import-video-file-job.ts
@@ -2,19 +2,19 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { areObjectStorageTestsDisabled } from '@shared/core-utils'
6import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models'
5import { 7import {
6 areObjectStorageTestsDisabled,
7 cleanupTests, 8 cleanupTests,
8 createMultipleServers, 9 createMultipleServers,
9 doubleFollow, 10 doubleFollow,
10 expectStartWith,
11 makeRawRequest, 11 makeRawRequest,
12 ObjectStorageCommand, 12 ObjectStorageCommand,
13 PeerTubeServer, 13 PeerTubeServer,
14 setAccessTokensToServers, 14 setAccessTokensToServers,
15 waitJobs 15 waitJobs
16} from '@shared/extra-utils' 16} from '@shared/server-commands'
17import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models' 17import { expectStartWith } from '../shared'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
diff --git a/server/tests/cli/create-move-video-storage-job.ts b/server/tests/cli/create-move-video-storage-job.ts
index b598c8359..c674d28d2 100644
--- a/server/tests/cli/create-move-video-storage-job.ts
+++ b/server/tests/cli/create-move-video-storage-job.ts
@@ -1,20 +1,19 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4 4import { areObjectStorageTestsDisabled } from '@shared/core-utils'
5import { HttpStatusCode, VideoDetails } from '@shared/models'
5import { 6import {
6 areObjectStorageTestsDisabled,
7 cleanupTests, 7 cleanupTests,
8 createMultipleServers, 8 createMultipleServers,
9 doubleFollow, 9 doubleFollow,
10 expectStartWith,
11 makeRawRequest, 10 makeRawRequest,
12 ObjectStorageCommand, 11 ObjectStorageCommand,
13 PeerTubeServer, 12 PeerTubeServer,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 waitJobs 14 waitJobs
16} from '@shared/extra-utils' 15} from '@shared/server-commands'
17import { HttpStatusCode, VideoDetails } from '@shared/models' 16import { expectStartWith } from '../shared'
18 17
19async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) { 18async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
20 for (const file of video.files) { 19 for (const file of video.files) {
diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts
index fb9c2584f..c85130fef 100644
--- a/server/tests/cli/create-transcoding-job.ts
+++ b/server/tests/cli/create-transcoding-job.ts
@@ -2,19 +2,19 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { areObjectStorageTestsDisabled } from '@shared/core-utils'
5import { HttpStatusCode, VideoFile } from '@shared/models' 6import { HttpStatusCode, VideoFile } from '@shared/models'
6import { 7import {
7 areObjectStorageTestsDisabled,
8 cleanupTests, 8 cleanupTests,
9 createMultipleServers, 9 createMultipleServers,
10 doubleFollow, 10 doubleFollow,
11 expectStartWith,
12 makeRawRequest, 11 makeRawRequest,
13 ObjectStorageCommand, 12 ObjectStorageCommand,
14 PeerTubeServer, 13 PeerTubeServer,
15 setAccessTokensToServers, 14 setAccessTokensToServers,
16 waitJobs 15 waitJobs
17} from '../../../shared/extra-utils' 16} from '@shared/server-commands'
17import { expectStartWith } from '../shared'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index f2a984962..034d216e3 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -2,19 +2,17 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils'
5import { 6import {
6 areHttpImportTestsDisabled,
7 buildAbsoluteFixturePath,
8 cleanupTests, 7 cleanupTests,
9 CLICommand, 8 CLICommand,
10 createSingleServer, 9 createSingleServer,
11 doubleFollow, 10 doubleFollow,
12 FIXTURE_URLS,
13 PeerTubeServer, 11 PeerTubeServer,
14 setAccessTokensToServers, 12 setAccessTokensToServers,
15 testHelloWorldRegisteredSettings,
16 waitJobs 13 waitJobs
17} from '../../../shared/extra-utils' 14} from '@shared/server-commands'
15import { FIXTURE_URLS, testHelloWorldRegisteredSettings } from '../shared'
18 16
19describe('Test CLI wrapper', function () { 17describe('Test CLI wrapper', function () {
20 let server: PeerTubeServer 18 let server: PeerTubeServer
@@ -207,6 +205,25 @@ describe('Test CLI wrapper', function () {
207 205
208 expect(res).to.not.contain('peertube-plugin-hello-world') 206 expect(res).to.not.contain('peertube-plugin-hello-world')
209 }) 207 })
208
209 it('Should install a plugin in requested version', async function () {
210 this.timeout(60000)
211
212 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.17`)
213 })
214
215 it('Should list installed plugins, in correct version', async function () {
216 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
217
218 expect(res).to.contain('peertube-plugin-hello-world')
219 expect(res).to.contain('0.0.17')
220 })
221
222 it('Should uninstall the plugin again', async function () {
223 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
224
225 expect(res).to.not.contain('peertube-plugin-hello-world')
226 })
210 }) 227 })
211 228
212 describe('Manage video redundancies', function () { 229 describe('Manage video redundancies', function () {
diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.ts
index 07c78cc89..cd9f4e1c3 100644
--- a/server/tests/cli/plugins.ts
+++ b/server/tests/cli/plugins.ts
@@ -9,7 +9,7 @@ import {
9 PeerTubeServer, 9 PeerTubeServer,
10 PluginsCommand, 10 PluginsCommand,
11 setAccessTokensToServers 11 setAccessTokensToServers
12} from '../../../shared/extra-utils' 12} from '@shared/server-commands'
13 13
14describe('Test plugin scripts', function () { 14describe('Test plugin scripts', function () {
15 let server: PeerTubeServer 15 let server: PeerTubeServer
diff --git a/server/tests/cli/print-transcode-command.ts b/server/tests/cli/print-transcode-command.ts
index 0b8629251..27896f031 100644
--- a/server/tests/cli/print-transcode-command.ts
+++ b/server/tests/cli/print-transcode-command.ts
@@ -2,7 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { buildAbsoluteFixturePath, CLICommand } from '@shared/extra-utils' 5import { buildAbsoluteFixturePath } from '@shared/core-utils'
6import { CLICommand } from '@shared/server-commands'
6import { VideoResolution } from '../../../shared/models/videos' 7import { VideoResolution } from '../../../shared/models/videos'
7 8
8const expect = chai.expect 9const expect = chai.expect
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index 2d4c02da7..a723ed8b4 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -4,7 +4,9 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { createFile, readdir } from 'fs-extra' 5import { createFile, readdir } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { buildUUID } from '@server/helpers/uuid' 7import { wait } from '@shared/core-utils'
8import { buildUUID } from '@shared/extra-utils'
9import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
8import { 10import {
9 cleanupTests, 11 cleanupTests,
10 CLICommand, 12 CLICommand,
@@ -15,10 +17,8 @@ import {
15 PeerTubeServer, 17 PeerTubeServer,
16 setAccessTokensToServers, 18 setAccessTokensToServers,
17 setDefaultVideoChannel, 19 setDefaultVideoChannel,
18 wait,
19 waitJobs 20 waitJobs
20} from '@shared/extra-utils' 21} from '@shared/server-commands'
21import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
22 22
23const expect = chai.expect 23const expect = chai.expect
24 24
@@ -36,7 +36,7 @@ async function assertNotExists (server: PeerTubeServer, directory: string, subst
36 } 36 }
37} 37}
38 38
39async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: string) { 39async function assertCountAreOkay (servers: PeerTubeServer[]) {
40 for (const server of servers) { 40 for (const server of servers) {
41 const videosCount = await countFiles(server, 'videos') 41 const videosCount = await countFiles(server, 'videos')
42 expect(videosCount).to.equal(8) 42 expect(videosCount).to.equal(8)
@@ -52,22 +52,16 @@ async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID:
52 52
53 const avatarsCount = await countFiles(server, 'avatars') 53 const avatarsCount = await countFiles(server, 'avatars')
54 expect(avatarsCount).to.equal(2) 54 expect(avatarsCount).to.equal(2)
55 }
56
57 // When we'll prune HLS directories too
58 // const hlsRootCount = await countFiles(servers[1], 'streaming-playlists/hls/')
59 // expect(hlsRootCount).to.equal(2)
60 55
61 // const hlsCount = await countFiles(servers[1], 'streaming-playlists/hls/' + videoServer2UUID) 56 const hlsRootCount = await countFiles(server, 'streaming-playlists/hls')
62 // expect(hlsCount).to.equal(10) 57 expect(hlsRootCount).to.equal(2)
58 }
63} 59}
64 60
65describe('Test prune storage scripts', function () { 61describe('Test prune storage scripts', function () {
66 let servers: PeerTubeServer[] 62 let servers: PeerTubeServer[]
67 const badNames: { [directory: string]: string[] } = {} 63 const badNames: { [directory: string]: string[] } = {}
68 64
69 let videoServer2UUID: string
70
71 before(async function () { 65 before(async function () {
72 this.timeout(120000) 66 this.timeout(120000)
73 67
@@ -77,9 +71,7 @@ describe('Test prune storage scripts', function () {
77 71
78 for (const server of servers) { 72 for (const server of servers) {
79 await server.videos.upload({ attributes: { name: 'video 1' } }) 73 await server.videos.upload({ attributes: { name: 'video 1' } })
80 74 await server.videos.upload({ attributes: { name: 'video 2' } })
81 const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } })
82 if (server.serverNumber === 2) videoServer2UUID = uuid
83 75
84 await server.users.updateMyAvatar({ fixture: 'avatar.png' }) 76 await server.users.updateMyAvatar({ fixture: 'avatar.png' })
85 77
@@ -123,7 +115,7 @@ describe('Test prune storage scripts', function () {
123 }) 115 })
124 116
125 it('Should have the files on the disk', async function () { 117 it('Should have the files on the disk', async function () {
126 await assertCountAreOkay(servers, videoServer2UUID) 118 await assertCountAreOkay(servers)
127 }) 119 })
128 120
129 it('Should create some dirty files', async function () { 121 it('Should create some dirty files', async function () {
@@ -188,27 +180,14 @@ describe('Test prune storage scripts', function () {
188 badNames['avatars'] = [ n1, n2 ] 180 badNames['avatars'] = [ n1, n2 ]
189 } 181 }
190 182
191 // When we'll prune HLS directories too 183 {
192 // { 184 const directory = join('streaming-playlists', 'hls')
193 // const directory = join('streaming-playlists', 'hls') 185 const base = servers[0].servers.buildDirectory(directory)
194 // const base = servers[1].servers.buildDirectory(directory)
195
196 // const n1 = buildUUID()
197 // await createFile(join(base, n1))
198 // badNames[directory] = [ n1 ]
199 // }
200
201 // {
202 // const directory = join('streaming-playlists', 'hls', videoServer2UUID)
203 // const base = servers[1].servers.buildDirectory(directory)
204 // const n1 = buildUUID() + '-240-fragmented-.mp4'
205 // const n2 = buildUUID() + '-master.m3u8'
206
207 // await createFile(join(base, n1))
208 // await createFile(join(base, n2))
209 186
210 // badNames[directory] = [ n1, n2 ] 187 const n1 = buildUUID()
211 // } 188 await createFile(join(base, n1))
189 badNames[directory] = [ n1 ]
190 }
212 } 191 }
213 }) 192 })
214 193
@@ -220,7 +199,7 @@ describe('Test prune storage scripts', function () {
220 }) 199 })
221 200
222 it('Should have removed files', async function () { 201 it('Should have removed files', async function () {
223 await assertCountAreOkay(servers, videoServer2UUID) 202 await assertCountAreOkay(servers)
224 203
225 for (const directory of Object.keys(badNames)) { 204 for (const directory of Object.keys(badNames)) {
226 for (const name of badNames[directory]) { 205 for (const name of badNames[directory]) {
diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts
index 780c9b4bd..98d15272a 100644
--- a/server/tests/cli/regenerate-thumbnails.ts
+++ b/server/tests/cli/regenerate-thumbnails.ts
@@ -11,7 +11,7 @@ import {
11 PeerTubeServer, 11 PeerTubeServer,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 waitJobs 13 waitJobs
14} from '../../../shared/extra-utils' 14} from '../../../shared/server-commands'
15 15
16async function testThumbnail (server: PeerTubeServer, videoId: number | string) { 16async function testThumbnail (server: PeerTubeServer, videoId: number | string) {
17 const video = await server.videos.get({ id: videoId }) 17 const video = await server.videos.get({ id: videoId })
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts
index 4a02db35d..018e9d788 100644
--- a/server/tests/cli/reset-password.ts
+++ b/server/tests/cli/reset-password.ts
@@ -1,5 +1,5 @@
1import 'mocha' 1import 'mocha'
2import { cleanupTests, CLICommand, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '../../../shared/extra-utils' 2import { cleanupTests, CLICommand, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
3 3
4describe('Test reset password scripts', function () { 4describe('Test reset password scripts', function () {
5 let server: PeerTubeServer 5 let server: PeerTubeServer
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts
index 43fbaec30..da89ff153 100644
--- a/server/tests/cli/update-host.ts
+++ b/server/tests/cli/update-host.ts
@@ -11,7 +11,7 @@ import {
11 PeerTubeServer, 11 PeerTubeServer,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 waitJobs 13 waitJobs
14} from '@shared/extra-utils' 14} from '@shared/server-commands'
15 15
16describe('Test update host scripts', function () { 16describe('Test update host scripts', function () {
17 let server: PeerTubeServer 17 let server: PeerTubeServer
diff --git a/server/tests/client.ts b/server/tests/client.ts
index a91bec906..fe048d7ff 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -14,7 +14,7 @@ import {
14 setAccessTokensToServers, 14 setAccessTokensToServers,
15 setDefaultVideoChannel, 15 setDefaultVideoChannel,
16 waitJobs 16 waitJobs
17} from '../../shared/extra-utils' 17} from '../../shared/server-commands'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
diff --git a/server/tests/external-plugins/auth-ldap.ts b/server/tests/external-plugins/auth-ldap.ts
index acec69df5..326453a5f 100644
--- a/server/tests/external-plugins/auth-ldap.ts
+++ b/server/tests/external-plugins/auth-ldap.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 5import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
6import { HttpStatusCode } from '@shared/models' 6import { HttpStatusCode } from '@shared/models'
7 7
8describe('Official plugin auth-ldap', function () { 8describe('Official plugin auth-ldap', function () {
diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts
index 0eb4bda9a..bc5c93621 100644
--- a/server/tests/external-plugins/auto-block-videos.ts
+++ b/server/tests/external-plugins/auto-block-videos.ts
@@ -2,17 +2,17 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { wait } from '@shared/core-utils'
6import { Video } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
8 doubleFollow, 10 doubleFollow,
9 killallServers, 11 killallServers,
10 MockBlocklist,
11 PeerTubeServer, 12 PeerTubeServer,
12 setAccessTokensToServers, 13 setAccessTokensToServers
13 wait 14} from '@shared/server-commands'
14} from '@shared/extra-utils' 15import { MockBlocklist } from '../shared'
15import { Video } from '@shared/models'
16 16
17async function check (server: PeerTubeServer, videoUUID: string, exists = true) { 17async function check (server: PeerTubeServer, videoUUID: string, exists = true) {
18 const { data } = await server.videos.list() 18 const { data } = await server.videos.list()
diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts
index 271779dd4..375ccf91a 100644
--- a/server/tests/external-plugins/auto-mute.ts
+++ b/server/tests/external-plugins/auto-mute.ts
@@ -2,18 +2,18 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { wait } from '@shared/core-utils'
6import { HttpStatusCode } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createMultipleServers, 9 createMultipleServers,
8 doubleFollow, 10 doubleFollow,
9 killallServers, 11 killallServers,
10 makeGetRequest, 12 makeGetRequest,
11 MockBlocklist,
12 PeerTubeServer, 13 PeerTubeServer,
13 setAccessTokensToServers, 14 setAccessTokensToServers
14 wait 15} from '@shared/server-commands'
15} from '@shared/extra-utils' 16import { MockBlocklist } from '../shared'
16import { HttpStatusCode } from '@shared/models'
17 17
18describe('Official plugin auto-mute', function () { 18describe('Official plugin auto-mute', function () {
19 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' 19 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index a1c976fd3..24a518342 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { parse, validate } from 'fast-xml-parser' 5import { XMLParser, XMLValidator } from 'fast-xml-parser'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createMultipleServers, 8 createMultipleServers,
@@ -12,7 +12,7 @@ import {
12 PeerTubeServer, 12 PeerTubeServer,
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 waitJobs 14 waitJobs
15} from '@shared/extra-utils' 15} from '@shared/server-commands'
16import { HttpStatusCode, VideoPrivacy } from '@shared/models' 16import { HttpStatusCode, VideoPrivacy } from '@shared/models'
17 17
18chai.use(require('chai-xml')) 18chai.use(require('chai-xml'))
@@ -149,9 +149,10 @@ describe('Test syndication feeds', () => {
149 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () { 149 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
150 for (const server of servers) { 150 for (const server of servers) {
151 const rss = await server.feed.getXML({ feed: 'videos' }) 151 const rss = await server.feed.getXML({ feed: 'videos' })
152 expect(validate(rss)).to.be.true 152 expect(XMLValidator.validate(rss)).to.be.true
153 153
154 const xmlDoc = parse(rss, { parseAttributeValue: true, ignoreAttributes: false }) 154 const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false })
155 const xmlDoc = parser.parse(rss)
155 156
156 const enclosure = xmlDoc.rss.channel.item[0].enclosure 157 const enclosure = xmlDoc.rss.channel.item[0].enclosure
157 expect(enclosure).to.exist 158 expect(enclosure).to.exist
diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js
index b9b207b81..bff42ff40 100644
--- a/server/tests/fixtures/peertube-plugin-test-four/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-four/main.js
@@ -104,6 +104,20 @@ async function register ({
104 isUser 104 isUser
105 }) 105 })
106 }) 106 })
107
108 router.get('/video-files/:id', async (req, res) => {
109 const details = await peertubeHelpers.videos.getFiles(req.params.id)
110 if (!details) return res.sendStatus(404)
111
112 return res.json(details)
113 })
114
115 router.get('/ffprobe', async (req, res) => {
116 const result = await peertubeHelpers.videos.ffprobe(req.query.path)
117 if (!result) return res.sendStatus(404)
118
119 return res.json(result)
120 })
107 } 121 }
108 122
109} 123}
diff --git a/server/tests/fixtures/peertube-plugin-test-six/main.js b/server/tests/fixtures/peertube-plugin-test-six/main.js
index 858bdb2df..243b041e7 100644
--- a/server/tests/fixtures/peertube-plugin-test-six/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-six/main.js
@@ -11,9 +11,14 @@ async function register ({
11 { 11 {
12 await storageManager.storeData('superkey', { value: 'toto' }) 12 await storageManager.storeData('superkey', { value: 'toto' })
13 await storageManager.storeData('anotherkey', { value: 'toto2' }) 13 await storageManager.storeData('anotherkey', { value: 'toto2' })
14 await storageManager.storeData('storedArrayKey', ['toto', 'toto2'])
14 15
15 const result = await storageManager.getData('superkey') 16 const result = await storageManager.getData('superkey')
16 logger.info('superkey stored value is %s', result.value) 17 logger.info('superkey stored value is %s', result.value)
18
19 const storedArrayValue = await storageManager.getData('storedArrayKey')
20 logger.info('storedArrayKey isArray is %s', Array.isArray(storedArrayValue) ? 'true' : 'false')
21 logger.info('storedArrayKey stored value is %s', storedArrayValue.join(', '))
17 } 22 }
18 23
19 { 24 {
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index db405ff31..90951d611 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -13,6 +13,9 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
13 'action:api.video-comment-reply.created', 13 'action:api.video-comment-reply.created',
14 'action:api.video-comment.deleted', 14 'action:api.video-comment.deleted',
15 15
16 'action:api.video-caption.created',
17 'action:api.video-caption.deleted',
18
16 'action:api.user.blocked', 19 'action:api.user.blocked',
17 'action:api.user.unblocked', 20 'action:api.user.unblocked',
18 'action:api.user.registered', 21 'action:api.user.registered',
@@ -233,6 +236,28 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
233 } 236 }
234 }) 237 })
235 238
239 registerHook({
240 target: 'filter:api.server.stats.get.result',
241 handler: (result) => {
242 return { ...result, customStats: 14 }
243 }
244 })
245
246 // Upload/import/live attributes
247 for (const target of [
248 'filter:api.video.upload.video-attribute.result',
249 'filter:api.video.import-url.video-attribute.result',
250 'filter:api.video.import-torrent.video-attribute.result',
251 'filter:api.video.live.video-attribute.result'
252 ]) {
253 registerHook({
254 target,
255 handler: (result) => {
256 return { ...result, description: result.description + ' - ' + target }
257 }
258 })
259 }
260
236 { 261 {
237 const filterHooks = [ 262 const filterHooks = [
238 'filter:api.search.videos.local.list.params', 263 'filter:api.search.videos.local.list.params',
diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts
index 9fe9aa4cb..64bd373cc 100644
--- a/server/tests/helpers/image.ts
+++ b/server/tests/helpers/image.ts
@@ -4,8 +4,8 @@ import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { readFile, remove } from 'fs-extra' 5import { readFile, remove } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { buildAbsoluteFixturePath, root } from '@shared/core-utils'
7import { processImage } from '../../../server/helpers/image-utils' 8import { processImage } from '../../../server/helpers/image-utils'
8import { buildAbsoluteFixturePath, root } from '../../../shared/extra-utils'
9 9
10async function checkBuffers (path1: string, path2: string, equals: boolean) { 10async function checkBuffers (path1: string, path2: string, equals: boolean) {
11 const [ buf1, buf2 ] = await Promise.all([ 11 const [ buf1, buf2 ] = await Promise.all([
diff --git a/server/tests/helpers/request.ts b/server/tests/helpers/request.ts
index 6edbf2a76..de507ba35 100644
--- a/server/tests/helpers/request.ts
+++ b/server/tests/helpers/request.ts
@@ -4,9 +4,9 @@ import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { pathExists, remove } from 'fs-extra' 5import { pathExists, remove } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { Mock429 } from '@shared/extra-utils/mock-servers/mock-429' 7import { root, wait } from '@shared/core-utils'
8import { FIXTURE_URLS, root, wait } from '../../../shared/extra-utils'
9import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' 8import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
9import { FIXTURE_URLS, Mock429 } from '../shared'
10 10
11describe('Request helpers', function () { 11describe('Request helpers', function () {
12 const destPath1 = join(root(), 'test-output-1.txt') 12 const destPath1 = join(root(), 'test-output-1.txt')
diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts
index 4968eef08..876546d89 100644
--- a/server/tests/misc-endpoints.ts
+++ b/server/tests/misc-endpoints.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 5import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
6import { HttpStatusCode, VideoPrivacy } from '@shared/models' 6import { HttpStatusCode, VideoPrivacy } from '@shared/models'
7 7
8const expect = chai.expect 8const expect = chai.expect
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index 4c1bc7d06..8788a9644 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -9,7 +9,7 @@ import {
9 PluginsCommand, 9 PluginsCommand,
10 setAccessTokensToServers, 10 setAccessTokensToServers,
11 setDefaultVideoChannel 11 setDefaultVideoChannel
12} from '@shared/extra-utils' 12} from '@shared/server-commands'
13import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' 13import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
14 14
15describe('Test plugin action hooks', function () { 15describe('Test plugin action hooks', function () {
@@ -103,6 +103,20 @@ describe('Test plugin action hooks', function () {
103 }) 103 })
104 }) 104 })
105 105
106 describe('Captions hooks', function () {
107 it('Should run action:api.video-caption.created', async function () {
108 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
109
110 await checkHook('action:api.video-caption.created')
111 })
112
113 it('Should run action:api.video-caption.deleted', async function () {
114 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
115
116 await checkHook('action:api.video-caption.deleted')
117 })
118 })
119
106 describe('Users hooks', function () { 120 describe('Users hooks', function () {
107 let userId: number 121 let userId: number
108 122
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index f3e018d43..583100671 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -2,16 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { wait } from '@shared/core-utils'
6import { HttpStatusCode, UserRole } from '@shared/models'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
7 createSingleServer, 9 createSingleServer,
8 decodeQueryString, 10 decodeQueryString,
9 PeerTubeServer, 11 PeerTubeServer,
10 PluginsCommand, 12 PluginsCommand,
11 setAccessTokensToServers, 13 setAccessTokensToServers
12 wait 14} from '@shared/server-commands'
13} from '@shared/extra-utils'
14import { HttpStatusCode, UserRole } from '@shared/models'
15 15
16async function loginExternal (options: { 16async function loginExternal (options: {
17 server: PeerTubeServer 17 server: PeerTubeServer
@@ -125,7 +125,7 @@ describe('Test external auth plugins', function () {
125 expectedStatus: HttpStatusCode.BAD_REQUEST_400 125 expectedStatus: HttpStatusCode.BAD_REQUEST_400
126 }) 126 })
127 127
128 await server.servers.waitUntilLog('expired external auth token', 2) 128 await server.servers.waitUntilLog('expired external auth token', 4)
129 }) 129 })
130 130
131 it('Should auto login Cyan, create the user and use the token', async function () { 131 it('Should auto login Cyan, create the user and use the token', async function () {
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index 02915f08c..52ba396e5 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -2,19 +2,19 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 createMultipleServers, 8 createMultipleServers,
8 doubleFollow, 9 doubleFollow,
9 FIXTURE_URLS,
10 makeRawRequest, 10 makeRawRequest,
11 PeerTubeServer, 11 PeerTubeServer,
12 PluginsCommand, 12 PluginsCommand,
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 setDefaultVideoChannel, 14 setDefaultVideoChannel,
15 waitJobs 15 waitJobs
16} from '@shared/extra-utils' 16} from '@shared/server-commands'
17import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' 17import { FIXTURE_URLS } from '../shared'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
@@ -537,6 +537,75 @@ describe('Test plugin filter hooks', function () {
537 }) 537 })
538 }) 538 })
539 539
540 describe('Upload/import/live attributes filters', function () {
541
542 before(async function () {
543 await servers[0].config.enableLive({ transcoding: false, allowReplay: false })
544 await servers[0].config.enableImports()
545 await servers[0].config.disableTranscoding()
546 })
547
548 it('Should run filter:api.video.upload.video-attribute.result', async function () {
549 for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
550 const { id } = await servers[0].videos.upload({ attributes: { name: 'video', description: 'upload' }, mode })
551
552 const video = await servers[0].videos.get({ id })
553 expect(video.description).to.equal('upload - filter:api.video.upload.video-attribute.result')
554 }
555 })
556
557 it('Should run filter:api.video.import-url.video-attribute.result', async function () {
558 const attributes = {
559 name: 'video',
560 description: 'import url',
561 channelId: servers[0].store.channel.id,
562 targetUrl: FIXTURE_URLS.goodVideo,
563 privacy: VideoPrivacy.PUBLIC
564 }
565 const { video: { id } } = await servers[0].imports.importVideo({ attributes })
566
567 const video = await servers[0].videos.get({ id })
568 expect(video.description).to.equal('import url - filter:api.video.import-url.video-attribute.result')
569 })
570
571 it('Should run filter:api.video.import-torrent.video-attribute.result', async function () {
572 const attributes = {
573 name: 'video',
574 description: 'import torrent',
575 channelId: servers[0].store.channel.id,
576 magnetUri: FIXTURE_URLS.magnet,
577 privacy: VideoPrivacy.PUBLIC
578 }
579 const { video: { id } } = await servers[0].imports.importVideo({ attributes })
580
581 const video = await servers[0].videos.get({ id })
582 expect(video.description).to.equal('import torrent - filter:api.video.import-torrent.video-attribute.result')
583 })
584
585 it('Should run filter:api.video.live.video-attribute.result', async function () {
586 const fields = {
587 name: 'live',
588 description: 'live',
589 channelId: servers[0].store.channel.id,
590 privacy: VideoPrivacy.PUBLIC
591 }
592 const { id } = await servers[0].live.create({ fields })
593
594 const video = await servers[0].videos.get({ id })
595 expect(video.description).to.equal('live - filter:api.video.live.video-attribute.result')
596 })
597 })
598
599 describe('Stats filters', function () {
600
601 it('Should run filter:api.server.stats.get.result', async function () {
602 const data = await servers[0].stats.get()
603
604 expect((data as any).customStats).to.equal(14)
605 })
606
607 })
608
540 after(async function () { 609 after(async function () {
541 await cleanupTests(servers) 610 await cleanupTests(servers)
542 }) 611 })
diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts
index 95c0cd687..0a3a9c25f 100644
--- a/server/tests/plugins/html-injection.ts
+++ b/server/tests/plugins/html-injection.ts
@@ -9,7 +9,7 @@ import {
9 PeerTubeServer, 9 PeerTubeServer,
10 PluginsCommand, 10 PluginsCommand,
11 setAccessTokensToServers 11 setAccessTokensToServers
12} from '../../../shared/extra-utils' 12} from '@shared/server-commands'
13 13
14const expect = chai.expect 14const expect = chai.expect
15 15
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index fde0166f9..e72046ce2 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers, wait } from '@shared/extra-utils' 5import { wait } from '@shared/core-utils'
6import { HttpStatusCode, UserRole } from '@shared/models' 6import { HttpStatusCode, UserRole } from '@shared/models'
7import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/server-commands'
7 8
8describe('Test id and pass auth plugins', function () { 9describe('Test id and pass auth plugins', function () {
9 let server: PeerTubeServer 10 let server: PeerTubeServer
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index 5d16b28a4..167429ef4 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -2,19 +2,21 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { pathExists } from 'fs-extra'
6import { HttpStatusCode, ThumbnailType } from '@shared/models'
5import { 7import {
6 checkVideoFilesWereRemoved,
7 cleanupTests, 8 cleanupTests,
8 createMultipleServers, 9 createMultipleServers,
9 doubleFollow, 10 doubleFollow,
10 makeGetRequest, 11 makeGetRequest,
11 makePostBodyRequest, 12 makePostBodyRequest,
13 makeRawRequest,
12 PeerTubeServer, 14 PeerTubeServer,
13 PluginsCommand, 15 PluginsCommand,
14 setAccessTokensToServers, 16 setAccessTokensToServers,
15 waitJobs 17 waitJobs
16} from '@shared/extra-utils' 18} from '@shared/server-commands'
17import { HttpStatusCode } from '@shared/models' 19import { checkVideoFilesWereRemoved } from '../shared'
18 20
19function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) { 21function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) {
20 const body = { command } 22 const body = { command }
@@ -222,10 +224,75 @@ describe('Test plugin helpers', function () {
222 224
223 describe('Videos', function () { 225 describe('Videos', function () {
224 let videoUUID: string 226 let videoUUID: string
227 let videoPath: string
225 228
226 before(async () => { 229 before(async () => {
230 this.timeout(240000)
231
232 await servers[0].config.enableTranscoding()
233
227 const res = await servers[0].videos.quickUpload({ name: 'video1' }) 234 const res = await servers[0].videos.quickUpload({ name: 'video1' })
228 videoUUID = res.uuid 235 videoUUID = res.uuid
236
237 await waitJobs(servers)
238 })
239
240 it('Should get video files', async function () {
241 const { body } = await makeGetRequest({
242 url: servers[0].url,
243 path: '/plugins/test-four/router/video-files/' + videoUUID,
244 expectedStatus: HttpStatusCode.OK_200
245 })
246
247 // Video files check
248 {
249 expect(body.webtorrent.videoFiles).to.be.an('array')
250 expect(body.hls.videoFiles).to.be.an('array')
251
252 for (const resolution of [ 144, 240, 360, 480, 720 ]) {
253 for (const files of [ body.webtorrent.videoFiles, body.hls.videoFiles ]) {
254 const file = files.find(f => f.resolution === resolution)
255 expect(file).to.exist
256
257 expect(file.size).to.be.a('number')
258 expect(file.fps).to.equal(25)
259
260 expect(await pathExists(file.path)).to.be.true
261 await makeRawRequest(file.url, HttpStatusCode.OK_200)
262 }
263 }
264
265 videoPath = body.webtorrent.videoFiles[0].path
266 }
267
268 // Thumbnails check
269 {
270 expect(body.thumbnails).to.be.an('array')
271
272 const miniature = body.thumbnails.find(t => t.type === ThumbnailType.MINIATURE)
273 expect(miniature).to.exist
274 expect(await pathExists(miniature.path)).to.be.true
275 await makeRawRequest(miniature.url, HttpStatusCode.OK_200)
276
277 const preview = body.thumbnails.find(t => t.type === ThumbnailType.PREVIEW)
278 expect(preview).to.exist
279 expect(await pathExists(preview.path)).to.be.true
280 await makeRawRequest(preview.url, HttpStatusCode.OK_200)
281 }
282 })
283
284 it('Should probe a file', async function () {
285 const { body } = await makeGetRequest({
286 url: servers[0].url,
287 path: '/plugins/test-four/router/ffprobe',
288 query: {
289 path: videoPath
290 },
291 expectedStatus: HttpStatusCode.OK_200
292 })
293
294 expect(body.streams).to.be.an('array')
295 expect(body.streams).to.have.lengthOf(2)
229 }) 296 })
230 297
231 it('Should remove a video after a view', async function () { 298 it('Should remove a video after a view', async function () {
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts
index b1ac9e2fe..58629adc7 100644
--- a/server/tests/plugins/plugin-router.ts
+++ b/server/tests/plugins/plugin-router.ts
@@ -10,7 +10,7 @@ import {
10 PeerTubeServer, 10 PeerTubeServer,
11 PluginsCommand, 11 PluginsCommand,
12 setAccessTokensToServers 12 setAccessTokensToServers
13} from '@shared/extra-utils' 13} from '@shared/server-commands'
14import { HttpStatusCode } from '@shared/models' 14import { HttpStatusCode } from '@shared/models'
15 15
16describe('Test plugin helpers', function () { 16describe('Test plugin helpers', function () {
diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts
index e20c36dba..0bfc4fe28 100644
--- a/server/tests/plugins/plugin-storage.ts
+++ b/server/tests/plugins/plugin-storage.ts
@@ -11,7 +11,7 @@ import {
11 PeerTubeServer, 11 PeerTubeServer,
12 PluginsCommand, 12 PluginsCommand,
13 setAccessTokensToServers 13 setAccessTokensToServers
14} from '@shared/extra-utils' 14} from '@shared/server-commands'
15import { HttpStatusCode } from '@shared/models' 15import { HttpStatusCode } from '@shared/models'
16 16
17describe('Test plugin storage', function () { 17describe('Test plugin storage', function () {
@@ -27,10 +27,14 @@ describe('Test plugin storage', function () {
27 }) 27 })
28 28
29 describe('DB storage', function () { 29 describe('DB storage', function () {
30
31 it('Should correctly store a subkey', async function () { 30 it('Should correctly store a subkey', async function () {
32 await server.servers.waitUntilLog('superkey stored value is toto') 31 await server.servers.waitUntilLog('superkey stored value is toto')
33 }) 32 })
33
34 it('Should correctly retrieve an array as array from the storage.', async function () {
35 await server.servers.waitUntilLog('storedArrayKey isArray is true')
36 await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2')
37 })
34 }) 38 })
35 39
36 describe('Disk storage', function () { 40 describe('Disk storage', function () {
diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts
index 93637e3ce..5ab686472 100644
--- a/server/tests/plugins/plugin-transcoding.ts
+++ b/server/tests/plugins/plugin-transcoding.ts
@@ -12,7 +12,7 @@ import {
12 setDefaultVideoChannel, 12 setDefaultVideoChannel,
13 testFfmpegStreamError, 13 testFfmpegStreamError,
14 waitJobs 14 waitJobs
15} from '@shared/extra-utils' 15} from '@shared/server-commands'
16import { VideoPrivacy } from '@shared/models' 16import { VideoPrivacy } from '@shared/models'
17 17
18async function createLiveWrapper (server: PeerTubeServer) { 18async function createLiveWrapper (server: PeerTubeServer) {
diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts
index 6bf2fda9b..a94b83695 100644
--- a/server/tests/plugins/plugin-unloading.ts
+++ b/server/tests/plugins/plugin-unloading.ts
@@ -9,7 +9,7 @@ import {
9 PeerTubeServer, 9 PeerTubeServer,
10 PluginsCommand, 10 PluginsCommand,
11 setAccessTokensToServers 11 setAccessTokensToServers
12} from '@shared/extra-utils' 12} from '@shared/server-commands'
13import { HttpStatusCode } from '@shared/models' 13import { HttpStatusCode } from '@shared/models'
14 14
15describe('Test plugins module unloading', function () { 15describe('Test plugins module unloading', function () {
diff --git a/server/tests/plugins/translations.ts b/server/tests/plugins/translations.ts
index 8b25c6b75..0b6e5793d 100644
--- a/server/tests/plugins/translations.ts
+++ b/server/tests/plugins/translations.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/extra-utils' 5import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/server-commands'
6 6
7const expect = chai.expect 7const expect = chai.expect
8 8
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts
index 19cba6c2c..6dce6922f 100644
--- a/server/tests/plugins/video-constants.ts
+++ b/server/tests/plugins/video-constants.ts
@@ -9,7 +9,7 @@ import {
9 PeerTubeServer, 9 PeerTubeServer,
10 PluginsCommand, 10 PluginsCommand,
11 setAccessTokensToServers 11 setAccessTokensToServers
12} from '@shared/extra-utils' 12} from '@shared/server-commands'
13import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' 13import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
14 14
15const expect = chai.expect 15const expect = chai.expect
diff --git a/server/tests/register.ts b/server/tests/register.ts
deleted file mode 100644
index af6c8c644..000000000
--- a/server/tests/register.ts
+++ /dev/null
@@ -1,3 +0,0 @@
1import { registerTSPaths } from '../helpers/register-ts-paths'
2
3registerTSPaths()
diff --git a/server/tests/shared/actors.ts b/server/tests/shared/actors.ts
new file mode 100644
index 000000000..f8f4a5137
--- /dev/null
+++ b/server/tests/shared/actors.ts
@@ -0,0 +1,73 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path'
6import { root } from '@shared/core-utils'
7import { Account, VideoChannel } from '@shared/models'
8import { PeerTubeServer } from '@shared/server-commands'
9
10async function expectChannelsFollows (options: {
11 server: PeerTubeServer
12 handle: string
13 followers: number
14 following: number
15}) {
16 const { server } = options
17 const { data } = await server.channels.list()
18
19 return expectActorFollow({ ...options, data })
20}
21
22async function expectAccountFollows (options: {
23 server: PeerTubeServer
24 handle: string
25 followers: number
26 following: number
27}) {
28 const { server } = options
29 const { data } = await server.accounts.list()
30
31 return expectActorFollow({ ...options, data })
32}
33
34async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
35 const testDirectory = 'test' + serverNumber
36
37 for (const directory of [ 'avatars' ]) {
38 const directoryPath = join(root(), testDirectory, directory)
39
40 const directoryExists = await pathExists(directoryPath)
41 expect(directoryExists).to.be.true
42
43 const files = await readdir(directoryPath)
44 for (const file of files) {
45 expect(file).to.not.contain(filename)
46 }
47 }
48}
49
50export {
51 expectAccountFollows,
52 expectChannelsFollows,
53 checkActorFilesWereRemoved
54}
55
56// ---------------------------------------------------------------------------
57
58function expectActorFollow (options: {
59 server: PeerTubeServer
60 data: (Account | VideoChannel)[]
61 handle: string
62 followers: number
63 following: number
64}) {
65 const { server, data, handle, followers, following } = options
66
67 const actor = data.find(a => a.name + '@' + a.host === handle)
68 const message = `${handle} on ${server.url}`
69
70 expect(actor, message).to.exist
71 expect(actor.followersCount).to.equal(followers, message)
72 expect(actor.followingCount).to.equal(following, message)
73}
diff --git a/server/tests/shared/captions.ts b/server/tests/shared/captions.ts
new file mode 100644
index 000000000..35e722408
--- /dev/null
+++ b/server/tests/shared/captions.ts
@@ -0,0 +1,21 @@
1import { expect } from 'chai'
2import request from 'supertest'
3import { HttpStatusCode } from '@shared/models'
4
5async function testCaptionFile (url: string, captionPath: string, toTest: RegExp | string) {
6 const res = await request(url)
7 .get(captionPath)
8 .expect(HttpStatusCode.OK_200)
9
10 if (toTest instanceof RegExp) {
11 expect(res.text).to.match(toTest)
12 } else {
13 expect(res.text).to.contain(toTest)
14 }
15}
16
17// ---------------------------------------------------------------------------
18
19export {
20 testCaptionFile
21}
diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts
new file mode 100644
index 000000000..9ecc84b5d
--- /dev/null
+++ b/server/tests/shared/checks.ts
@@ -0,0 +1,98 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
2
3import { expect } from 'chai'
4import { pathExists, readFile } from 'fs-extra'
5import { join } from 'path'
6import { root } from '@shared/core-utils'
7import { HttpStatusCode } from '@shared/models'
8import { makeGetRequest, PeerTubeServer } from '@shared/server-commands'
9
10// Default interval -> 5 minutes
11function dateIsValid (dateString: string, interval = 300000) {
12 const dateToCheck = new Date(dateString)
13 const now = new Date()
14
15 return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval
16}
17
18function expectStartWith (str: string, start: string) {
19 expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.true
20}
21
22async function expectLogDoesNotContain (server: PeerTubeServer, str: string) {
23 const content = await server.servers.getLogContent()
24
25 expect(content.toString()).to.not.contain(str)
26}
27
28async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
29 const res = await makeGetRequest({
30 url,
31 path: imagePath,
32 expectedStatus: HttpStatusCode.OK_200
33 })
34
35 const body = res.body
36
37 const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension))
38 const minLength = body.length - ((30 * body.length) / 100)
39 const maxLength = body.length + ((30 * body.length) / 100)
40
41 expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture')
42 expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture')
43}
44
45async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) {
46 const base = server.servers.buildDirectory(directory)
47
48 expect(await pathExists(join(base, filePath))).to.equal(exist)
49}
50
51function checkBadStartPagination (url: string, path: string, token?: string, query = {}) {
52 return makeGetRequest({
53 url,
54 path,
55 token,
56 query: { ...query, start: 'hello' },
57 expectedStatus: HttpStatusCode.BAD_REQUEST_400
58 })
59}
60
61async function checkBadCountPagination (url: string, path: string, token?: string, query = {}) {
62 await makeGetRequest({
63 url,
64 path,
65 token,
66 query: { ...query, count: 'hello' },
67 expectedStatus: HttpStatusCode.BAD_REQUEST_400
68 })
69
70 await makeGetRequest({
71 url,
72 path,
73 token,
74 query: { ...query, count: 2000 },
75 expectedStatus: HttpStatusCode.BAD_REQUEST_400
76 })
77}
78
79function checkBadSortPagination (url: string, path: string, token?: string, query = {}) {
80 return makeGetRequest({
81 url,
82 path,
83 token,
84 query: { ...query, sort: 'hello' },
85 expectedStatus: HttpStatusCode.BAD_REQUEST_400
86 })
87}
88
89export {
90 dateIsValid,
91 testImage,
92 expectLogDoesNotContain,
93 testFileExistsOrNot,
94 expectStartWith,
95 checkBadStartPagination,
96 checkBadCountPagination,
97 checkBadSortPagination
98}
diff --git a/server/tests/shared/directories.ts b/server/tests/shared/directories.ts
new file mode 100644
index 000000000..c7065a767
--- /dev/null
+++ b/server/tests/shared/directories.ts
@@ -0,0 +1,34 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path'
6import { root } from '@shared/core-utils'
7import { PeerTubeServer } from '@shared/server-commands'
8
9async function checkTmpIsEmpty (server: PeerTubeServer) {
10 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])
11
12 if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) {
13 await checkDirectoryIsEmpty(server, 'tmp/hls')
14 }
15}
16
17async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) {
18 const testDirectory = 'test' + server.internalServerNumber
19
20 const directoryPath = join(root(), testDirectory, directory)
21
22 const directoryExists = await pathExists(directoryPath)
23 expect(directoryExists).to.be.true
24
25 const files = await readdir(directoryPath)
26 const filtered = files.filter(f => exceptions.includes(f) === false)
27
28 expect(filtered).to.have.lengthOf(0)
29}
30
31export {
32 checkTmpIsEmpty,
33 checkDirectoryIsEmpty
34}
diff --git a/server/tests/shared/generate.ts b/server/tests/shared/generate.ts
new file mode 100644
index 000000000..f806df2f5
--- /dev/null
+++ b/server/tests/shared/generate.ts
@@ -0,0 +1,74 @@
1import { expect } from 'chai'
2import ffmpeg from 'fluent-ffmpeg'
3import { ensureDir, pathExists } from 'fs-extra'
4import { dirname } from 'path'
5import { buildAbsoluteFixturePath, getMaxBitrate } from '@shared/core-utils'
6import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '@shared/extra-utils'
7
8async function ensureHasTooBigBitrate (fixturePath: string) {
9 const bitrate = await getVideoFileBitrate(fixturePath)
10 const dataResolution = await getVideoFileResolution(fixturePath)
11 const fps = await getVideoFileFPS(fixturePath)
12
13 const maxBitrate = getMaxBitrate({ ...dataResolution, fps })
14 expect(bitrate).to.be.above(maxBitrate)
15}
16
17async function generateHighBitrateVideo () {
18 const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true)
19
20 await ensureDir(dirname(tempFixturePath))
21
22 const exists = await pathExists(tempFixturePath)
23 if (!exists) {
24 console.log('Generating high bitrate video.')
25
26 // Generate a random, high bitrate video on the fly, so we don't have to include
27 // a large file in the repo. The video needs to have a certain minimum length so
28 // that FFmpeg properly applies bitrate limits.
29 // https://stackoverflow.com/a/15795112
30 return new Promise<string>((res, rej) => {
31 ffmpeg()
32 .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ])
33 .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])
34 .outputOptions([ '-maxrate 10M', '-bufsize 10M' ])
35 .output(tempFixturePath)
36 .on('error', rej)
37 .on('end', () => res(tempFixturePath))
38 .run()
39 })
40 }
41
42 await ensureHasTooBigBitrate(tempFixturePath)
43
44 return tempFixturePath
45}
46
47async function generateVideoWithFramerate (fps = 60) {
48 const tempFixturePath = buildAbsoluteFixturePath(`video_${fps}fps.mp4`, true)
49
50 await ensureDir(dirname(tempFixturePath))
51
52 const exists = await pathExists(tempFixturePath)
53 if (!exists) {
54 console.log('Generating video with framerate %d.', fps)
55
56 return new Promise<string>((res, rej) => {
57 ffmpeg()
58 .outputOptions([ '-f rawvideo', '-video_size 1280x720', '-i /dev/urandom' ])
59 .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])
60 .outputOptions([ `-r ${fps}` ])
61 .output(tempFixturePath)
62 .on('error', rej)
63 .on('end', () => res(tempFixturePath))
64 .run()
65 })
66 }
67
68 return tempFixturePath
69}
70
71export {
72 generateHighBitrateVideo,
73 generateVideoWithFramerate
74}
diff --git a/server/tests/shared/index.ts b/server/tests/shared/index.ts
new file mode 100644
index 000000000..47019d6a8
--- /dev/null
+++ b/server/tests/shared/index.ts
@@ -0,0 +1,15 @@
1export * from './mock-servers'
2export * from './actors'
3export * from './captions'
4export * from './checks'
5export * from './directories'
6export * from './generate'
7export * from './live'
8export * from './notifications'
9export * from './playlists'
10export * from './plugins'
11export * from './requests'
12export * from './streaming-playlists'
13export * from './tests'
14export * from './tracker'
15export * from './videos'
diff --git a/server/tests/shared/live.ts b/server/tests/shared/live.ts
new file mode 100644
index 000000000..72e3e27f6
--- /dev/null
+++ b/server/tests/shared/live.ts
@@ -0,0 +1,41 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path'
6import { PeerTubeServer } from '@shared/server-commands'
7
8async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) {
9 const basePath = server.servers.buildDirectory('streaming-playlists')
10 const hlsPath = join(basePath, 'hls', videoUUID)
11
12 if (resolutions.length === 0) {
13 const result = await pathExists(hlsPath)
14 expect(result).to.be.false
15
16 return
17 }
18
19 const files = await readdir(hlsPath)
20
21 // fragmented file and playlist per resolution + master playlist + segments sha256 json file
22 expect(files).to.have.lengthOf(resolutions.length * 2 + 2)
23
24 for (const resolution of resolutions) {
25 const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`))
26 expect(fragmentedFile).to.exist
27
28 const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`))
29 expect(playlistFile).to.exist
30 }
31
32 const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8'))
33 expect(masterPlaylistFile).to.exist
34
35 const shaFile = files.find(f => f.endsWith('-segments-sha256.json'))
36 expect(shaFile).to.exist
37}
38
39export {
40 checkLiveCleanupAfterSave
41}
diff --git a/server/tests/shared/mock-servers/index.ts b/server/tests/shared/mock-servers/index.ts
new file mode 100644
index 000000000..abf4a8203
--- /dev/null
+++ b/server/tests/shared/mock-servers/index.ts
@@ -0,0 +1,7 @@
1export * from './mock-429'
2export * from './mock-email'
3export * from './mock-instances-index'
4export * from './mock-joinpeertube-versions'
5export * from './mock-object-storage'
6export * from './mock-plugin-blocklist'
7export * from './mock-proxy'
diff --git a/server/tests/shared/mock-servers/mock-429.ts b/server/tests/shared/mock-servers/mock-429.ts
new file mode 100644
index 000000000..1fc20b079
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-429.ts
@@ -0,0 +1,33 @@
1import express from 'express'
2import { Server } from 'http'
3import { getPort, randomListen, terminateServer } from './shared'
4
5export class Mock429 {
6 private server: Server
7 private responseSent = false
8
9 async initialize () {
10 const app = express()
11
12 app.get('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
13
14 if (!this.responseSent) {
15 this.responseSent = true
16
17 // Retry after 5 seconds
18 res.header('retry-after', '2')
19 return res.sendStatus(429)
20 }
21
22 return res.sendStatus(200)
23 })
24
25 this.server = await randomListen(app)
26
27 return getPort(this.server)
28 }
29
30 terminate () {
31 return terminateServer(this.server)
32 }
33}
diff --git a/server/tests/shared/mock-servers/mock-email.ts b/server/tests/shared/mock-servers/mock-email.ts
new file mode 100644
index 000000000..c518679c9
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-email.ts
@@ -0,0 +1,62 @@
1import { ChildProcess } from 'child_process'
2import MailDev from '@peertube/maildev'
3import { parallelTests, randomInt } from '@shared/core-utils'
4
5class MockSmtpServer {
6
7 private static instance: MockSmtpServer
8 private started = false
9 private emailChildProcess: ChildProcess
10 private emails: object[]
11
12 private constructor () { }
13
14 collectEmails (emailsCollection: object[]) {
15 return new Promise<number>((res, rej) => {
16 const port = parallelTests() ? randomInt(1000, 2000) : 1025
17 this.emails = emailsCollection
18
19 if (this.started) {
20 return res(undefined)
21 }
22
23 const maildev = new MailDev({
24 ip: '127.0.0.1',
25 smtp: port,
26 disableWeb: true,
27 silent: true
28 })
29
30 maildev.on('new', email => {
31 this.emails.push(email)
32 })
33
34 maildev.listen(err => {
35 if (err) return rej(err)
36
37 this.started = true
38
39 return res(port)
40 })
41 })
42 }
43
44 kill () {
45 if (!this.emailChildProcess) return
46
47 process.kill(this.emailChildProcess.pid)
48
49 this.emailChildProcess = null
50 MockSmtpServer.instance = null
51 }
52
53 static get Instance () {
54 return this.instance || (this.instance = new this())
55 }
56}
57
58// ---------------------------------------------------------------------------
59
60export {
61 MockSmtpServer
62}
diff --git a/server/tests/shared/mock-servers/mock-instances-index.ts b/server/tests/shared/mock-servers/mock-instances-index.ts
new file mode 100644
index 000000000..598b007f1
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-instances-index.ts
@@ -0,0 +1,46 @@
1import express from 'express'
2import { Server } from 'http'
3import { getPort, randomListen, terminateServer } from './shared'
4
5export class MockInstancesIndex {
6 private server: Server
7
8 private readonly indexInstances: { host: string, createdAt: string }[] = []
9
10 async initialize () {
11 const app = express()
12
13 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
14 if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
15
16 return next()
17 })
18
19 app.get('/api/v1/instances/hosts', (req: express.Request, res: express.Response) => {
20 const since = req.query.since
21
22 const filtered = this.indexInstances.filter(i => {
23 if (!since) return true
24
25 return i.createdAt > since
26 })
27
28 return res.json({
29 total: filtered.length,
30 data: filtered
31 })
32 })
33
34 this.server = await randomListen(app)
35
36 return getPort(this.server)
37 }
38
39 addInstance (host: string) {
40 this.indexInstances.push({ host, createdAt: new Date().toISOString() })
41 }
42
43 terminate () {
44 return terminateServer(this.server)
45 }
46}
diff --git a/server/tests/shared/mock-servers/mock-joinpeertube-versions.ts b/server/tests/shared/mock-servers/mock-joinpeertube-versions.ts
new file mode 100644
index 000000000..502f4e2f5
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-joinpeertube-versions.ts
@@ -0,0 +1,34 @@
1import express from 'express'
2import { Server } from 'http'
3import { getPort, randomListen } from './shared'
4
5export class MockJoinPeerTubeVersions {
6 private server: Server
7 private latestVersion: string
8
9 async initialize () {
10 const app = express()
11
12 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
13 if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
14
15 return next()
16 })
17
18 app.get('/versions.json', (req: express.Request, res: express.Response) => {
19 return res.json({
20 peertube: {
21 latestVersion: this.latestVersion
22 }
23 })
24 })
25
26 this.server = await randomListen(app)
27
28 return getPort(this.server)
29 }
30
31 setLatestVersion (latestVersion: string) {
32 this.latestVersion = latestVersion
33 }
34}
diff --git a/server/tests/shared/mock-servers/mock-object-storage.ts b/server/tests/shared/mock-servers/mock-object-storage.ts
new file mode 100644
index 000000000..99d68e014
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-object-storage.ts
@@ -0,0 +1,41 @@
1import express from 'express'
2import got, { RequestError } from 'got'
3import { Server } from 'http'
4import { pipeline } from 'stream'
5import { ObjectStorageCommand } from '@shared/server-commands'
6import { getPort, randomListen, terminateServer } from './shared'
7
8export class MockObjectStorage {
9 private server: Server
10
11 async initialize () {
12 const app = express()
13
14 app.get('/:bucketName/:path(*)', (req: express.Request, res: express.Response, next: express.NextFunction) => {
15 const url = `http://${req.params.bucketName}.${ObjectStorageCommand.getEndpointHost()}/${req.params.path}`
16
17 if (process.env.DEBUG) {
18 console.log('Receiving request on mocked server %s.', req.url)
19 console.log('Proxifying request to %s', url)
20 }
21
22 return pipeline(
23 got.stream(url, { throwHttpErrors: false }),
24 res,
25 (err: RequestError) => {
26 if (!err) return
27
28 console.error('Pipeline failed.', err)
29 }
30 )
31 })
32
33 this.server = await randomListen(app)
34
35 return getPort(this.server)
36 }
37
38 terminate () {
39 return terminateServer(this.server)
40 }
41}
diff --git a/server/tests/shared/mock-servers/mock-plugin-blocklist.ts b/server/tests/shared/mock-servers/mock-plugin-blocklist.ts
new file mode 100644
index 000000000..5d6e01816
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-plugin-blocklist.ts
@@ -0,0 +1,36 @@
1import express, { Request, Response } from 'express'
2import { Server } from 'http'
3import { getPort, randomListen, terminateServer } from './shared'
4
5type BlocklistResponse = {
6 data: {
7 value: string
8 action?: 'add' | 'remove'
9 updatedAt?: string
10 }[]
11}
12
13export class MockBlocklist {
14 private body: BlocklistResponse
15 private server: Server
16
17 async initialize () {
18 const app = express()
19
20 app.get('/blocklist', (req: Request, res: Response) => {
21 return res.json(this.body)
22 })
23
24 this.server = await randomListen(app)
25
26 return getPort(this.server)
27 }
28
29 replace (body: BlocklistResponse) {
30 this.body = body
31 }
32
33 terminate () {
34 return terminateServer(this.server)
35 }
36}
diff --git a/server/tests/shared/mock-servers/mock-proxy.ts b/server/tests/shared/mock-servers/mock-proxy.ts
new file mode 100644
index 000000000..cbc7c4466
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-proxy.ts
@@ -0,0 +1,24 @@
1import { createServer, Server } from 'http'
2import proxy from 'proxy'
3import { getPort, terminateServer } from './shared'
4
5class MockProxy {
6 private server: Server
7
8 initialize () {
9 return new Promise<number>(res => {
10 this.server = proxy(createServer())
11 this.server.listen(0, () => res(getPort(this.server)))
12 })
13 }
14
15 terminate () {
16 return terminateServer(this.server)
17 }
18}
19
20// ---------------------------------------------------------------------------
21
22export {
23 MockProxy
24}
diff --git a/server/tests/shared/mock-servers/shared.ts b/server/tests/shared/mock-servers/shared.ts
new file mode 100644
index 000000000..235642439
--- /dev/null
+++ b/server/tests/shared/mock-servers/shared.ts
@@ -0,0 +1,33 @@
1import { Express } from 'express'
2import { Server } from 'http'
3import { AddressInfo } from 'net'
4
5function randomListen (app: Express) {
6 return new Promise<Server>(res => {
7 const server = app.listen(0, () => res(server))
8 })
9}
10
11function getPort (server: Server) {
12 const address = server.address() as AddressInfo
13
14 return address.port
15}
16
17function terminateServer (server: Server) {
18 if (!server) return Promise.resolve()
19
20 return new Promise<void>((res, rej) => {
21 server.close(err => {
22 if (err) return rej(err)
23
24 return res()
25 })
26 })
27}
28
29export {
30 randomListen,
31 getPort,
32 terminateServer
33}
diff --git a/server/tests/shared/notifications.ts b/server/tests/shared/notifications.ts
new file mode 100644
index 000000000..cdc21fdc8
--- /dev/null
+++ b/server/tests/shared/notifications.ts
@@ -0,0 +1,798 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { inspect } from 'util'
5import {
6 AbuseState,
7 PluginType,
8 UserNotification,
9 UserNotificationSetting,
10 UserNotificationSettingValue,
11 UserNotificationType
12} from '@shared/models'
13import { createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
14import { MockSmtpServer } from './mock-servers'
15
16type CheckerBaseParams = {
17 server: PeerTubeServer
18 emails: any[]
19 socketNotifications: UserNotification[]
20 token: string
21 check?: { web: boolean, mail: boolean }
22}
23
24type CheckerType = 'presence' | 'absence'
25
26function getAllNotificationsSettings (): UserNotificationSetting {
27 return {
28 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
29 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
30 abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
31 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
32 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
33 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
34 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
35 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
36 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
37 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
38 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
39 abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
40 abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
41 autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
42 newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
43 newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
44 }
45}
46
47async function checkNewVideoFromSubscription (options: CheckerBaseParams & {
48 videoName: string
49 shortUUID: string
50 checkType: CheckerType
51}) {
52 const { videoName, shortUUID } = options
53 const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION
54
55 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
56 if (checkType === 'presence') {
57 expect(notification).to.not.be.undefined
58 expect(notification.type).to.equal(notificationType)
59
60 checkVideo(notification.video, videoName, shortUUID)
61 checkActor(notification.video.channel)
62 } else {
63 expect(notification).to.satisfy((n: UserNotification) => {
64 return n === undefined || n.type !== UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION || n.video.name !== videoName
65 })
66 }
67 }
68
69 function emailNotificationFinder (email: object) {
70 const text = email['text']
71 return text.indexOf(shortUUID) !== -1 && text.indexOf('Your subscription') !== -1
72 }
73
74 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
75}
76
77async function checkVideoIsPublished (options: CheckerBaseParams & {
78 videoName: string
79 shortUUID: string
80 checkType: CheckerType
81}) {
82 const { videoName, shortUUID } = options
83 const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED
84
85 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
86 if (checkType === 'presence') {
87 expect(notification).to.not.be.undefined
88 expect(notification.type).to.equal(notificationType)
89
90 checkVideo(notification.video, videoName, shortUUID)
91 checkActor(notification.video.channel)
92 } else {
93 expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName)
94 }
95 }
96
97 function emailNotificationFinder (email: object) {
98 const text: string = email['text']
99 return text.includes(shortUUID) && text.includes('Your video')
100 }
101
102 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
103}
104
105async function checkMyVideoImportIsFinished (options: CheckerBaseParams & {
106 videoName: string
107 shortUUID: string
108 url: string
109 success: boolean
110 checkType: CheckerType
111}) {
112 const { videoName, shortUUID, url, success } = options
113
114 const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR
115
116 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
117 if (checkType === 'presence') {
118 expect(notification).to.not.be.undefined
119 expect(notification.type).to.equal(notificationType)
120
121 expect(notification.videoImport.targetUrl).to.equal(url)
122
123 if (success) checkVideo(notification.videoImport.video, videoName, shortUUID)
124 } else {
125 expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url)
126 }
127 }
128
129 function emailNotificationFinder (email: object) {
130 const text: string = email['text']
131 const toFind = success ? ' finished' : ' error'
132
133 return text.includes(url) && text.includes(toFind)
134 }
135
136 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
137}
138
139async function checkUserRegistered (options: CheckerBaseParams & {
140 username: string
141 checkType: CheckerType
142}) {
143 const { username } = options
144 const notificationType = UserNotificationType.NEW_USER_REGISTRATION
145
146 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
147 if (checkType === 'presence') {
148 expect(notification).to.not.be.undefined
149 expect(notification.type).to.equal(notificationType)
150
151 checkActor(notification.account)
152 expect(notification.account.name).to.equal(username)
153 } else {
154 expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
155 }
156 }
157
158 function emailNotificationFinder (email: object) {
159 const text: string = email['text']
160
161 return text.includes(' registered.') && text.includes(username)
162 }
163
164 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
165}
166
167async function checkNewActorFollow (options: CheckerBaseParams & {
168 followType: 'channel' | 'account'
169 followerName: string
170 followerDisplayName: string
171 followingDisplayName: string
172 checkType: CheckerType
173}) {
174 const { followType, followerName, followerDisplayName, followingDisplayName } = options
175 const notificationType = UserNotificationType.NEW_FOLLOW
176
177 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
178 if (checkType === 'presence') {
179 expect(notification).to.not.be.undefined
180 expect(notification.type).to.equal(notificationType)
181
182 checkActor(notification.actorFollow.follower)
183 expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName)
184 expect(notification.actorFollow.follower.name).to.equal(followerName)
185 expect(notification.actorFollow.follower.host).to.not.be.undefined
186
187 const following = notification.actorFollow.following
188 expect(following.displayName).to.equal(followingDisplayName)
189 expect(following.type).to.equal(followType)
190 } else {
191 expect(notification).to.satisfy(n => {
192 return n.type !== notificationType ||
193 (n.actorFollow.follower.name !== followerName && n.actorFollow.following !== followingDisplayName)
194 })
195 }
196 }
197
198 function emailNotificationFinder (email: object) {
199 const text: string = email['text']
200
201 return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
202 }
203
204 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
205}
206
207async function checkNewInstanceFollower (options: CheckerBaseParams & {
208 followerHost: string
209 checkType: CheckerType
210}) {
211 const { followerHost } = options
212 const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER
213
214 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
215 if (checkType === 'presence') {
216 expect(notification).to.not.be.undefined
217 expect(notification.type).to.equal(notificationType)
218
219 checkActor(notification.actorFollow.follower)
220 expect(notification.actorFollow.follower.name).to.equal('peertube')
221 expect(notification.actorFollow.follower.host).to.equal(followerHost)
222
223 expect(notification.actorFollow.following.name).to.equal('peertube')
224 } else {
225 expect(notification).to.satisfy(n => {
226 return n.type !== notificationType || n.actorFollow.follower.host !== followerHost
227 })
228 }
229 }
230
231 function emailNotificationFinder (email: object) {
232 const text: string = email['text']
233
234 return text.includes('instance has a new follower') && text.includes(followerHost)
235 }
236
237 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
238}
239
240async function checkAutoInstanceFollowing (options: CheckerBaseParams & {
241 followerHost: string
242 followingHost: string
243 checkType: CheckerType
244}) {
245 const { followerHost, followingHost } = options
246 const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
247
248 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
249 if (checkType === 'presence') {
250 expect(notification).to.not.be.undefined
251 expect(notification.type).to.equal(notificationType)
252
253 const following = notification.actorFollow.following
254 checkActor(following)
255 expect(following.name).to.equal('peertube')
256 expect(following.host).to.equal(followingHost)
257
258 expect(notification.actorFollow.follower.name).to.equal('peertube')
259 expect(notification.actorFollow.follower.host).to.equal(followerHost)
260 } else {
261 expect(notification).to.satisfy(n => {
262 return n.type !== notificationType || n.actorFollow.following.host !== followingHost
263 })
264 }
265 }
266
267 function emailNotificationFinder (email: object) {
268 const text: string = email['text']
269
270 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
271 }
272
273 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
274}
275
276async function checkCommentMention (options: CheckerBaseParams & {
277 shortUUID: string
278 commentId: number
279 threadId: number
280 byAccountDisplayName: string
281 checkType: CheckerType
282}) {
283 const { shortUUID, commentId, threadId, byAccountDisplayName } = options
284 const notificationType = UserNotificationType.COMMENT_MENTION
285
286 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
287 if (checkType === 'presence') {
288 expect(notification).to.not.be.undefined
289 expect(notification.type).to.equal(notificationType)
290
291 checkComment(notification.comment, commentId, threadId)
292 checkActor(notification.comment.account)
293 expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
294
295 checkVideo(notification.comment.video, undefined, shortUUID)
296 } else {
297 expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
298 }
299 }
300
301 function emailNotificationFinder (email: object) {
302 const text: string = email['text']
303
304 return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName)
305 }
306
307 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
308}
309
310let lastEmailCount = 0
311
312async function checkNewCommentOnMyVideo (options: CheckerBaseParams & {
313 shortUUID: string
314 commentId: number
315 threadId: number
316 checkType: CheckerType
317}) {
318 const { server, shortUUID, commentId, threadId, checkType, emails } = options
319 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
320
321 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
322 if (checkType === 'presence') {
323 expect(notification).to.not.be.undefined
324 expect(notification.type).to.equal(notificationType)
325
326 checkComment(notification.comment, commentId, threadId)
327 checkActor(notification.comment.account)
328 checkVideo(notification.comment.video, undefined, shortUUID)
329 } else {
330 expect(notification).to.satisfy((n: UserNotification) => {
331 return n === undefined || n.comment === undefined || n.comment.id !== commentId
332 })
333 }
334 }
335
336 const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}`
337
338 function emailNotificationFinder (email: object) {
339 return email['text'].indexOf(commentUrl) !== -1
340 }
341
342 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
343
344 if (checkType === 'presence') {
345 // We cannot detect email duplicates, so check we received another email
346 expect(emails).to.have.length.above(lastEmailCount)
347 lastEmailCount = emails.length
348 }
349}
350
351async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & {
352 shortUUID: string
353 videoName: string
354 checkType: CheckerType
355}) {
356 const { shortUUID, videoName } = options
357 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
358
359 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
360 if (checkType === 'presence') {
361 expect(notification).to.not.be.undefined
362 expect(notification.type).to.equal(notificationType)
363
364 expect(notification.abuse.id).to.be.a('number')
365 checkVideo(notification.abuse.video, videoName, shortUUID)
366 } else {
367 expect(notification).to.satisfy((n: UserNotification) => {
368 return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID
369 })
370 }
371 }
372
373 function emailNotificationFinder (email: object) {
374 const text = email['text']
375 return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
376 }
377
378 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
379}
380
381async function checkNewAbuseMessage (options: CheckerBaseParams & {
382 abuseId: number
383 message: string
384 toEmail: string
385 checkType: CheckerType
386}) {
387 const { abuseId, message, toEmail } = options
388 const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE
389
390 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
391 if (checkType === 'presence') {
392 expect(notification).to.not.be.undefined
393 expect(notification.type).to.equal(notificationType)
394
395 expect(notification.abuse.id).to.equal(abuseId)
396 } else {
397 expect(notification).to.satisfy((n: UserNotification) => {
398 return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId
399 })
400 }
401 }
402
403 function emailNotificationFinder (email: object) {
404 const text = email['text']
405 const to = email['to'].filter(t => t.address === toEmail)
406
407 return text.indexOf(message) !== -1 && to.length !== 0
408 }
409
410 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
411}
412
413async function checkAbuseStateChange (options: CheckerBaseParams & {
414 abuseId: number
415 state: AbuseState
416 checkType: CheckerType
417}) {
418 const { abuseId, state } = options
419 const notificationType = UserNotificationType.ABUSE_STATE_CHANGE
420
421 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
422 if (checkType === 'presence') {
423 expect(notification).to.not.be.undefined
424 expect(notification.type).to.equal(notificationType)
425
426 expect(notification.abuse.id).to.equal(abuseId)
427 expect(notification.abuse.state).to.equal(state)
428 } else {
429 expect(notification).to.satisfy((n: UserNotification) => {
430 return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId
431 })
432 }
433 }
434
435 function emailNotificationFinder (email: object) {
436 const text = email['text']
437
438 const contains = state === AbuseState.ACCEPTED
439 ? ' accepted'
440 : ' rejected'
441
442 return text.indexOf(contains) !== -1
443 }
444
445 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
446}
447
448async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & {
449 shortUUID: string
450 videoName: string
451 checkType: CheckerType
452}) {
453 const { shortUUID, videoName } = options
454 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
455
456 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
457 if (checkType === 'presence') {
458 expect(notification).to.not.be.undefined
459 expect(notification.type).to.equal(notificationType)
460
461 expect(notification.abuse.id).to.be.a('number')
462 checkVideo(notification.abuse.comment.video, videoName, shortUUID)
463 } else {
464 expect(notification).to.satisfy((n: UserNotification) => {
465 return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID
466 })
467 }
468 }
469
470 function emailNotificationFinder (email: object) {
471 const text = email['text']
472 return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
473 }
474
475 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
476}
477
478async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & {
479 displayName: string
480 checkType: CheckerType
481}) {
482 const { displayName } = options
483 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
484
485 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
486 if (checkType === 'presence') {
487 expect(notification).to.not.be.undefined
488 expect(notification.type).to.equal(notificationType)
489
490 expect(notification.abuse.id).to.be.a('number')
491 expect(notification.abuse.account.displayName).to.equal(displayName)
492 } else {
493 expect(notification).to.satisfy((n: UserNotification) => {
494 return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName
495 })
496 }
497 }
498
499 function emailNotificationFinder (email: object) {
500 const text = email['text']
501 return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
502 }
503
504 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
505}
506
507async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & {
508 shortUUID: string
509 videoName: string
510 checkType: CheckerType
511}) {
512 const { shortUUID, videoName } = options
513 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
514
515 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
516 if (checkType === 'presence') {
517 expect(notification).to.not.be.undefined
518 expect(notification.type).to.equal(notificationType)
519
520 expect(notification.videoBlacklist.video.id).to.be.a('number')
521 checkVideo(notification.videoBlacklist.video, videoName, shortUUID)
522 } else {
523 expect(notification).to.satisfy((n: UserNotification) => {
524 return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID
525 })
526 }
527 }
528
529 function emailNotificationFinder (email: object) {
530 const text = email['text']
531 return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
532 }
533
534 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
535}
536
537async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & {
538 shortUUID: string
539 videoName: string
540 blacklistType: 'blacklist' | 'unblacklist'
541}) {
542 const { videoName, shortUUID, blacklistType } = options
543 const notificationType = blacklistType === 'blacklist'
544 ? UserNotificationType.BLACKLIST_ON_MY_VIDEO
545 : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO
546
547 function notificationChecker (notification: UserNotification) {
548 expect(notification).to.not.be.undefined
549 expect(notification.type).to.equal(notificationType)
550
551 const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video
552
553 checkVideo(video, videoName, shortUUID)
554 }
555
556 function emailNotificationFinder (email: object) {
557 const text = email['text']
558 const blacklistText = blacklistType === 'blacklist'
559 ? 'blacklisted'
560 : 'unblacklisted'
561
562 return text.includes(shortUUID) && text.includes(blacklistText)
563 }
564
565 await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' })
566}
567
568async function checkNewPeerTubeVersion (options: CheckerBaseParams & {
569 latestVersion: string
570 checkType: CheckerType
571}) {
572 const { latestVersion } = options
573 const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION
574
575 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
576 if (checkType === 'presence') {
577 expect(notification).to.not.be.undefined
578 expect(notification.type).to.equal(notificationType)
579
580 expect(notification.peertube).to.exist
581 expect(notification.peertube.latestVersion).to.equal(latestVersion)
582 } else {
583 expect(notification).to.satisfy((n: UserNotification) => {
584 return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion
585 })
586 }
587 }
588
589 function emailNotificationFinder (email: object) {
590 const text = email['text']
591
592 return text.includes(latestVersion)
593 }
594
595 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
596}
597
598async function checkNewPluginVersion (options: CheckerBaseParams & {
599 pluginType: PluginType
600 pluginName: string
601 checkType: CheckerType
602}) {
603 const { pluginName, pluginType } = options
604 const notificationType = UserNotificationType.NEW_PLUGIN_VERSION
605
606 function notificationChecker (notification: UserNotification, checkType: CheckerType) {
607 if (checkType === 'presence') {
608 expect(notification).to.not.be.undefined
609 expect(notification.type).to.equal(notificationType)
610
611 expect(notification.plugin.name).to.equal(pluginName)
612 expect(notification.plugin.type).to.equal(pluginType)
613 } else {
614 expect(notification).to.satisfy((n: UserNotification) => {
615 return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName
616 })
617 }
618 }
619
620 function emailNotificationFinder (email: object) {
621 const text = email['text']
622
623 return text.includes(pluginName)
624 }
625
626 await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
627}
628
629async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) {
630 const userNotifications: UserNotification[] = []
631 const adminNotifications: UserNotification[] = []
632 const adminNotificationsServer2: UserNotification[] = []
633 const emails: object[] = []
634
635 const port = await MockSmtpServer.Instance.collectEmails(emails)
636
637 const overrideConfig = {
638 smtp: {
639 hostname: 'localhost',
640 port
641 },
642 signup: {
643 limit: 20
644 }
645 }
646 const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg))
647
648 await setAccessTokensToServers(servers)
649
650 if (serversCount > 1) {
651 await doubleFollow(servers[0], servers[1])
652 }
653
654 const user = { username: 'user_1', password: 'super password' }
655 await servers[0].users.create({ ...user, videoQuota: 10 * 1000 * 1000 })
656 const userAccessToken = await servers[0].login.getAccessToken(user)
657
658 await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
659 await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
660
661 if (serversCount > 1) {
662 await servers[1].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
663 }
664
665 {
666 const socket = servers[0].socketIO.getUserNotificationSocket({ token: userAccessToken })
667 socket.on('new-notification', n => userNotifications.push(n))
668 }
669 {
670 const socket = servers[0].socketIO.getUserNotificationSocket()
671 socket.on('new-notification', n => adminNotifications.push(n))
672 }
673
674 if (serversCount > 1) {
675 const socket = servers[1].socketIO.getUserNotificationSocket()
676 socket.on('new-notification', n => adminNotificationsServer2.push(n))
677 }
678
679 const { videoChannels } = await servers[0].users.getMyInfo()
680 const channelId = videoChannels[0].id
681
682 return {
683 userNotifications,
684 adminNotifications,
685 adminNotificationsServer2,
686 userAccessToken,
687 emails,
688 servers,
689 channelId
690 }
691}
692
693// ---------------------------------------------------------------------------
694
695export {
696 getAllNotificationsSettings,
697
698 CheckerBaseParams,
699 CheckerType,
700 checkMyVideoImportIsFinished,
701 checkUserRegistered,
702 checkAutoInstanceFollowing,
703 checkVideoIsPublished,
704 checkNewVideoFromSubscription,
705 checkNewActorFollow,
706 checkNewCommentOnMyVideo,
707 checkNewBlacklistOnMyVideo,
708 checkCommentMention,
709 checkNewVideoAbuseForModerators,
710 checkVideoAutoBlacklistForModerators,
711 checkNewAbuseMessage,
712 checkAbuseStateChange,
713 checkNewInstanceFollower,
714 prepareNotificationsTest,
715 checkNewCommentAbuseForModerators,
716 checkNewAccountAbuseForModerators,
717 checkNewPeerTubeVersion,
718 checkNewPluginVersion
719}
720
721// ---------------------------------------------------------------------------
722
723async function checkNotification (options: CheckerBaseParams & {
724 notificationChecker: (notification: UserNotification, checkType: CheckerType) => void
725 emailNotificationFinder: (email: object) => boolean
726 checkType: CheckerType
727}) {
728 const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options
729
730 const check = options.check || { web: true, mail: true }
731
732 if (check.web) {
733 const notification = await server.notifications.getLatest({ token: token })
734
735 if (notification || checkType !== 'absence') {
736 notificationChecker(notification, checkType)
737 }
738
739 const socketNotification = socketNotifications.find(n => {
740 try {
741 notificationChecker(n, 'presence')
742 return true
743 } catch {
744 return false
745 }
746 })
747
748 if (checkType === 'presence') {
749 const obj = inspect(socketNotifications, { depth: 5 })
750 expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
751 } else {
752 const obj = inspect(socketNotification, { depth: 5 })
753 expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
754 }
755 }
756
757 if (check.mail) {
758 // Last email
759 const email = emails
760 .slice()
761 .reverse()
762 .find(e => emailNotificationFinder(e))
763
764 if (checkType === 'presence') {
765 const texts = emails.map(e => e.text)
766 expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined
767 } else {
768 expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
769 }
770 }
771}
772
773function checkVideo (video: any, videoName?: string, shortUUID?: string) {
774 if (videoName) {
775 expect(video.name).to.be.a('string')
776 expect(video.name).to.not.be.empty
777 expect(video.name).to.equal(videoName)
778 }
779
780 if (shortUUID) {
781 expect(video.shortUUID).to.be.a('string')
782 expect(video.shortUUID).to.not.be.empty
783 expect(video.shortUUID).to.equal(shortUUID)
784 }
785
786 expect(video.id).to.be.a('number')
787}
788
789function checkActor (actor: any) {
790 expect(actor.displayName).to.be.a('string')
791 expect(actor.displayName).to.not.be.empty
792 expect(actor.host).to.not.be.undefined
793}
794
795function checkComment (comment: any, commentId: number, threadId: number) {
796 expect(comment.id).to.equal(commentId)
797 expect(comment.threadId).to.equal(threadId)
798}
diff --git a/server/tests/shared/playlists.ts b/server/tests/shared/playlists.ts
new file mode 100644
index 000000000..fdd541d20
--- /dev/null
+++ b/server/tests/shared/playlists.ts
@@ -0,0 +1,25 @@
1import { expect } from 'chai'
2import { readdir } from 'fs-extra'
3import { join } from 'path'
4import { root } from '@shared/core-utils'
5
6async function checkPlaylistFilesWereRemoved (
7 playlistUUID: string,
8 internalServerNumber: number,
9 directories = [ 'thumbnails' ]
10) {
11 const testDirectory = 'test' + internalServerNumber
12
13 for (const directory of directories) {
14 const directoryPath = join(root(), testDirectory, directory)
15
16 const files = await readdir(directoryPath)
17 for (const file of files) {
18 expect(file).to.not.contain(playlistUUID)
19 }
20 }
21}
22
23export {
24 checkPlaylistFilesWereRemoved
25}
diff --git a/server/tests/shared/plugins.ts b/server/tests/shared/plugins.ts
new file mode 100644
index 000000000..036fce2ff
--- /dev/null
+++ b/server/tests/shared/plugins.ts
@@ -0,0 +1,18 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { PeerTubeServer } from '@shared/server-commands'
5
6async function testHelloWorldRegisteredSettings (server: PeerTubeServer) {
7 const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' })
8
9 const registeredSettings = body.registeredSettings
10 expect(registeredSettings).to.have.length.at.least(1)
11
12 const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name')
13 expect(adminNameSettings).to.not.be.undefined
14}
15
16export {
17 testHelloWorldRegisteredSettings
18}
diff --git a/server/tests/shared/requests.ts b/server/tests/shared/requests.ts
new file mode 100644
index 000000000..7f1acc0e1
--- /dev/null
+++ b/server/tests/shared/requests.ts
@@ -0,0 +1,41 @@
1import { activityPubContextify } from '@server/helpers/activitypub'
2import { buildDigest } from '@server/helpers/peertube-crypto'
3import { doRequest } from '@server/helpers/requests'
4import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants'
5
6export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
7 const options = {
8 method: 'POST' as 'POST',
9 json: body,
10 httpSignature,
11 headers
12 }
13
14 return doRequest(url, options)
15}
16
17export async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) {
18 const follow = {
19 type: 'Follow',
20 id: by.url + '/' + new Date().getTime(),
21 actor: by.url,
22 object: to.url
23 }
24
25 const body = activityPubContextify(follow)
26
27 const httpSignature = {
28 algorithm: HTTP_SIGNATURE.ALGORITHM,
29 authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
30 keyId: by.url,
31 key: by.privateKey,
32 headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
33 }
34 const headers = {
35 'digest': buildDigest(body),
36 'content-type': 'application/activity+json',
37 'accept': ACTIVITY_PUB.ACCEPT_HEADER
38 }
39
40 return makePOSTAPRequest(to.url + '/inbox', body, httpSignature, headers)
41}
diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts
new file mode 100644
index 000000000..7ca707f2e
--- /dev/null
+++ b/server/tests/shared/streaming-playlists.ts
@@ -0,0 +1,77 @@
1import { expect } from 'chai'
2import { basename } from 'path'
3import { removeFragmentedMP4Ext } from '@shared/core-utils'
4import { sha256 } from '@shared/extra-utils'
5import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models'
6import { PeerTubeServer } from '@shared/server-commands'
7
8async function checkSegmentHash (options: {
9 server: PeerTubeServer
10 baseUrlPlaylist: string
11 baseUrlSegment: string
12 resolution: number
13 hlsPlaylist: VideoStreamingPlaylist
14}) {
15 const { server, baseUrlPlaylist, baseUrlSegment, resolution, hlsPlaylist } = options
16 const command = server.streamingPlaylists
17
18 const file = hlsPlaylist.files.find(f => f.resolution.id === resolution)
19 const videoName = basename(file.fileUrl)
20
21 const playlist = await command.get({ url: `${baseUrlPlaylist}/${removeFragmentedMP4Ext(videoName)}.m3u8` })
22
23 const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist)
24
25 const length = parseInt(matches[1], 10)
26 const offset = parseInt(matches[2], 10)
27 const range = `${offset}-${offset + length - 1}`
28
29 const segmentBody = await command.getSegment({
30 url: `${baseUrlSegment}/${videoName}`,
31 expectedStatus: HttpStatusCode.PARTIAL_CONTENT_206,
32 range: `bytes=${range}`
33 })
34
35 const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url })
36 expect(sha256(segmentBody)).to.equal(shaBody[videoName][range])
37}
38
39async function checkLiveSegmentHash (options: {
40 server: PeerTubeServer
41 baseUrlSegment: string
42 videoUUID: string
43 segmentName: string
44 hlsPlaylist: VideoStreamingPlaylist
45}) {
46 const { server, baseUrlSegment, videoUUID, segmentName, hlsPlaylist } = options
47 const command = server.streamingPlaylists
48
49 const segmentBody = await command.getSegment({ url: `${baseUrlSegment}/${videoUUID}/${segmentName}` })
50 const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url })
51
52 expect(sha256(segmentBody)).to.equal(shaBody[segmentName])
53}
54
55async function checkResolutionsInMasterPlaylist (options: {
56 server: PeerTubeServer
57 playlistUrl: string
58 resolutions: number[]
59}) {
60 const { server, playlistUrl, resolutions } = options
61
62 const masterPlaylist = await server.streamingPlaylists.get({ url: playlistUrl })
63
64 for (const resolution of resolutions) {
65 const reg = new RegExp(
66 '#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',(FRAME-RATE=\\d+,)?CODECS="avc1.64001f,mp4a.40.2"'
67 )
68
69 expect(masterPlaylist).to.match(reg)
70 }
71}
72
73export {
74 checkSegmentHash,
75 checkLiveSegmentHash,
76 checkResolutionsInMasterPlaylist
77}
diff --git a/server/tests/shared/tests.ts b/server/tests/shared/tests.ts
new file mode 100644
index 000000000..3abaf833d
--- /dev/null
+++ b/server/tests/shared/tests.ts
@@ -0,0 +1,37 @@
1const FIXTURE_URLS = {
2 peertube_long: 'https://peertube2.cpy.re/videos/watch/122d093a-1ede-43bd-bd34-59d2931ffc5e',
3 peertube_short: 'https://peertube2.cpy.re/w/3fbif9S3WmtTP8gGsC5HBd',
4
5 youtube: 'https://www.youtube.com/watch?v=msX3jv1XdvM',
6
7 /**
8 * The video is used to check format-selection correctness wrt. HDR,
9 * which brings its own set of oddities outside of a MediaSource.
10 *
11 * The video needs to have the following format_ids:
12 * (which you can check by using `youtube-dl <url> -F`):
13 * - (webm vp9)
14 * - (mp4 avc1)
15 * - (webm vp9.2 HDR)
16 */
17 youtubeHDR: 'https://www.youtube.com/watch?v=RQgnBB9z_N4',
18
19 // eslint-disable-next-line max-len
20 magnet: 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Flazy-static%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4',
21
22 badVideo: 'https://download.cpy.re/peertube/bad_video.mp4',
23 goodVideo: 'https://download.cpy.re/peertube/good_video.mp4',
24 goodVideo720: 'https://download.cpy.re/peertube/good_video_720.mp4',
25
26 file4K: 'https://download.cpy.re/peertube/4k_file.txt'
27}
28
29function buildRequestStub (): any {
30 return { }
31}
32
33export {
34 FIXTURE_URLS,
35
36 buildRequestStub
37}
diff --git a/server/tests/shared/tracker.ts b/server/tests/shared/tracker.ts
new file mode 100644
index 000000000..9c1f0246a
--- /dev/null
+++ b/server/tests/shared/tracker.ts
@@ -0,0 +1,27 @@
1import { expect } from 'chai'
2import { sha1 } from '@shared/extra-utils'
3import { makeGetRequest } from '@shared/server-commands'
4
5async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) {
6 const path = '/tracker/announce'
7
8 const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`)
9
10 // From bittorrent-tracker
11 const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) {
12 return '%' + char.charCodeAt(0).toString(16).toUpperCase()
13 })
14
15 const res = await makeGetRequest({
16 url: serverUrl,
17 path,
18 rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`,
19 expectedStatus: 200
20 })
21
22 expect(res.text).to.not.contain('failure')
23}
24
25export {
26 hlsInfohashExist
27}
diff --git a/server/tests/shared/videos.ts b/server/tests/shared/videos.ts
new file mode 100644
index 000000000..6be094f2b
--- /dev/null
+++ b/server/tests/shared/videos.ts
@@ -0,0 +1,251 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
2
3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra'
5import { basename, join } from 'path'
6import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '@server/initializers/constants'
7import { getLowercaseExtension, uuidRegex } from '@shared/core-utils'
8import { HttpStatusCode, VideoCaption, VideoDetails } from '@shared/models'
9import { makeRawRequest, PeerTubeServer, VideoEdit, waitJobs, webtorrentAdd } from '@shared/server-commands'
10import { dateIsValid, testImage } from './checks'
11
12loadLanguages()
13
14async function completeVideoCheck (
15 server: PeerTubeServer,
16 video: any,
17 attributes: {
18 name: string
19 category: number
20 licence: number
21 language: string
22 nsfw: boolean
23 commentsEnabled: boolean
24 downloadEnabled: boolean
25 description: string
26 publishedAt?: string
27 support: string
28 originallyPublishedAt?: string
29 account: {
30 name: string
31 host: string
32 }
33 isLocal: boolean
34 tags: string[]
35 privacy: number
36 likes?: number
37 dislikes?: number
38 duration: number
39 channel: {
40 displayName: string
41 name: string
42 description: string
43 isLocal: boolean
44 }
45 fixture: string
46 files: {
47 resolution: number
48 size: number
49 }[]
50 thumbnailfile?: string
51 previewfile?: string
52 }
53) {
54 if (!attributes.likes) attributes.likes = 0
55 if (!attributes.dislikes) attributes.dislikes = 0
56
57 const host = new URL(server.url).host
58 const originHost = attributes.account.host
59
60 expect(video.name).to.equal(attributes.name)
61 expect(video.category.id).to.equal(attributes.category)
62 expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc')
63 expect(video.licence.id).to.equal(attributes.licence)
64 expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown')
65 expect(video.language.id).to.equal(attributes.language)
66 expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown')
67 expect(video.privacy.id).to.deep.equal(attributes.privacy)
68 expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
69 expect(video.nsfw).to.equal(attributes.nsfw)
70 expect(video.description).to.equal(attributes.description)
71 expect(video.account.id).to.be.a('number')
72 expect(video.account.host).to.equal(attributes.account.host)
73 expect(video.account.name).to.equal(attributes.account.name)
74 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
75 expect(video.channel.name).to.equal(attributes.channel.name)
76 expect(video.likes).to.equal(attributes.likes)
77 expect(video.dislikes).to.equal(attributes.dislikes)
78 expect(video.isLocal).to.equal(attributes.isLocal)
79 expect(video.duration).to.equal(attributes.duration)
80 expect(video.url).to.contain(originHost)
81 expect(dateIsValid(video.createdAt)).to.be.true
82 expect(dateIsValid(video.publishedAt)).to.be.true
83 expect(dateIsValid(video.updatedAt)).to.be.true
84
85 if (attributes.publishedAt) {
86 expect(video.publishedAt).to.equal(attributes.publishedAt)
87 }
88
89 if (attributes.originallyPublishedAt) {
90 expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt)
91 } else {
92 expect(video.originallyPublishedAt).to.be.null
93 }
94
95 const videoDetails = await server.videos.get({ id: video.uuid })
96
97 expect(videoDetails.files).to.have.lengthOf(attributes.files.length)
98 expect(videoDetails.tags).to.deep.equal(attributes.tags)
99 expect(videoDetails.account.name).to.equal(attributes.account.name)
100 expect(videoDetails.account.host).to.equal(attributes.account.host)
101 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
102 expect(video.channel.name).to.equal(attributes.channel.name)
103 expect(videoDetails.channel.host).to.equal(attributes.account.host)
104 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal)
105 expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true
106 expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true
107 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
108 expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled)
109
110 for (const attributeFile of attributes.files) {
111 const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution)
112 expect(file).not.to.be.undefined
113
114 let extension = getLowercaseExtension(attributes.fixture)
115 // Transcoding enabled: extension will always be .mp4
116 if (attributes.files.length > 1) extension = '.mp4'
117
118 expect(file.magnetUri).to.have.lengthOf.above(2)
119
120 expect(file.torrentDownloadUrl).to.match(new RegExp(`http://${host}/download/torrents/${uuidRegex}-${file.resolution.id}.torrent`))
121 expect(file.torrentUrl).to.match(new RegExp(`http://${host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}.torrent`))
122
123 expect(file.fileUrl).to.match(new RegExp(`http://${originHost}/static/webseed/${uuidRegex}-${file.resolution.id}${extension}`))
124 expect(file.fileDownloadUrl).to.match(new RegExp(`http://${originHost}/download/videos/${uuidRegex}-${file.resolution.id}${extension}`))
125
126 await Promise.all([
127 makeRawRequest(file.torrentUrl, 200),
128 makeRawRequest(file.torrentDownloadUrl, 200),
129 makeRawRequest(file.metadataUrl, 200)
130 ])
131
132 expect(file.resolution.id).to.equal(attributeFile.resolution)
133 expect(file.resolution.label).to.equal(attributeFile.resolution + 'p')
134
135 const minSize = attributeFile.size - ((10 * attributeFile.size) / 100)
136 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
137 expect(
138 file.size,
139 'File size for resolution ' + file.resolution.label + ' outside confidence interval (' + minSize + '> size <' + maxSize + ')'
140 ).to.be.above(minSize).and.below(maxSize)
141
142 const torrent = await webtorrentAdd(file.magnetUri, true)
143 expect(torrent.files).to.be.an('array')
144 expect(torrent.files.length).to.equal(1)
145 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
146 }
147
148 expect(videoDetails.thumbnailPath).to.exist
149 await testImage(server.url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath)
150
151 if (attributes.previewfile) {
152 expect(videoDetails.previewPath).to.exist
153 await testImage(server.url, attributes.previewfile, videoDetails.previewPath)
154 }
155}
156
157async function checkVideoFilesWereRemoved (options: {
158 server: PeerTubeServer
159 video: VideoDetails
160 captions?: VideoCaption[]
161 onlyVideoFiles?: boolean // default false
162}) {
163 const { video, server, captions = [], onlyVideoFiles = false } = options
164
165 const webtorrentFiles = video.files || []
166 const hlsFiles = video.streamingPlaylists[0]?.files || []
167
168 const thumbnailName = basename(video.thumbnailPath)
169 const previewName = basename(video.previewPath)
170
171 const torrentNames = webtorrentFiles.concat(hlsFiles).map(f => basename(f.torrentUrl))
172
173 const captionNames = captions.map(c => basename(c.captionPath))
174
175 const webtorrentFilenames = webtorrentFiles.map(f => basename(f.fileUrl))
176 const hlsFilenames = hlsFiles.map(f => basename(f.fileUrl))
177
178 let directories: { [ directory: string ]: string[] } = {
179 videos: webtorrentFilenames,
180 redundancy: webtorrentFilenames,
181 [join('playlists', 'hls')]: hlsFilenames,
182 [join('redundancy', 'hls')]: hlsFilenames
183 }
184
185 if (onlyVideoFiles !== true) {
186 directories = {
187 ...directories,
188
189 thumbnails: [ thumbnailName ],
190 previews: [ previewName ],
191 torrents: torrentNames,
192 captions: captionNames
193 }
194 }
195
196 for (const directory of Object.keys(directories)) {
197 const directoryPath = server.servers.buildDirectory(directory)
198
199 const directoryExists = await pathExists(directoryPath)
200 if (directoryExists === false) continue
201
202 const existingFiles = await readdir(directoryPath)
203 for (const existingFile of existingFiles) {
204 for (const shouldNotExist of directories[directory]) {
205 expect(existingFile, `File ${existingFile} should not exist in ${directoryPath}`).to.not.contain(shouldNotExist)
206 }
207 }
208 }
209}
210
211async function saveVideoInServers (servers: PeerTubeServer[], uuid: string) {
212 for (const server of servers) {
213 server.store.videoDetails = await server.videos.get({ id: uuid })
214 }
215}
216
217function checkUploadVideoParam (
218 server: PeerTubeServer,
219 token: string,
220 attributes: Partial<VideoEdit>,
221 expectedStatus = HttpStatusCode.OK_200,
222 mode: 'legacy' | 'resumable' = 'legacy'
223) {
224 return mode === 'legacy'
225 ? server.videos.buildLegacyUpload({ token, attributes, expectedStatus })
226 : server.videos.buildResumeUpload({ token, attributes, expectedStatus })
227}
228
229// serverNumber starts from 1
230async function uploadRandomVideoOnServers (
231 servers: PeerTubeServer[],
232 serverNumber: number,
233 additionalParams?: VideoEdit & { prefixName?: string }
234) {
235 const server = servers.find(s => s.serverNumber === serverNumber)
236 const res = await server.videos.randomUpload({ wait: false, additionalParams })
237
238 await waitJobs(servers)
239
240 return res
241}
242
243// ---------------------------------------------------------------------------
244
245export {
246 completeVideoCheck,
247 checkUploadVideoParam,
248 uploadRandomVideoOnServers,
249 checkVideoFilesWereRemoved,
250 saveVideoInServers
251}