aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/activitypub/client.ts6
-rw-r--r--server/tests/api/activitypub/fetch.ts10
-rw-r--r--server/tests/api/activitypub/helpers.ts2
-rw-r--r--server/tests/api/activitypub/index.ts2
-rw-r--r--server/tests/api/activitypub/refresher.ts136
-rw-r--r--server/tests/api/activitypub/security.ts13
-rw-r--r--server/tests/api/check-params/accounts.ts17
-rw-r--r--server/tests/api/check-params/blocklist.ts43
-rw-r--r--server/tests/api/check-params/config.ts54
-rw-r--r--server/tests/api/check-params/contact-form.ts30
-rw-r--r--server/tests/api/check-params/debug.ts71
-rw-r--r--server/tests/api/check-params/follows.ts144
-rw-r--r--server/tests/api/check-params/index.ts3
-rw-r--r--server/tests/api/check-params/jobs.ts24
-rw-r--r--server/tests/api/check-params/logs.ts111
-rw-r--r--server/tests/api/check-params/redundancy.ts21
-rw-r--r--server/tests/api/check-params/search.ts21
-rw-r--r--server/tests/api/check-params/services.ts34
-rw-r--r--server/tests/api/check-params/user-notifications.ts30
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts44
-rw-r--r--server/tests/api/check-params/users.ts121
-rw-r--r--server/tests/api/check-params/video-abuses.ts22
-rw-r--r--server/tests/api/check-params/video-blacklist.ts31
-rw-r--r--server/tests/api/check-params/video-captions.ts22
-rw-r--r--server/tests/api/check-params/video-channels.ts25
-rw-r--r--server/tests/api/check-params/video-comments.ts30
-rw-r--r--server/tests/api/check-params/video-imports.ts27
-rw-r--r--server/tests/api/check-params/video-playlists.ts674
-rw-r--r--server/tests/api/check-params/videos-filter.ts72
-rw-r--r--server/tests/api/check-params/videos-history.ts18
-rw-r--r--server/tests/api/check-params/videos.ts92
-rw-r--r--server/tests/api/index-1.ts1
-rw-r--r--server/tests/api/notifications/index.ts1
-rw-r--r--server/tests/api/notifications/user-notifications.ts (renamed from server/tests/api/users/user-notifications.ts)346
-rw-r--r--server/tests/api/redundancy/redundancy.ts272
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts21
-rw-r--r--server/tests/api/search/search-activitypub-videos.ts15
-rw-r--r--server/tests/api/search/search-videos.ts82
-rw-r--r--server/tests/api/server/config.ts50
-rw-r--r--server/tests/api/server/contact-form.ts23
-rw-r--r--server/tests/api/server/email.ts22
-rw-r--r--server/tests/api/server/follow-constraints.ts14
-rw-r--r--server/tests/api/server/follows-moderation.ts195
-rw-r--r--server/tests/api/server/follows.ts29
-rw-r--r--server/tests/api/server/handle-down.ts12
-rw-r--r--server/tests/api/server/index.ts2
-rw-r--r--server/tests/api/server/jobs.ts14
-rw-r--r--server/tests/api/server/logs.ts97
-rw-r--r--server/tests/api/server/no-client.ts19
-rw-r--r--server/tests/api/server/reverse-proxy.ts32
-rw-r--r--server/tests/api/server/stats.ts17
-rw-r--r--server/tests/api/server/tracker.ts42
-rw-r--r--server/tests/api/users/blocklist.ts28
-rw-r--r--server/tests/api/users/index.ts1
-rw-r--r--server/tests/api/users/user-subscriptions.ts15
-rw-r--r--server/tests/api/users/users-multiple-servers.ts35
-rw-r--r--server/tests/api/users/users-verification.ts20
-rw-r--r--server/tests/api/users/users.ts889
-rw-r--r--server/tests/api/videos/index.ts3
-rw-r--r--server/tests/api/videos/multiple-servers.ts41
-rw-r--r--server/tests/api/videos/services.ts18
-rw-r--r--server/tests/api/videos/single-server.ts21
-rw-r--r--server/tests/api/videos/video-abuse.ts9
-rw-r--r--server/tests/api/videos/video-blacklist.ts144
-rw-r--r--server/tests/api/videos/video-captions.ts19
-rw-r--r--server/tests/api/videos/video-change-ownership.ts56
-rw-r--r--server/tests/api/videos/video-channels.ts13
-rw-r--r--server/tests/api/videos/video-comments.ts16
-rw-r--r--server/tests/api/videos/video-description.ts9
-rw-r--r--server/tests/api/videos/video-hls.ts134
-rw-r--r--server/tests/api/videos/video-imports.ts14
-rw-r--r--server/tests/api/videos/video-nsfw.ts27
-rw-r--r--server/tests/api/videos/video-playlists.ts867
-rw-r--r--server/tests/api/videos/video-privacy.ts17
-rw-r--r--server/tests/api/videos/video-schedule-update.ts7
-rw-r--r--server/tests/api/videos/video-transcoder.ts8
-rw-r--r--server/tests/api/videos/videos-filter.ts28
-rw-r--r--server/tests/api/videos/videos-history.ts52
-rw-r--r--server/tests/api/videos/videos-overview.ts15
-rw-r--r--server/tests/api/videos/videos-views-cleaner.ts106
-rw-r--r--server/tests/cli/create-import-video-file-job.ts8
-rw-r--r--server/tests/cli/create-transcoding-job.ts9
-rw-r--r--server/tests/cli/optimize-old-videos.ts11
-rw-r--r--server/tests/cli/peertube.ts14
-rw-r--r--server/tests/cli/reset-password.ts15
-rw-r--r--server/tests/cli/update-host.ts35
-rw-r--r--server/tests/client.ts13
-rw-r--r--server/tests/feeds/feeds.ts16
-rw-r--r--server/tests/fixtures/thumbnail-playlist.jpgbin0 -> 2520 bytes
-rw-r--r--server/tests/helpers/index.ts1
-rw-r--r--server/tests/helpers/request.ts48
-rw-r--r--server/tests/misc-endpoints.ts17
-rw-r--r--server/tests/real-world/populate-database.ts9
-rw-r--r--server/tests/real-world/real-world.ts4
94 files changed, 4639 insertions, 1429 deletions
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts
index 6d90d8643..edf588c16 100644
--- a/server/tests/api/activitypub/client.ts
+++ b/server/tests/api/activitypub/client.ts
@@ -11,7 +11,7 @@ import {
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 uploadVideo 13 uploadVideo
14} from '../../../../shared/utils' 14} from '../../../../shared/extra-utils'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
@@ -22,8 +22,6 @@ describe('Test activitypub', function () {
22 before(async function () { 22 before(async function () {
23 this.timeout(30000) 23 this.timeout(30000)
24 24
25 await flushTests()
26
27 servers = await flushAndRunMultipleServers(2) 25 servers = await flushAndRunMultipleServers(2)
28 26
29 await setAccessTokensToServers(servers) 27 await setAccessTokensToServers(servers)
@@ -61,7 +59,7 @@ describe('Test activitypub', function () {
61 expect(res.header.location).to.equal('http://localhost:9001/videos/watch/' + videoUUID) 59 expect(res.header.location).to.equal('http://localhost:9001/videos/watch/' + videoUUID)
62 }) 60 })
63 61
64 after(async function () { 62 after(function () {
65 killallServers(servers) 63 killallServers(servers)
66 }) 64 })
67}) 65})
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
index 03609c1a9..7240bb0fb 100644
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@ -3,6 +3,7 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 closeAllSequelize,
6 createUser, 7 createUser,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -16,7 +17,7 @@ import {
16 uploadVideo, 17 uploadVideo,
17 userLogin, 18 userLogin,
18 waitJobs 19 waitJobs
19} from '../../../../shared/utils' 20} from '../../../../shared/extra-utils'
20import * as chai from 'chai' 21import * as chai from 'chai'
21import { Video } from '../../../../shared/models/videos' 22import { Video } from '../../../../shared/models/videos'
22 23
@@ -37,7 +38,7 @@ describe('Test ActivityPub fetcher', function () {
37 38
38 const user = { username: 'user1', password: 'password' } 39 const user = { username: 'user1', password: 'password' }
39 for (const server of servers) { 40 for (const server of servers) {
40 await createUser(server.url, server.accessToken, user.username, user.password) 41 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
41 } 42 }
42 43
43 const userAccessToken = await userLogin(servers[0], user) 44 const userAccessToken = await userLogin(servers[0], user)
@@ -79,9 +80,6 @@ describe('Test ActivityPub fetcher', function () {
79 after(async function () { 80 after(async function () {
80 killallServers(servers) 81 killallServers(servers)
81 82
82 // Keep the logs if the test failed 83 await closeAllSequelize(servers)
83 if (this['ok']) {
84 await flushTests()
85 }
86 }) 84 })
87}) 85})
diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts
index ac6e755c3..365d0e1ae 100644
--- a/server/tests/api/activitypub/helpers.ts
+++ b/server/tests/api/activitypub/helpers.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { buildRequestStub } from '../../../../shared/utils/miscs/stubs' 5import { buildRequestStub } from '../../../../shared/extra-utils/miscs/stubs'
6import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' 6import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
7import { cloneDeep } from 'lodash' 7import { cloneDeep } from 'lodash'
8import { buildSignedActivity } from '../../../helpers/activitypub' 8import { buildSignedActivity } from '../../../helpers/activitypub'
diff --git a/server/tests/api/activitypub/index.ts b/server/tests/api/activitypub/index.ts
index 450053309..92bd6f660 100644
--- a/server/tests/api/activitypub/index.ts
+++ b/server/tests/api/activitypub/index.ts
@@ -1,5 +1,5 @@
1import './client' 1import './client'
2import './fetch' 2import './fetch'
3import './helpers'
4import './refresher' 3import './refresher'
4import './helpers'
5import './security' 5import './security'
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index 62ad8a0b5..9be9aa495 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -2,92 +2,158 @@
2 2
3import 'mocha' 3import 'mocha'
4import { 4import {
5 createVideoPlaylist,
5 doubleFollow, 6 doubleFollow,
6 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
8 generateUserAccessToken,
7 getVideo, 9 getVideo,
8 killallServers, 10 getVideoPlaylist,
11 killallServers, rateVideo,
9 reRunServer, 12 reRunServer,
10 ServerInfo, 13 ServerInfo,
11 setAccessTokensToServers, 14 setAccessTokensToServers,
15 setActorField,
16 setDefaultVideoChannel,
17 setPlaylistField,
18 setVideoField,
12 uploadVideo, 19 uploadVideo,
20 uploadVideoAndGetId,
13 wait, 21 wait,
14 setVideoField,
15 waitJobs 22 waitJobs
16} from '../../../../shared/utils' 23} from '../../../../shared/extra-utils'
24import { getAccount } from '../../../../shared/extra-utils/users/accounts'
25import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
17 26
18describe('Test AP refresher', function () { 27describe('Test AP refresher', function () {
19 let servers: ServerInfo[] = [] 28 let servers: ServerInfo[] = []
20 let videoUUID1: string 29 let videoUUID1: string
21 let videoUUID2: string 30 let videoUUID2: string
22 let videoUUID3: string 31 let videoUUID3: string
32 let playlistUUID1: string
33 let playlistUUID2: string
23 34
24 before(async function () { 35 before(async function () {
25 this.timeout(60000) 36 this.timeout(60000)
26 37
27 servers = await flushAndRunMultipleServers(2) 38 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
28 39
29 // Get the access tokens 40 // Get the access tokens
30 await setAccessTokensToServers(servers) 41 await setAccessTokensToServers(servers)
42 await setDefaultVideoChannel(servers)
43
44 {
45 videoUUID1 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video1' })).uuid
46 videoUUID2 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video2' })).uuid
47 videoUUID3 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video3' })).uuid
48 }
31 49
32 { 50 {
33 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) 51 const a1 = await generateUserAccessToken(servers[1], 'user1')
34 videoUUID1 = res.body.video.uuid 52 await uploadVideo(servers[1].url, a1, { name: 'video4' })
53
54 const a2 = await generateUserAccessToken(servers[1], 'user2')
55 await uploadVideo(servers[1].url, a2, { name: 'video5' })
35 } 56 }
36 57
37 { 58 {
38 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) 59 const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
39 videoUUID2 = res.body.video.uuid 60 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs })
61 playlistUUID1 = res.body.videoPlaylist.uuid
40 } 62 }
41 63
42 { 64 {
43 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video3' }) 65 const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
44 videoUUID3 = res.body.video.uuid 66 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs })
67 playlistUUID2 = res.body.videoPlaylist.uuid
45 } 68 }
46 69
47 await doubleFollow(servers[0], servers[1]) 70 await doubleFollow(servers[0], servers[1])
48 }) 71 })
49 72
50 it('Should remove a deleted remote video', async function () { 73 describe('Videos refresher', function () {
51 this.timeout(60000) 74
75 it('Should remove a deleted remote video', async function () {
76 this.timeout(60000)
77
78 await wait(10000)
79
80 // Change UUID so the remote server returns a 404
81 await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
82
83 await getVideo(servers[ 0 ].url, videoUUID1)
84 await getVideo(servers[ 0 ].url, videoUUID2)
85
86 await waitJobs(servers)
52 87
53 await wait(10000) 88 await getVideo(servers[ 0 ].url, videoUUID1, 404)
89 await getVideo(servers[ 0 ].url, videoUUID2, 200)
90 })
54 91
55 // Change UUID so the remote server returns a 404 92 it('Should not update a remote video if the remote instance is down', async function () {
56 await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') 93 this.timeout(60000)
57 94
58 await getVideo(servers[0].url, videoUUID1) 95 killallServers([ servers[ 1 ] ])
59 await getVideo(servers[0].url, videoUUID2)
60 96
61 await waitJobs(servers) 97 await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
62 98
63 await getVideo(servers[0].url, videoUUID1, 404) 99 // Video will need a refresh
64 await getVideo(servers[0].url, videoUUID2, 200) 100 await wait(10000)
101
102 await getVideo(servers[ 0 ].url, videoUUID3)
103 // The refresh should fail
104 await waitJobs([ servers[ 0 ] ])
105
106 await reRunServer(servers[ 1 ])
107
108 // Should not refresh the video, even if the last refresh failed (to avoir a loop on dead instances)
109 await getVideo(servers[ 0 ].url, videoUUID3)
110 await waitJobs(servers)
111
112 await getVideo(servers[ 0 ].url, videoUUID3, 200)
113 })
65 }) 114 })
66 115
67 it('Should not update a remote video if the remote instance is down', async function () { 116 describe('Actors refresher', function () {
68 this.timeout(60000) 117
118 it('Should remove a deleted actor', async function () {
119 this.timeout(60000)
120
121 await wait(10000)
122
123 // Change actor name so the remote server returns a 404
124 await setActorField(2, 'http://localhost:9002/accounts/user2', 'preferredUsername', 'toto')
125
126 await getAccount(servers[ 0 ].url, 'user1@localhost:9002')
127 await getAccount(servers[ 0 ].url, 'user2@localhost:9002')
128
129 await waitJobs(servers)
130
131 await getAccount(servers[ 0 ].url, 'user1@localhost:9002', 200)
132 await getAccount(servers[ 0 ].url, 'user2@localhost:9002', 404)
133 })
134 })
69 135
70 killallServers([ servers[1] ]) 136 describe('Playlist refresher', function () {
71 137
72 await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') 138 it('Should remove a deleted playlist', async function () {
139 this.timeout(60000)
73 140
74 // Video will need a refresh 141 await wait(10000)
75 await wait(10000)
76 142
77 await getVideo(servers[0].url, videoUUID3) 143 // Change UUID so the remote server returns a 404
78 // The refresh should fail 144 await setPlaylistField(2, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
79 await waitJobs([ servers[0] ])
80 145
81 await reRunServer(servers[1]) 146 await getVideoPlaylist(servers[ 0 ].url, playlistUUID1)
147 await getVideoPlaylist(servers[ 0 ].url, playlistUUID2)
82 148
83 // Should not refresh the video, even if the last refresh failed (to avoir a loop on dead instances) 149 await waitJobs(servers)
84 await getVideo(servers[0].url, videoUUID3)
85 await waitJobs(servers)
86 150
87 await getVideo(servers[0].url, videoUUID3, 200) 151 await getVideoPlaylist(servers[ 0 ].url, playlistUUID1, 200)
152 await getVideoPlaylist(servers[ 0 ].url, playlistUUID2, 404)
153 })
88 }) 154 })
89 155
90 after(async function () { 156 after(function () {
91 killallServers(servers) 157 killallServers(servers)
92 }) 158 })
93}) 159})
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts
index 342ae0fa1..11e6859bf 100644
--- a/server/tests/api/activitypub/security.ts
+++ b/server/tests/api/activitypub/security.ts
@@ -3,18 +3,18 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 closeAllSequelize,
6 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
7 flushTests, 8 flushTests,
8 killallServers, 9 killallServers,
9 makeFollowRequest,
10 makePOSTAPRequest,
11 ServerInfo, 10 ServerInfo,
12 setActorField 11 setActorField
13} from '../../../../shared/utils' 12} from '../../../../shared/extra-utils'
14import { HTTP_SIGNATURE } from '../../../initializers' 13import { HTTP_SIGNATURE } from '../../../initializers/constants'
15import { buildDigest, buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils' 14import { buildDigest, buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils'
16import * as chai from 'chai' 15import * as chai from 'chai'
17import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' 16import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub'
17import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub'
18 18
19const expect = chai.expect 19const expect = chai.expect
20 20
@@ -179,9 +179,6 @@ describe('Test ActivityPub security', function () {
179 after(async function () { 179 after(async function () {
180 killallServers(servers) 180 killallServers(servers)
181 181
182 // Keep the logs if the test failed 182 await closeAllSequelize(servers)
183 if (this['ok']) {
184 await flushTests()
185 }
186 }) 183 })
187}) 184})
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts
index 68f9519c6..4f79685bd 100644
--- a/server/tests/api/check-params/accounts.ts
+++ b/server/tests/api/check-params/accounts.ts
@@ -2,13 +2,13 @@
2 2
3import 'mocha' 3import 'mocha'
4 4
5import { flushTests, killallServers, runServer, ServerInfo } from '../../../../shared/utils' 5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
6import { 6import {
7 checkBadCountPagination, 7 checkBadCountPagination,
8 checkBadSortPagination, 8 checkBadSortPagination,
9 checkBadStartPagination 9 checkBadStartPagination
10} from '../../../../shared/utils/requests/check-api-params' 10} from '../../../../shared/extra-utils/requests/check-api-params'
11import { getAccount } from '../../../../shared/utils/users/accounts' 11import { getAccount } from '../../../../shared/extra-utils/users/accounts'
12 12
13describe('Test accounts API validators', function () { 13describe('Test accounts API validators', function () {
14 const path = '/api/v1/accounts/' 14 const path = '/api/v1/accounts/'
@@ -19,9 +19,7 @@ describe('Test accounts API validators', function () {
19 before(async function () { 19 before(async function () {
20 this.timeout(30000) 20 this.timeout(30000)
21 21
22 await flushTests() 22 server = await flushAndRunServer(1)
23
24 server = await runServer(1)
25 }) 23 })
26 24
27 describe('When listing accounts', function () { 25 describe('When listing accounts', function () {
@@ -45,11 +43,6 @@ describe('Test accounts API validators', function () {
45 }) 43 })
46 44
47 after(async function () { 45 after(async function () {
48 killallServers([ server ]) 46 await cleanupTests([ server ])
49
50 // Keep the logs if the test failed
51 if (this['ok']) {
52 await flushTests()
53 }
54 }) 47 })
55}) 48})
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts
index c20453c16..0661676ce 100644
--- a/server/tests/api/check-params/blocklist.ts
+++ b/server/tests/api/check-params/blocklist.ts
@@ -3,22 +3,22 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
9 flushTests,
10 killallServers,
11 makeDeleteRequest, 10 makeDeleteRequest,
12 makeGetRequest, 11 makeGetRequest,
13 makePostBodyRequest, 12 makePostBodyRequest,
14 ServerInfo, 13 ServerInfo,
15 setAccessTokensToServers, userLogin 14 setAccessTokensToServers,
16} from '../../../../shared/utils' 15 userLogin
16} from '../../../../shared/extra-utils'
17import { 17import {
18 checkBadCountPagination, 18 checkBadCountPagination,
19 checkBadSortPagination, 19 checkBadSortPagination,
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22 22
23describe('Test blocklist API validators', function () { 23describe('Test blocklist API validators', function () {
24 let servers: ServerInfo[] 24 let servers: ServerInfo[]
@@ -28,15 +28,13 @@ describe('Test blocklist API validators', function () {
28 before(async function () { 28 before(async function () {
29 this.timeout(60000) 29 this.timeout(60000)
30 30
31 await flushTests()
32
33 servers = await flushAndRunMultipleServers(2) 31 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers) 32 await setAccessTokensToServers(servers)
35 33
36 server = servers[0] 34 server = servers[0]
37 35
38 const user = { username: 'user1', password: 'password' } 36 const user = { username: 'user1', password: 'password' }
39 await createUser(server.url, server.accessToken, user.username, user.password) 37 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
40 38
41 userAccessToken = await userLogin(server, user) 39 userAccessToken = await userLogin(server, user)
42 40
@@ -192,7 +190,7 @@ describe('Test blocklist API validators', function () {
192 url: server.url, 190 url: server.url,
193 token: server.accessToken, 191 token: server.accessToken,
194 path, 192 path,
195 fields: { host: 'localhost:9001' }, 193 fields: { host: 'localhost:' + server.port },
196 statusCodeExpected: 409 194 statusCodeExpected: 409
197 }) 195 })
198 }) 196 })
@@ -202,7 +200,7 @@ describe('Test blocklist API validators', function () {
202 url: server.url, 200 url: server.url,
203 token: server.accessToken, 201 token: server.accessToken,
204 path, 202 path,
205 fields: { host: 'localhost:9002' }, 203 fields: { host: 'localhost:' + servers[1].port },
206 statusCodeExpected: 204 204 statusCodeExpected: 204
207 }) 205 })
208 }) 206 })
@@ -212,7 +210,7 @@ describe('Test blocklist API validators', function () {
212 it('Should fail with an unauthenticated user', async function () { 210 it('Should fail with an unauthenticated user', async function () {
213 await makeDeleteRequest({ 211 await makeDeleteRequest({
214 url: server.url, 212 url: server.url,
215 path: path + '/localhost:9002', 213 path: path + '/localhost:' + servers[1].port,
216 statusCodeExpected: 401 214 statusCodeExpected: 401
217 }) 215 })
218 }) 216 })
@@ -229,7 +227,7 @@ describe('Test blocklist API validators', function () {
229 it('Should succeed with the correct params', async function () { 227 it('Should succeed with the correct params', async function () {
230 await makeDeleteRequest({ 228 await makeDeleteRequest({
231 url: server.url, 229 url: server.url,
232 path: path + '/localhost:9002', 230 path: path + '/localhost:' + servers[1].port,
233 token: server.accessToken, 231 token: server.accessToken,
234 statusCodeExpected: 204 232 statusCodeExpected: 204
235 }) 233 })
@@ -402,7 +400,7 @@ describe('Test blocklist API validators', function () {
402 await makePostBodyRequest({ 400 await makePostBodyRequest({
403 url: server.url, 401 url: server.url,
404 path, 402 path,
405 fields: { host: 'localhost:9002' }, 403 fields: { host: 'localhost:' + servers[1].port },
406 statusCodeExpected: 401 404 statusCodeExpected: 401
407 }) 405 })
408 }) 406 })
@@ -412,7 +410,7 @@ describe('Test blocklist API validators', function () {
412 url: server.url, 410 url: server.url,
413 token: userAccessToken, 411 token: userAccessToken,
414 path, 412 path,
415 fields: { host: 'localhost:9002' }, 413 fields: { host: 'localhost:' + servers[1].port },
416 statusCodeExpected: 403 414 statusCodeExpected: 403
417 }) 415 })
418 }) 416 })
@@ -432,7 +430,7 @@ describe('Test blocklist API validators', function () {
432 url: server.url, 430 url: server.url,
433 token: server.accessToken, 431 token: server.accessToken,
434 path, 432 path,
435 fields: { host: 'localhost:9001' }, 433 fields: { host: 'localhost:' + server.port },
436 statusCodeExpected: 409 434 statusCodeExpected: 409
437 }) 435 })
438 }) 436 })
@@ -442,7 +440,7 @@ describe('Test blocklist API validators', function () {
442 url: server.url, 440 url: server.url,
443 token: server.accessToken, 441 token: server.accessToken,
444 path, 442 path,
445 fields: { host: 'localhost:9002' }, 443 fields: { host: 'localhost:' + servers[1].port },
446 statusCodeExpected: 204 444 statusCodeExpected: 204
447 }) 445 })
448 }) 446 })
@@ -452,7 +450,7 @@ describe('Test blocklist API validators', function () {
452 it('Should fail with an unauthenticated user', async function () { 450 it('Should fail with an unauthenticated user', async function () {
453 await makeDeleteRequest({ 451 await makeDeleteRequest({
454 url: server.url, 452 url: server.url,
455 path: path + '/localhost:9002', 453 path: path + '/localhost:' + servers[1].port,
456 statusCodeExpected: 401 454 statusCodeExpected: 401
457 }) 455 })
458 }) 456 })
@@ -460,7 +458,7 @@ describe('Test blocklist API validators', function () {
460 it('Should fail with a user without the appropriate rights', async function () { 458 it('Should fail with a user without the appropriate rights', async function () {
461 await makeDeleteRequest({ 459 await makeDeleteRequest({
462 url: server.url, 460 url: server.url,
463 path: path + '/localhost:9002', 461 path: path + '/localhost:' + servers[1].port,
464 token: userAccessToken, 462 token: userAccessToken,
465 statusCodeExpected: 403 463 statusCodeExpected: 403
466 }) 464 })
@@ -478,7 +476,7 @@ describe('Test blocklist API validators', function () {
478 it('Should succeed with the correct params', async function () { 476 it('Should succeed with the correct params', async function () {
479 await makeDeleteRequest({ 477 await makeDeleteRequest({
480 url: server.url, 478 url: server.url,
481 path: path + '/localhost:9002', 479 path: path + '/localhost:' + servers[1].port,
482 token: server.accessToken, 480 token: server.accessToken,
483 statusCodeExpected: 204 481 statusCodeExpected: 204
484 }) 482 })
@@ -488,11 +486,6 @@ describe('Test blocklist API validators', function () {
488 }) 486 })
489 487
490 after(async function () { 488 after(async function () {
491 killallServers(servers) 489 await cleanupTests(servers)
492
493 // Keep the logs if the test failed
494 if (this['ok']) {
495 await flushTests()
496 }
497 }) 490 })
498}) 491})
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 4038ecbf0..2a2ec606a 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -5,9 +5,9 @@ import 'mocha'
5import { CustomConfig } from '../../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
6 6
7import { 7import {
8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, 8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, flushAndRunServer, ServerInfo,
9 setAccessTokensToServers, userLogin, immutableAssign 9 setAccessTokensToServers, userLogin, immutableAssign, cleanupTests
10} from '../../../../shared/utils' 10} from '../../../../shared/extra-utils'
11 11
12describe('Test config API validators', function () { 12describe('Test config API validators', function () {
13 const path = '/api/v1/config/custom' 13 const path = '/api/v1/config/custom'
@@ -19,6 +19,7 @@ describe('Test config API validators', function () {
19 shortDescription: 'my short description', 19 shortDescription: 'my short description',
20 description: 'my super description', 20 description: 'my super description',
21 terms: 'my super terms', 21 terms: 'my super terms',
22 isNSFW: true,
22 defaultClientRoute: '/videos/recently-added', 23 defaultClientRoute: '/videos/recently-added',
23 defaultNSFWPolicy: 'blur', 24 defaultNSFWPolicy: 'blur',
24 customizations: { 25 customizations: {
@@ -65,6 +66,9 @@ describe('Test config API validators', function () {
65 '480p': true, 66 '480p': true,
66 '720p': false, 67 '720p': false,
67 '1080p': false 68 '1080p': false
69 },
70 hls: {
71 enabled: false
68 } 72 }
69 }, 73 },
70 import: { 74 import: {
@@ -76,6 +80,19 @@ describe('Test config API validators', function () {
76 enabled: false 80 enabled: false
77 } 81 }
78 } 82 }
83 },
84 autoBlacklist: {
85 videos: {
86 ofUsers: {
87 enabled: false
88 }
89 }
90 },
91 followers: {
92 instance: {
93 enabled: false,
94 manualApproval: true
95 }
79 } 96 }
80 } 97 }
81 98
@@ -84,8 +101,7 @@ describe('Test config API validators', function () {
84 before(async function () { 101 before(async function () {
85 this.timeout(30000) 102 this.timeout(30000)
86 103
87 await flushTests() 104 server = await flushAndRunServer(1)
88 server = await runServer(1)
89 105
90 await setAccessTokensToServers([ server ]) 106 await setAccessTokensToServers([ server ])
91 107
@@ -93,7 +109,7 @@ describe('Test config API validators', function () {
93 username: 'user1', 109 username: 'user1',
94 password: 'password' 110 password: 'password'
95 } 111 }
96 await createUser(server.url, server.accessToken, user.username, user.password) 112 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
97 userAccessToken = await userLogin(server, user) 113 userAccessToken = await userLogin(server, user)
98 }) 114 })
99 115
@@ -164,6 +180,25 @@ describe('Test config API validators', function () {
164 }) 180 })
165 }) 181 })
166 182
183 it('Should fail if email disabled and signup requires email verification', async function () {
184 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
185 const newUpdateParams = immutableAssign(updateParams, {
186 signup: {
187 enabled: true,
188 limit: 5,
189 requiresEmailVerification: true
190 }
191 })
192
193 await makePutBodyRequest({
194 url: server.url,
195 path,
196 fields: newUpdateParams,
197 token: server.accessToken,
198 statusCodeExpected: 400
199 })
200 })
201
167 it('Should success with the correct parameters', async function () { 202 it('Should success with the correct parameters', async function () {
168 await makePutBodyRequest({ 203 await makePutBodyRequest({
169 url: server.url, 204 url: server.url,
@@ -195,11 +230,6 @@ describe('Test config API validators', function () {
195 }) 230 })
196 231
197 after(async function () { 232 after(async function () {
198 killallServers([ server ]) 233 await cleanupTests([ server ])
199
200 // Keep the logs if the test failed
201 if (this['ok']) {
202 await flushTests()
203 }
204 }) 234 })
205}) 235})
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts
index c7e014b1f..dbdd3a8a6 100644
--- a/server/tests/api/check-params/contact-form.ts
+++ b/server/tests/api/check-params/contact-form.ts
@@ -7,18 +7,18 @@ import {
7 immutableAssign, 7 immutableAssign,
8 killallServers, 8 killallServers,
9 reRunServer, 9 reRunServer,
10 runServer, 10 flushAndRunServer,
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers 12 setAccessTokensToServers, cleanupTests
13} from '../../../../shared/utils' 13} from '../../../../shared/extra-utils'
14import { 14import {
15 checkBadCountPagination, 15 checkBadCountPagination,
16 checkBadSortPagination, 16 checkBadSortPagination,
17 checkBadStartPagination 17 checkBadStartPagination
18} from '../../../../shared/utils/requests/check-api-params' 18} from '../../../../shared/extra-utils/requests/check-api-params'
19import { getAccount } from '../../../../shared/utils/users/accounts' 19import { getAccount } from '../../../../shared/extra-utils/users/accounts'
20import { sendContactForm } from '../../../../shared/utils/server/contact-form' 20import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
21import { MockSmtpServer } from '../../../../shared/utils/miscs/email' 21import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
22 22
23describe('Test contact form API validators', function () { 23describe('Test contact form API validators', function () {
24 let server: ServerInfo 24 let server: ServerInfo
@@ -28,17 +28,17 @@ describe('Test contact form API validators', function () {
28 fromEmail: 'toto@example.com', 28 fromEmail: 'toto@example.com',
29 body: 'Hello, how are you?' 29 body: 'Hello, how are you?'
30 } 30 }
31 let emailPort: number
31 32
32 // --------------------------------------------------------------- 33 // ---------------------------------------------------------------
33 34
34 before(async function () { 35 before(async function () {
35 this.timeout(60000) 36 this.timeout(60000)
36 37
37 await flushTests() 38 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
38 await MockSmtpServer.Instance.collectEmails(emails)
39 39
40 // Email is disabled 40 // Email is disabled
41 server = await runServer(1) 41 server = await flushAndRunServer(1)
42 }) 42 })
43 43
44 it('Should not accept a contact form if emails are disabled', async function () { 44 it('Should not accept a contact form if emails are disabled', async function () {
@@ -51,7 +51,7 @@ describe('Test contact form API validators', function () {
51 killallServers([ server ]) 51 killallServers([ server ])
52 52
53 // Contact form is disabled 53 // Contact form is disabled
54 await reRunServer(server, { smtp: { hostname: 'localhost' }, contact_form: { enabled: false } }) 54 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
55 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 })) 55 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 409 }))
56 }) 56 })
57 57
@@ -61,7 +61,7 @@ describe('Test contact form API validators', function () {
61 killallServers([ server ]) 61 killallServers([ server ])
62 62
63 // Email & contact form enabled 63 // Email & contact form enabled
64 await reRunServer(server, { smtp: { hostname: 'localhost' } }) 64 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } })
65 65
66 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' })) 66 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail' }))
67 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' })) 67 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: 400, fromEmail: 'badEmail@' }))
@@ -86,11 +86,7 @@ describe('Test contact form API validators', function () {
86 86
87 after(async function () { 87 after(async function () {
88 MockSmtpServer.Instance.kill() 88 MockSmtpServer.Instance.kill()
89 killallServers([ server ])
90 89
91 // Keep the logs if the test failed 90 await cleanupTests([ server ])
92 if (this['ok']) {
93 await flushTests()
94 }
95 }) 91 })
96}) 92})
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
new file mode 100644
index 000000000..8dad26723
--- /dev/null
+++ b/server/tests/api/check-params/debug.ts
@@ -0,0 +1,71 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 flushTests,
8 killallServers,
9 flushAndRunServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 userLogin, cleanupTests
13} from '../../../../shared/extra-utils'
14import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
15
16describe('Test debug API validators', function () {
17 const path = '/api/v1/server/debug'
18 let server: ServerInfo
19 let userAccessToken = ''
20
21 // ---------------------------------------------------------------
22
23 before(async function () {
24 this.timeout(120000)
25
26 server = await flushAndRunServer(1)
27
28 await setAccessTokensToServers([ server ])
29
30 const user = {
31 username: 'user1',
32 password: 'my super password'
33 }
34 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
35 userAccessToken = await userLogin(server, user)
36 })
37
38 describe('When getting debug endpoint', function () {
39
40 it('Should fail with a non authenticated user', async function () {
41 await makeGetRequest({
42 url: server.url,
43 path,
44 statusCodeExpected: 401
45 })
46 })
47
48 it('Should fail with a non admin user', async function () {
49 await makeGetRequest({
50 url: server.url,
51 path,
52 token: userAccessToken,
53 statusCodeExpected: 403
54 })
55 })
56
57 it('Should succeed with the correct params', async function () {
58 await makeGetRequest({
59 url: server.url,
60 path,
61 token: server.accessToken,
62 query: { startDate: new Date().toISOString() },
63 statusCodeExpected: 200
64 })
65 })
66 })
67
68 after(async function () {
69 await cleanupTests([ server ])
70 })
71})
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 2ad1575a3..2eb54cb0a 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -3,14 +3,20 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, 6 cleanupTests,
7 createUser,
8 flushAndRunServer,
9 makeDeleteRequest,
10 makePostBodyRequest,
11 ServerInfo,
12 setAccessTokensToServers,
7 userLogin 13 userLogin
8} from '../../../../shared/utils' 14} from '../../../../shared/extra-utils'
9import { 15import {
10 checkBadCountPagination, 16 checkBadCountPagination,
11 checkBadSortPagination, 17 checkBadSortPagination,
12 checkBadStartPagination 18 checkBadStartPagination
13} from '../../../../shared/utils/requests/check-api-params' 19} from '../../../../shared/extra-utils/requests/check-api-params'
14 20
15describe('Test server follows API validators', function () { 21describe('Test server follows API validators', function () {
16 let server: ServerInfo 22 let server: ServerInfo
@@ -20,8 +26,7 @@ describe('Test server follows API validators', function () {
20 before(async function () { 26 before(async function () {
21 this.timeout(30000) 27 this.timeout(30000)
22 28
23 await flushTests() 29 server = await flushAndRunServer(1)
24 server = await runServer(1)
25 30
26 await setAccessTokensToServers([ server ]) 31 await setAccessTokensToServers([ server ])
27 }) 32 })
@@ -35,7 +40,7 @@ describe('Test server follows API validators', function () {
35 password: 'password' 40 password: 'password'
36 } 41 }
37 42
38 await createUser(server.url, server.accessToken, user.username, user.password) 43 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
39 userAccessToken = await userLogin(server, user) 44 userAccessToken = await userLogin(server, user)
40 }) 45 })
41 46
@@ -144,6 +149,126 @@ describe('Test server follows API validators', function () {
144 }) 149 })
145 }) 150 })
146 151
152 describe('When removing a follower', function () {
153 const path = '/api/v1/server/followers'
154
155 it('Should fail with an invalid token', async function () {
156 await makeDeleteRequest({
157 url: server.url,
158 path: path + '/toto@localhost:9002',
159 token: 'fake_token',
160 statusCodeExpected: 401
161 })
162 })
163
164 it('Should fail if the user is not an administrator', async function () {
165 await makeDeleteRequest({
166 url: server.url,
167 path: path + '/toto@localhost:9002',
168 token: userAccessToken,
169 statusCodeExpected: 403
170 })
171 })
172
173 it('Should fail with an invalid follower', async function () {
174 await makeDeleteRequest({
175 url: server.url,
176 path: path + '/toto',
177 token: server.accessToken,
178 statusCodeExpected: 400
179 })
180 })
181
182 it('Should fail with an unknown follower', async function () {
183 await makeDeleteRequest({
184 url: server.url,
185 path: path + '/toto@localhost:9003',
186 token: server.accessToken,
187 statusCodeExpected: 404
188 })
189 })
190 })
191
192 describe('When accepting a follower', function () {
193 const path = '/api/v1/server/followers'
194
195 it('Should fail with an invalid token', async function () {
196 await makePostBodyRequest({
197 url: server.url,
198 path: path + '/toto@localhost:9002/accept',
199 token: 'fake_token',
200 statusCodeExpected: 401
201 })
202 })
203
204 it('Should fail if the user is not an administrator', async function () {
205 await makePostBodyRequest({
206 url: server.url,
207 path: path + '/toto@localhost:9002/accept',
208 token: userAccessToken,
209 statusCodeExpected: 403
210 })
211 })
212
213 it('Should fail with an invalid follower', async function () {
214 await makePostBodyRequest({
215 url: server.url,
216 path: path + '/toto/accept',
217 token: server.accessToken,
218 statusCodeExpected: 400
219 })
220 })
221
222 it('Should fail with an unknown follower', async function () {
223 await makePostBodyRequest({
224 url: server.url,
225 path: path + '/toto@localhost:9003/accept',
226 token: server.accessToken,
227 statusCodeExpected: 404
228 })
229 })
230 })
231
232 describe('When rejecting a follower', function () {
233 const path = '/api/v1/server/followers'
234
235 it('Should fail with an invalid token', async function () {
236 await makePostBodyRequest({
237 url: server.url,
238 path: path + '/toto@localhost:9002/reject',
239 token: 'fake_token',
240 statusCodeExpected: 401
241 })
242 })
243
244 it('Should fail if the user is not an administrator', async function () {
245 await makePostBodyRequest({
246 url: server.url,
247 path: path + '/toto@localhost:9002/reject',
248 token: userAccessToken,
249 statusCodeExpected: 403
250 })
251 })
252
253 it('Should fail with an invalid follower', async function () {
254 await makePostBodyRequest({
255 url: server.url,
256 path: path + '/toto/reject',
257 token: server.accessToken,
258 statusCodeExpected: 400
259 })
260 })
261
262 it('Should fail with an unknown follower', async function () {
263 await makePostBodyRequest({
264 url: server.url,
265 path: path + '/toto@localhost:9003/reject',
266 token: server.accessToken,
267 statusCodeExpected: 404
268 })
269 })
270 })
271
147 describe('When removing following', function () { 272 describe('When removing following', function () {
148 const path = '/api/v1/server/following' 273 const path = '/api/v1/server/following'
149 274
@@ -177,11 +302,6 @@ describe('Test server follows API validators', function () {
177 }) 302 })
178 303
179 after(async function () { 304 after(async function () {
180 killallServers([ server ]) 305 await cleanupTests([ server ])
181
182 // Keep the logs if the test failed
183 if (this['ok']) {
184 await flushTests()
185 }
186 }) 306 })
187}) 307})
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 77c17036a..844fa31c5 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -2,8 +2,10 @@ import './accounts'
2import './blocklist' 2import './blocklist'
3import './config' 3import './config'
4import './contact-form' 4import './contact-form'
5import './debug'
5import './follows' 6import './follows'
6import './jobs' 7import './jobs'
8import './logs'
7import './redundancy' 9import './redundancy'
8import './search' 10import './search'
9import './services' 11import './services'
@@ -16,6 +18,7 @@ import './video-captions'
16import './video-channels' 18import './video-channels'
17import './video-comments' 19import './video-comments'
18import './video-imports' 20import './video-imports'
21import './video-playlists'
19import './videos' 22import './videos'
20import './videos-filter' 23import './videos-filter'
21import './videos-history' 24import './videos-history'
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index 89760ff98..c70139514 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -6,17 +6,18 @@ import {
6 createUser, 6 createUser,
7 flushTests, 7 flushTests,
8 killallServers, 8 killallServers,
9 runServer, 9 flushAndRunServer,
10 ServerInfo, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 userLogin 12 userLogin,
13} from '../../../../shared/utils' 13 cleanupTests
14} from '../../../../shared/extra-utils'
14import { 15import {
15 checkBadCountPagination, 16 checkBadCountPagination,
16 checkBadSortPagination, 17 checkBadSortPagination,
17 checkBadStartPagination 18 checkBadStartPagination
18} from '../../../../shared/utils/requests/check-api-params' 19} from '../../../../shared/extra-utils/requests/check-api-params'
19import { makeGetRequest } from '../../../../shared/utils/requests/requests' 20import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
20 21
21describe('Test jobs API validators', function () { 22describe('Test jobs API validators', function () {
22 const path = '/api/v1/jobs/failed' 23 const path = '/api/v1/jobs/failed'
@@ -28,9 +29,7 @@ describe('Test jobs API validators', function () {
28 before(async function () { 29 before(async function () {
29 this.timeout(120000) 30 this.timeout(120000)
30 31
31 await flushTests() 32 server = await flushAndRunServer(1)
32
33 server = await runServer(1)
34 33
35 await setAccessTokensToServers([ server ]) 34 await setAccessTokensToServers([ server ])
36 35
@@ -38,7 +37,7 @@ describe('Test jobs API validators', function () {
38 username: 'user1', 37 username: 'user1',
39 password: 'my super password' 38 password: 'my super password'
40 } 39 }
41 await createUser(server.url, server.accessToken, user.username, user.password) 40 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
42 userAccessToken = await userLogin(server, user) 41 userAccessToken = await userLogin(server, user)
43 }) 42 })
44 43
@@ -83,11 +82,6 @@ describe('Test jobs API validators', function () {
83 }) 82 })
84 83
85 after(async function () { 84 after(async function () {
86 killallServers([ server ]) 85 await cleanupTests([ server ])
87
88 // Keep the logs if the test failed
89 if (this['ok']) {
90 await flushTests()
91 }
92 }) 86 })
93}) 87})
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
new file mode 100644
index 000000000..f9d96bcc0
--- /dev/null
+++ b/server/tests/api/check-params/logs.ts
@@ -0,0 +1,111 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 flushTests,
8 killallServers,
9 flushAndRunServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 userLogin,
13 cleanupTests
14} from '../../../../shared/extra-utils'
15import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
16
17describe('Test logs API validators', function () {
18 const path = '/api/v1/server/logs'
19 let server: ServerInfo
20 let userAccessToken = ''
21
22 // ---------------------------------------------------------------
23
24 before(async function () {
25 this.timeout(120000)
26
27 server = await flushAndRunServer(1)
28
29 await setAccessTokensToServers([ server ])
30
31 const user = {
32 username: 'user1',
33 password: 'my super password'
34 }
35 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
36 userAccessToken = await userLogin(server, user)
37 })
38
39 describe('When getting logs', function () {
40
41 it('Should fail with a non authenticated user', async function () {
42 await makeGetRequest({
43 url: server.url,
44 path,
45 statusCodeExpected: 401
46 })
47 })
48
49 it('Should fail with a non admin user', async function () {
50 await makeGetRequest({
51 url: server.url,
52 path,
53 token: userAccessToken,
54 statusCodeExpected: 403
55 })
56 })
57
58 it('Should fail with a missing startDate query', async function () {
59 await makeGetRequest({
60 url: server.url,
61 path,
62 token: server.accessToken,
63 statusCodeExpected: 400
64 })
65 })
66
67 it('Should fail with a bad startDate query', async function () {
68 await makeGetRequest({
69 url: server.url,
70 path,
71 token: server.accessToken,
72 query: { startDate: 'toto' },
73 statusCodeExpected: 400
74 })
75 })
76
77 it('Should fail with a bad endDate query', async function () {
78 await makeGetRequest({
79 url: server.url,
80 path,
81 token: server.accessToken,
82 query: { startDate: new Date().toISOString(), endDate: 'toto' },
83 statusCodeExpected: 400
84 })
85 })
86
87 it('Should fail with a bad level parameter', async function () {
88 await makeGetRequest({
89 url: server.url,
90 path,
91 token: server.accessToken,
92 query: { startDate: new Date().toISOString(), level: 'toto' },
93 statusCodeExpected: 400
94 })
95 })
96
97 it('Should succeed with the correct params', async function () {
98 await makeGetRequest({
99 url: server.url,
100 path,
101 token: server.accessToken,
102 query: { startDate: new Date().toISOString() },
103 statusCodeExpected: 200
104 })
105 })
106 })
107
108 after(async function () {
109 await cleanupTests([ server ])
110 })
111})
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index ff4726ceb..6471da840 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -3,6 +3,7 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -12,7 +13,7 @@ import {
12 ServerInfo, 13 ServerInfo,
13 setAccessTokensToServers, 14 setAccessTokensToServers,
14 userLogin 15 userLogin
15} from '../../../../shared/utils' 16} from '../../../../shared/extra-utils'
16 17
17describe('Test server redundancy API validators', function () { 18describe('Test server redundancy API validators', function () {
18 let servers: ServerInfo[] 19 let servers: ServerInfo[]
@@ -23,7 +24,6 @@ describe('Test server redundancy API validators', function () {
23 before(async function () { 24 before(async function () {
24 this.timeout(30000) 25 this.timeout(30000)
25 26
26 await flushTests()
27 servers = await flushAndRunMultipleServers(2) 27 servers = await flushAndRunMultipleServers(2)
28 28
29 await setAccessTokensToServers(servers) 29 await setAccessTokensToServers(servers)
@@ -34,7 +34,7 @@ describe('Test server redundancy API validators', function () {
34 password: 'password' 34 password: 'password'
35 } 35 }
36 36
37 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) 37 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
38 userAccessToken = await userLogin(servers[0], user) 38 userAccessToken = await userLogin(servers[0], user)
39 }) 39 })
40 40
@@ -44,7 +44,7 @@ describe('Test server redundancy API validators', function () {
44 it('Should fail with an invalid token', async function () { 44 it('Should fail with an invalid token', async function () {
45 await makePutBodyRequest({ 45 await makePutBodyRequest({
46 url: servers[0].url, 46 url: servers[0].url,
47 path: path + '/localhost:9002', 47 path: path + '/localhost:' + servers[1].port,
48 fields: { redundancyAllowed: true }, 48 fields: { redundancyAllowed: true },
49 token: 'fake_token', 49 token: 'fake_token',
50 statusCodeExpected: 401 50 statusCodeExpected: 401
@@ -54,7 +54,7 @@ describe('Test server redundancy API validators', function () {
54 it('Should fail if the user is not an administrator', async function () { 54 it('Should fail if the user is not an administrator', async function () {
55 await makePutBodyRequest({ 55 await makePutBodyRequest({
56 url: servers[0].url, 56 url: servers[0].url,
57 path: path + '/localhost:9002', 57 path: path + '/localhost:' + servers[1].port,
58 fields: { redundancyAllowed: true }, 58 fields: { redundancyAllowed: true },
59 token: userAccessToken, 59 token: userAccessToken,
60 statusCodeExpected: 403 60 statusCodeExpected: 403
@@ -74,7 +74,7 @@ describe('Test server redundancy API validators', function () {
74 it('Should fail without de redundancyAllowed param', async function () { 74 it('Should fail without de redundancyAllowed param', async function () {
75 await makePutBodyRequest({ 75 await makePutBodyRequest({
76 url: servers[0].url, 76 url: servers[0].url,
77 path: path + '/localhost:9002', 77 path: path + '/localhost:' + servers[1].port,
78 fields: { blabla: true }, 78 fields: { blabla: true },
79 token: servers[0].accessToken, 79 token: servers[0].accessToken,
80 statusCodeExpected: 400 80 statusCodeExpected: 400
@@ -84,7 +84,7 @@ describe('Test server redundancy API validators', function () {
84 it('Should succeed with the correct parameters', async function () { 84 it('Should succeed with the correct parameters', async function () {
85 await makePutBodyRequest({ 85 await makePutBodyRequest({
86 url: servers[0].url, 86 url: servers[0].url,
87 path: path + '/localhost:9002', 87 path: path + '/localhost:' + servers[1].port,
88 fields: { redundancyAllowed: true }, 88 fields: { redundancyAllowed: true },
89 token: servers[0].accessToken, 89 token: servers[0].accessToken,
90 statusCodeExpected: 204 90 statusCodeExpected: 204
@@ -93,11 +93,6 @@ describe('Test server redundancy API validators', function () {
93 }) 93 })
94 94
95 after(async function () { 95 after(async function () {
96 killallServers(servers) 96 await cleanupTests(servers)
97
98 // Keep the logs if the test failed
99 if (this['ok']) {
100 await flushTests()
101 }
102 }) 97 })
103}) 98})
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
index aa81965f3..8ad9d98bf 100644
--- a/server/tests/api/check-params/search.ts
+++ b/server/tests/api/check-params/search.ts
@@ -2,12 +2,12 @@
2 2
3import 'mocha' 3import 'mocha'
4 4
5import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../../../shared/utils' 5import { cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo } from '../../../../shared/extra-utils'
6import { 6import {
7 checkBadCountPagination, 7 checkBadCountPagination,
8 checkBadSortPagination, 8 checkBadSortPagination,
9 checkBadStartPagination 9 checkBadStartPagination
10} from '../../../../shared/utils/requests/check-api-params' 10} from '../../../../shared/extra-utils/requests/check-api-params'
11 11
12describe('Test videos API validator', function () { 12describe('Test videos API validator', function () {
13 let server: ServerInfo 13 let server: ServerInfo
@@ -17,9 +17,7 @@ describe('Test videos API validator', function () {
17 before(async function () { 17 before(async function () {
18 this.timeout(30000) 18 this.timeout(30000)
19 19
20 await flushTests() 20 server = await flushAndRunServer(1)
21
22 server = await runServer(1)
23 }) 21 })
24 22
25 describe('When searching videos', function () { 23 describe('When searching videos', function () {
@@ -113,6 +111,12 @@ describe('Test videos API validator', function () {
113 111
114 const customQuery2 = immutableAssign(query, { endDate: 'hello' }) 112 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
115 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 113 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
114
115 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
116 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 })
117
118 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
119 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 })
116 }) 120 })
117 }) 121 })
118 122
@@ -141,11 +145,6 @@ describe('Test videos API validator', function () {
141 }) 145 })
142 146
143 after(async function () { 147 after(async function () {
144 killallServers([ server ]) 148 await cleanupTests([ server ])
145
146 // Keep the logs if the test failed
147 if (this['ok']) {
148 await flushTests()
149 }
150 }) 149 })
151}) 150})
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
index 28591af9d..d15753aed 100644
--- a/server/tests/api/check-params/services.ts
+++ b/server/tests/api/check-params/services.ts
@@ -3,14 +3,13 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 flushTests, 6 cleanupTests,
7 killallServers, 7 flushAndRunServer,
8 makeGetRequest, 8 makeGetRequest,
9 runServer,
10 ServerInfo, 9 ServerInfo,
11 setAccessTokensToServers, 10 setAccessTokensToServers,
12 uploadVideo 11 uploadVideo
13} from '../../../../shared/utils' 12} from '../../../../shared/extra-utils'
14 13
15describe('Test services API validators', function () { 14describe('Test services API validators', function () {
16 let server: ServerInfo 15 let server: ServerInfo
@@ -20,9 +19,7 @@ describe('Test services API validators', function () {
20 before(async function () { 19 before(async function () {
21 this.timeout(60000) 20 this.timeout(60000)
22 21
23 await flushTests() 22 server = await flushAndRunServer(1)
24
25 server = await runServer(1)
26 await setAccessTokensToServers([ server ]) 23 await setAccessTokensToServers([ server ])
27 24
28 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' }) 25 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
@@ -42,47 +39,47 @@ describe('Test services API validators', function () {
42 }) 39 })
43 40
44 it('Should fail with an invalid video id', async function () { 41 it('Should fail with an invalid video id', async function () {
45 const embedUrl = 'http://localhost:9001/videos/watch/blabla' 42 const embedUrl = `http://localhost:${server.port}/videos/watch/blabla`
46 await checkParamEmbed(server, embedUrl) 43 await checkParamEmbed(server, embedUrl)
47 }) 44 })
48 45
49 it('Should fail with an unknown video', async function () { 46 it('Should fail with an unknown video', async function () {
50 const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c' 47 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
51 await checkParamEmbed(server, embedUrl, 404) 48 await checkParamEmbed(server, embedUrl, 404)
52 }) 49 })
53 50
54 it('Should fail with an invalid path', async function () { 51 it('Should fail with an invalid path', async function () {
55 const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid 52 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}`
56 53
57 await checkParamEmbed(server, embedUrl) 54 await checkParamEmbed(server, embedUrl)
58 }) 55 })
59 56
60 it('Should fail with an invalid max height', async function () { 57 it('Should fail with an invalid max height', async function () {
61 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid 58 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
62 59
63 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' }) 60 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' })
64 }) 61 })
65 62
66 it('Should fail with an invalid max width', async function () { 63 it('Should fail with an invalid max width', async function () {
67 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid 64 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
68 65
69 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' }) 66 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' })
70 }) 67 })
71 68
72 it('Should fail with an invalid format', async function () { 69 it('Should fail with an invalid format', async function () {
73 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid 70 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
74 71
75 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' }) 72 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' })
76 }) 73 })
77 74
78 it('Should fail with a non supported format', async function () { 75 it('Should fail with a non supported format', async function () {
79 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid 76 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
80 77
81 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) 78 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' })
82 }) 79 })
83 80
84 it('Should succeed with the correct params', async function () { 81 it('Should succeed with the correct params', async function () {
85 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid 82 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
86 const query = { 83 const query = {
87 format: 'json', 84 format: 'json',
88 maxheight: 400, 85 maxheight: 400,
@@ -94,12 +91,7 @@ describe('Test services API validators', function () {
94 }) 91 })
95 92
96 after(async function () { 93 after(async function () {
97 killallServers([ server ]) 94 await cleanupTests([ server ])
98
99 // Keep the logs if the test failed
100 if (this['ok']) {
101 await flushTests()
102 }
103 }) 95 })
104}) 96})
105 97
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 714f481e9..14ee20d45 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -4,22 +4,21 @@ import 'mocha'
4import * as io from 'socket.io-client' 4import * as io from 'socket.io-client'
5 5
6import { 6import {
7 flushTests, 7 cleanupTests,
8 flushAndRunServer,
8 immutableAssign, 9 immutableAssign,
9 killallServers,
10 makeGetRequest, 10 makeGetRequest,
11 makePostBodyRequest, 11 makePostBodyRequest,
12 makePutBodyRequest, 12 makePutBodyRequest,
13 runServer,
14 ServerInfo, 13 ServerInfo,
15 setAccessTokensToServers, 14 setAccessTokensToServers,
16 wait 15 wait
17} from '../../../../shared/utils' 16} from '../../../../shared/extra-utils'
18import { 17import {
19 checkBadCountPagination, 18 checkBadCountPagination,
20 checkBadSortPagination, 19 checkBadSortPagination,
21 checkBadStartPagination 20 checkBadStartPagination
22} from '../../../../shared/utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
23import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users' 22import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users'
24 23
25describe('Test user notifications API validators', function () { 24describe('Test user notifications API validators', function () {
@@ -30,9 +29,7 @@ describe('Test user notifications API validators', function () {
30 before(async function () { 29 before(async function () {
31 this.timeout(30000) 30 this.timeout(30000)
32 31
33 await flushTests() 32 server = await flushAndRunServer(1)
34
35 server = await runServer(1)
36 33
37 await setAccessTokensToServers([ server ]) 34 await setAccessTokensToServers([ server ])
38 }) 35 })
@@ -168,12 +165,14 @@ describe('Test user notifications API validators', function () {
168 newVideoFromSubscription: UserNotificationSettingValue.WEB, 165 newVideoFromSubscription: UserNotificationSettingValue.WEB,
169 newCommentOnMyVideo: UserNotificationSettingValue.WEB, 166 newCommentOnMyVideo: UserNotificationSettingValue.WEB,
170 videoAbuseAsModerator: UserNotificationSettingValue.WEB, 167 videoAbuseAsModerator: UserNotificationSettingValue.WEB,
168 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB,
171 blacklistOnMyVideo: UserNotificationSettingValue.WEB, 169 blacklistOnMyVideo: UserNotificationSettingValue.WEB,
172 myVideoImportFinished: UserNotificationSettingValue.WEB, 170 myVideoImportFinished: UserNotificationSettingValue.WEB,
173 myVideoPublished: UserNotificationSettingValue.WEB, 171 myVideoPublished: UserNotificationSettingValue.WEB,
174 commentMention: UserNotificationSettingValue.WEB, 172 commentMention: UserNotificationSettingValue.WEB,
175 newFollow: UserNotificationSettingValue.WEB, 173 newFollow: UserNotificationSettingValue.WEB,
176 newUserRegistration: UserNotificationSettingValue.WEB 174 newUserRegistration: UserNotificationSettingValue.WEB,
175 newInstanceFollower: UserNotificationSettingValue.WEB
177 } 176 }
178 177
179 it('Should fail with missing fields', async function () { 178 it('Should fail with missing fields', async function () {
@@ -234,7 +233,7 @@ describe('Test user notifications API validators', function () {
234 233
235 describe('When connecting to my notification socket', function () { 234 describe('When connecting to my notification socket', function () {
236 it('Should fail with no token', function (next) { 235 it('Should fail with no token', function (next) {
237 const socket = io('http://localhost:9001/user-notifications', { reconnection: false }) 236 const socket = io(`http://localhost:${server.port}/user-notifications`, { reconnection: false })
238 237
239 socket.on('error', () => { 238 socket.on('error', () => {
240 socket.removeListener('error', this) 239 socket.removeListener('error', this)
@@ -249,7 +248,7 @@ describe('Test user notifications API validators', function () {
249 }) 248 })
250 249
251 it('Should fail with an invalid token', function (next) { 250 it('Should fail with an invalid token', function (next) {
252 const socket = io('http://localhost:9001/user-notifications', { 251 const socket = io(`http://localhost:${server.port}/user-notifications`, {
253 query: { accessToken: 'bad_access_token' }, 252 query: { accessToken: 'bad_access_token' },
254 reconnection: false 253 reconnection: false
255 }) 254 })
@@ -267,7 +266,7 @@ describe('Test user notifications API validators', function () {
267 }) 266 })
268 267
269 it('Should success with the correct token', function (next) { 268 it('Should success with the correct token', function (next) {
270 const socket = io('http://localhost:9001/user-notifications', { 269 const socket = io(`http://localhost:${server.port}/user-notifications`, {
271 query: { accessToken: server.accessToken }, 270 query: { accessToken: server.accessToken },
272 reconnection: false 271 reconnection: false
273 }) 272 })
@@ -287,11 +286,6 @@ describe('Test user notifications API validators', function () {
287 }) 286 })
288 287
289 after(async function () { 288 after(async function () {
290 killallServers([ server ]) 289 await cleanupTests([ server ])
291
292 // Keep the logs if the test failed
293 if (this['ok']) {
294 await flushTests()
295 }
296 }) 290 })
297}) 291})
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 8a9ced7c1..fa36c4078 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -3,24 +3,23 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 flushTests, 8 flushAndRunServer,
8 killallServers,
9 makeDeleteRequest, 9 makeDeleteRequest,
10 makeGetRequest, 10 makeGetRequest,
11 makePostBodyRequest, 11 makePostBodyRequest,
12 runServer,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 userLogin 14 userLogin
16} from '../../../../shared/utils' 15} from '../../../../shared/extra-utils'
17 16
18import { 17import {
19 checkBadCountPagination, 18 checkBadCountPagination,
20 checkBadSortPagination, 19 checkBadSortPagination,
21 checkBadStartPagination 20 checkBadStartPagination
22} from '../../../../shared/utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
23import { waitJobs } from '../../../../shared/utils/server/jobs' 22import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
24 23
25describe('Test user subscriptions API validators', function () { 24describe('Test user subscriptions API validators', function () {
26 const path = '/api/v1/users/me/subscriptions' 25 const path = '/api/v1/users/me/subscriptions'
@@ -32,9 +31,7 @@ describe('Test user subscriptions API validators', function () {
32 before(async function () { 31 before(async function () {
33 this.timeout(30000) 32 this.timeout(30000)
34 33
35 await flushTests() 34 server = await flushAndRunServer(1)
36
37 server = await runServer(1)
38 35
39 await setAccessTokensToServers([ server ]) 36 await setAccessTokensToServers([ server ])
40 37
@@ -42,7 +39,7 @@ describe('Test user subscriptions API validators', function () {
42 username: 'user1', 39 username: 'user1',
43 password: 'my super password' 40 password: 'my super password'
44 } 41 }
45 await createUser(server.url, server.accessToken, user.username, user.password) 42 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
46 userAccessToken = await userLogin(server, user) 43 userAccessToken = await userLogin(server, user)
47 }) 44 })
48 45
@@ -115,7 +112,7 @@ describe('Test user subscriptions API validators', function () {
115 await makePostBodyRequest({ 112 await makePostBodyRequest({
116 url: server.url, 113 url: server.url,
117 path, 114 path,
118 fields: { uri: 'user1_channel@localhost:9001' }, 115 fields: { uri: 'user1_channel@localhost:' + server.port },
119 statusCodeExpected: 401 116 statusCodeExpected: 401
120 }) 117 })
121 }) 118 })
@@ -153,7 +150,7 @@ describe('Test user subscriptions API validators', function () {
153 url: server.url, 150 url: server.url,
154 path, 151 path,
155 token: server.accessToken, 152 token: server.accessToken,
156 fields: { uri: 'user1_channel@localhost:9001' }, 153 fields: { uri: 'user1_channel@localhost:' + server.port },
157 statusCodeExpected: 204 154 statusCodeExpected: 204
158 }) 155 })
159 156
@@ -165,7 +162,7 @@ describe('Test user subscriptions API validators', function () {
165 it('Should fail with a non authenticated user', async function () { 162 it('Should fail with a non authenticated user', async function () {
166 await makeGetRequest({ 163 await makeGetRequest({
167 url: server.url, 164 url: server.url,
168 path: path + '/user1_channel@localhost:9001', 165 path: path + '/user1_channel@localhost:' + server.port,
169 statusCodeExpected: 401 166 statusCodeExpected: 401
170 }) 167 })
171 }) 168 })
@@ -196,7 +193,7 @@ describe('Test user subscriptions API validators', function () {
196 it('Should fail with an unknown subscription', async function () { 193 it('Should fail with an unknown subscription', async function () {
197 await makeGetRequest({ 194 await makeGetRequest({
198 url: server.url, 195 url: server.url,
199 path: path + '/root1@localhost:9001', 196 path: path + '/root1@localhost:' + server.port,
200 token: server.accessToken, 197 token: server.accessToken,
201 statusCodeExpected: 404 198 statusCodeExpected: 404
202 }) 199 })
@@ -205,14 +202,14 @@ describe('Test user subscriptions API validators', function () {
205 it('Should succeed with the correct parameters', async function () { 202 it('Should succeed with the correct parameters', async function () {
206 await makeGetRequest({ 203 await makeGetRequest({
207 url: server.url, 204 url: server.url,
208 path: path + '/user1_channel@localhost:9001', 205 path: path + '/user1_channel@localhost:' + server.port,
209 token: server.accessToken, 206 token: server.accessToken,
210 statusCodeExpected: 200 207 statusCodeExpected: 200
211 }) 208 })
212 }) 209 })
213 }) 210 })
214 211
215 describe('When checking if subscriptions exist', async function () { 212 describe('When checking if subscriptions exist', function () {
216 const existPath = path + '/exist' 213 const existPath = path + '/exist'
217 214
218 it('Should fail with a non authenticated user', async function () { 215 it('Should fail with a non authenticated user', async function () {
@@ -245,7 +242,7 @@ describe('Test user subscriptions API validators', function () {
245 await makeGetRequest({ 242 await makeGetRequest({
246 url: server.url, 243 url: server.url,
247 path: existPath, 244 path: existPath,
248 query: { 'uris[]': 'coucou@localhost:9001' }, 245 query: { 'uris[]': 'coucou@localhost:' + server.port },
249 token: server.accessToken, 246 token: server.accessToken,
250 statusCodeExpected: 200 247 statusCodeExpected: 200
251 }) 248 })
@@ -256,7 +253,7 @@ describe('Test user subscriptions API validators', function () {
256 it('Should fail with a non authenticated user', async function () { 253 it('Should fail with a non authenticated user', async function () {
257 await makeDeleteRequest({ 254 await makeDeleteRequest({
258 url: server.url, 255 url: server.url,
259 path: path + '/user1_channel@localhost:9001', 256 path: path + '/user1_channel@localhost:' + server.port,
260 statusCodeExpected: 401 257 statusCodeExpected: 401
261 }) 258 })
262 }) 259 })
@@ -287,7 +284,7 @@ describe('Test user subscriptions API validators', function () {
287 it('Should fail with an unknown subscription', async function () { 284 it('Should fail with an unknown subscription', async function () {
288 await makeDeleteRequest({ 285 await makeDeleteRequest({
289 url: server.url, 286 url: server.url,
290 path: path + '/root1@localhost:9001', 287 path: path + '/root1@localhost:' + server.port,
291 token: server.accessToken, 288 token: server.accessToken,
292 statusCodeExpected: 404 289 statusCodeExpected: 404
293 }) 290 })
@@ -296,7 +293,7 @@ describe('Test user subscriptions API validators', function () {
296 it('Should succeed with the correct parameters', async function () { 293 it('Should succeed with the correct parameters', async function () {
297 await makeDeleteRequest({ 294 await makeDeleteRequest({
298 url: server.url, 295 url: server.url,
299 path: path + '/user1_channel@localhost:9001', 296 path: path + '/user1_channel@localhost:' + server.port,
300 token: server.accessToken, 297 token: server.accessToken,
301 statusCodeExpected: 204 298 statusCodeExpected: 204
302 }) 299 })
@@ -304,11 +301,6 @@ describe('Test user subscriptions API validators', function () {
304 }) 301 })
305 302
306 after(async function () { 303 after(async function () {
307 killallServers([ server ]) 304 await cleanupTests([ server ])
308
309 // Keep the logs if the test failed
310 if (this['ok']) {
311 await flushTests()
312 }
313 }) 305 })
314}) 306})
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index a3e8e2e9c..5935104a5 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -6,19 +6,38 @@ import { join } from 'path'
6import { UserRole, VideoImport, VideoImportState } from '../../../../shared' 6import { UserRole, VideoImport, VideoImportState } from '../../../../shared'
7 7
8import { 8import {
9 createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, 9 blockUser,
10 makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, 10 cleanupTests,
11 updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser 11 createUser,
12} from '../../../../shared/utils' 12 deleteMe,
13 flushAndRunServer,
14 getMyUserInformation,
15 getMyUserVideoRating,
16 getUsersList,
17 immutableAssign,
18 makeGetRequest,
19 makePostBodyRequest,
20 makePutBodyRequest,
21 makeUploadRequest,
22 registerUser,
23 removeUser,
24 ServerInfo,
25 setAccessTokensToServers,
26 unblockUser,
27 updateUser,
28 uploadVideo,
29 userLogin
30} from '../../../../shared/extra-utils'
13import { 31import {
14 checkBadCountPagination, 32 checkBadCountPagination,
15 checkBadSortPagination, 33 checkBadSortPagination,
16 checkBadStartPagination 34 checkBadStartPagination
17} from '../../../../shared/utils/requests/check-api-params' 35} from '../../../../shared/extra-utils/requests/check-api-params'
18import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' 36import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
19import { VideoPrivacy } from '../../../../shared/models/videos' 37import { VideoPrivacy } from '../../../../shared/models/videos'
20import { waitJobs } from '../../../../shared/utils/server/jobs' 38import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21import { expect } from 'chai' 39import { expect } from 'chai'
40import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
22 41
23describe('Test users API validators', function () { 42describe('Test users API validators', function () {
24 const path = '/api/v1/users/' 43 const path = '/api/v1/users/'
@@ -39,15 +58,19 @@ describe('Test users API validators', function () {
39 before(async function () { 58 before(async function () {
40 this.timeout(30000) 59 this.timeout(30000)
41 60
42 await flushTests() 61 server = await flushAndRunServer(1)
43 62 serverWithRegistrationDisabled = await flushAndRunServer(2)
44 server = await runServer(1)
45 serverWithRegistrationDisabled = await runServer(2)
46 63
47 await setAccessTokensToServers([ server ]) 64 await setAccessTokensToServers([ server ])
48 65
49 const videoQuota = 42000000 66 const videoQuota = 42000000
50 await createUser(server.url, server.accessToken, user.username, user.password, videoQuota) 67 await createUser({
68 url: server.url,
69 accessToken: server.accessToken,
70 username: user.username,
71 password: user.password,
72 videoQuota: videoQuota
73 })
51 userAccessToken = await userLogin(server, user) 74 userAccessToken = await userLogin(server, user)
52 75
53 { 76 {
@@ -99,7 +122,8 @@ describe('Test users API validators', function () {
99 password: 'my super password', 122 password: 'my super password',
100 videoQuota: -1, 123 videoQuota: -1,
101 videoQuotaDaily: -1, 124 videoQuotaDaily: -1,
102 role: UserRole.USER 125 role: UserRole.USER,
126 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
103 } 127 }
104 128
105 it('Should fail with a too small username', async function () { 129 it('Should fail with a too small username', async function () {
@@ -150,6 +174,12 @@ describe('Test users API validators', function () {
150 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 174 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
151 }) 175 })
152 176
177 it('Should fail with invalid admin flags', async function () {
178 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
179
180 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
181 })
182
153 it('Should fail with an non authenticated user', async function () { 183 it('Should fail with an non authenticated user', async function () {
154 await makePostBodyRequest({ 184 await makePostBodyRequest({
155 url: server.url, 185 url: server.url,
@@ -464,6 +494,24 @@ describe('Test users API validators', function () {
464 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) 494 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
465 }) 495 })
466 496
497 it('Should fail with a too small password', async function () {
498 const fields = {
499 currentPassword: 'my super password',
500 password: 'bla'
501 }
502
503 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
504 })
505
506 it('Should fail with a too long password', async function () {
507 const fields = {
508 currentPassword: 'my super password',
509 password: 'super'.repeat(61)
510 }
511
512 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
513 })
514
467 it('Should fail with an non authenticated user', async function () { 515 it('Should fail with an non authenticated user', async function () {
468 const fields = { 516 const fields = {
469 videoQuota: 42 517 videoQuota: 42
@@ -480,6 +528,12 @@ describe('Test users API validators', function () {
480 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields }) 528 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
481 }) 529 })
482 530
531 it('Should fail with invalid admin flags', async function () {
532 const fields = { adminFlags: 'toto' }
533
534 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
535 })
536
483 it('Should succeed with the correct params', async function () { 537 it('Should succeed with the correct params', async function () {
484 const fields = { 538 const fields = {
485 email: 'email@example.com', 539 email: 'email@example.com',
@@ -520,6 +574,38 @@ describe('Test users API validators', function () {
520 }) 574 })
521 }) 575 })
522 576
577 describe('When retrieving my global ratings', function () {
578 const path = '/api/v1/accounts/user1/ratings'
579
580 it('Should fail with a bad start pagination', async function () {
581 await checkBadStartPagination(server.url, path, userAccessToken)
582 })
583
584 it('Should fail with a bad count pagination', async function () {
585 await checkBadCountPagination(server.url, path, userAccessToken)
586 })
587
588 it('Should fail with an incorrect sort', async function () {
589 await checkBadSortPagination(server.url, path, userAccessToken)
590 })
591
592 it('Should fail with a unauthenticated user', async function () {
593 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
594 })
595
596 it('Should fail with a another user', async function () {
597 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
598 })
599
600 it('Should fail with a bad type', async function () {
601 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
602 })
603
604 it('Should succeed with the correct params', async function () {
605 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
606 })
607 })
608
523 describe('When blocking/unblocking/removing user', function () { 609 describe('When blocking/unblocking/removing user', function () {
524 it('Should fail with an incorrect id', async function () { 610 it('Should fail with an incorrect id', async function () {
525 await removeUser(server.url, 'blabla', server.accessToken, 400) 611 await removeUser(server.url, 'blabla', server.accessToken, 400)
@@ -627,7 +713,7 @@ describe('Test users API validators', function () {
627 }) 713 })
628 714
629 it('Should fail if we register a user with the same email', async function () { 715 it('Should fail if we register a user with the same email', async function () {
630 const fields = immutableAssign(baseCorrectParams, { email: 'admin1@example.com' }) 716 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
631 717
632 await makePostBodyRequest({ 718 await makePostBodyRequest({
633 url: server.url, 719 url: server.url,
@@ -812,11 +898,6 @@ describe('Test users API validators', function () {
812 }) 898 })
813 899
814 after(async function () { 900 after(async function () {
815 killallServers([ server, serverWithRegistrationDisabled ]) 901 await cleanupTests([ server, serverWithRegistrationDisabled ])
816
817 // Keep the logs if the test failed
818 if (this['ok']) {
819 await flushTests()
820 }
821 }) 902 })
822}) 903})
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts
index 3b8f5f14d..bf29f8d4d 100644
--- a/server/tests/api/check-params/video-abuses.ts
+++ b/server/tests/api/check-params/video-abuses.ts
@@ -3,24 +3,23 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 deleteVideoAbuse, 8 deleteVideoAbuse,
8 flushTests, 9 flushAndRunServer,
9 killallServers,
10 makeGetRequest, 10 makeGetRequest,
11 makePostBodyRequest, 11 makePostBodyRequest,
12 runServer,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 updateVideoAbuse, 14 updateVideoAbuse,
16 uploadVideo, 15 uploadVideo,
17 userLogin 16 userLogin
18} from '../../../../shared/utils' 17} from '../../../../shared/extra-utils'
19import { 18import {
20 checkBadCountPagination, 19 checkBadCountPagination,
21 checkBadSortPagination, 20 checkBadSortPagination,
22 checkBadStartPagination 21 checkBadStartPagination
23} from '../../../../shared/utils/requests/check-api-params' 22} from '../../../../shared/extra-utils/requests/check-api-params'
24import { VideoAbuseState } from '../../../../shared/models/videos' 23import { VideoAbuseState } from '../../../../shared/models/videos'
25 24
26describe('Test video abuses API validators', function () { 25describe('Test video abuses API validators', function () {
@@ -33,15 +32,13 @@ describe('Test video abuses API validators', function () {
33 before(async function () { 32 before(async function () {
34 this.timeout(30000) 33 this.timeout(30000)
35 34
36 await flushTests() 35 server = await flushAndRunServer(1)
37
38 server = await runServer(1)
39 36
40 await setAccessTokensToServers([ server ]) 37 await setAccessTokensToServers([ server ])
41 38
42 const username = 'user1' 39 const username = 'user1'
43 const password = 'my super password' 40 const password = 'my super password'
44 await createUser(server.url, server.accessToken, username, password) 41 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
45 userAccessToken = await userLogin(server, { username, password }) 42 userAccessToken = await userLogin(server, { username, password })
46 43
47 const res = await uploadVideo(server.url, server.accessToken, {}) 44 const res = await uploadVideo(server.url, server.accessToken, {})
@@ -191,11 +188,6 @@ describe('Test video abuses API validators', function () {
191 }) 188 })
192 189
193 after(async function () { 190 after(async function () {
194 killallServers([ server ]) 191 await cleanupTests([ server ])
195
196 // Keep the logs if the test failed
197 if (this['ok']) {
198 await flushTests()
199 }
200 }) 192 })
201}) 193})
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 6b82643f4..6466888fb 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -3,6 +3,7 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -18,13 +19,13 @@ import {
18 setAccessTokensToServers, 19 setAccessTokensToServers,
19 uploadVideo, 20 uploadVideo,
20 userLogin, waitJobs 21 userLogin, waitJobs
21} from '../../../../shared/utils' 22} from '../../../../shared/extra-utils'
22import { 23import {
23 checkBadCountPagination, 24 checkBadCountPagination,
24 checkBadSortPagination, 25 checkBadSortPagination,
25 checkBadStartPagination 26 checkBadStartPagination
26} from '../../../../shared/utils/requests/check-api-params' 27} from '../../../../shared/extra-utils/requests/check-api-params'
27import { VideoDetails } from '../../../../shared/models/videos' 28import { VideoDetails, VideoBlacklistType } from '../../../../shared/models/videos'
28import { expect } from 'chai' 29import { expect } from 'chai'
29 30
30describe('Test video blacklist API validators', function () { 31describe('Test video blacklist API validators', function () {
@@ -39,7 +40,6 @@ describe('Test video blacklist API validators', function () {
39 before(async function () { 40 before(async function () {
40 this.timeout(120000) 41 this.timeout(120000)
41 42
42 await flushTests()
43 servers = await flushAndRunMultipleServers(2) 43 servers = await flushAndRunMultipleServers(2)
44 44
45 await setAccessTokensToServers(servers) 45 await setAccessTokensToServers(servers)
@@ -48,14 +48,14 @@ describe('Test video blacklist API validators', function () {
48 { 48 {
49 const username = 'user1' 49 const username = 'user1'
50 const password = 'my super password' 50 const password = 'my super password'
51 await createUser(servers[0].url, servers[0].accessToken, username, password) 51 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password })
52 userAccessToken1 = await userLogin(servers[0], { username, password }) 52 userAccessToken1 = await userLogin(servers[0], { username, password })
53 } 53 }
54 54
55 { 55 {
56 const username = 'user2' 56 const username = 'user2'
57 const password = 'my super password' 57 const password = 'my super password'
58 await createUser(servers[0].url, servers[0].accessToken, username, password) 58 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password })
59 userAccessToken2 = await userLogin(servers[0], { username, password }) 59 userAccessToken2 = await userLogin(servers[0], { username, password })
60 } 60 }
61 61
@@ -220,11 +220,11 @@ describe('Test video blacklist API validators', function () {
220 const basePath = '/api/v1/videos/blacklist/' 220 const basePath = '/api/v1/videos/blacklist/'
221 221
222 it('Should fail with a non authenticated user', async function () { 222 it('Should fail with a non authenticated user', async function () {
223 await getBlacklistedVideosList(servers[0].url, 'fake token', 401) 223 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 })
224 }) 224 })
225 225
226 it('Should fail with a non admin user', async function () { 226 it('Should fail with a non admin user', async function () {
227 await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403) 227 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 })
228 }) 228 })
229 229
230 it('Should fail with a bad start pagination', async function () { 230 it('Should fail with a bad start pagination', async function () {
@@ -238,14 +238,17 @@ describe('Test video blacklist API validators', function () {
238 it('Should fail with an incorrect sort', async function () { 238 it('Should fail with an incorrect sort', async function () {
239 await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken) 239 await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
240 }) 240 })
241
242 it('Should fail with an invalid type', async function () {
243 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 })
244 })
245
246 it('Should succeed with the correct parameters', async function () {
247 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL })
248 })
241 }) 249 })
242 250
243 after(async function () { 251 after(async function () {
244 killallServers(servers) 252 await cleanupTests(servers)
245
246 // Keep the logs if the test failed
247 if (this['ok']) {
248 await flushTests()
249 }
250 }) 253 })
251}) 254})
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index e4d36fd4f..4a373d43d 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -2,20 +2,19 @@
2 2
3import 'mocha' 3import 'mocha'
4import { 4import {
5 cleanupTests,
5 createUser, 6 createUser,
6 flushTests, 7 flushAndRunServer,
7 killallServers,
8 makeDeleteRequest, 8 makeDeleteRequest,
9 makeGetRequest, 9 makeGetRequest,
10 makeUploadRequest, 10 makeUploadRequest,
11 runServer,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 uploadVideo, 13 uploadVideo,
15 userLogin 14 userLogin
16} from '../../../../shared/utils' 15} from '../../../../shared/extra-utils'
17import { join } from 'path' 16import { join } from 'path'
18import { createVideoCaption } from '../../../../shared/utils/videos/video-captions' 17import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
19 18
20describe('Test video captions API validator', function () { 19describe('Test video captions API validator', function () {
21 const path = '/api/v1/videos/' 20 const path = '/api/v1/videos/'
@@ -29,9 +28,7 @@ describe('Test video captions API validator', function () {
29 before(async function () { 28 before(async function () {
30 this.timeout(30000) 29 this.timeout(30000)
31 30
32 await flushTests() 31 server = await flushAndRunServer(1)
33
34 server = await runServer(1)
35 32
36 await setAccessTokensToServers([ server ]) 33 await setAccessTokensToServers([ server ])
37 34
@@ -45,7 +42,7 @@ describe('Test video captions API validator', function () {
45 username: 'user1', 42 username: 'user1',
46 password: 'my super password' 43 password: 'my super password'
47 } 44 }
48 await createUser(server.url, server.accessToken, user.username, user.password) 45 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
49 userAccessToken = await userLogin(server, user) 46 userAccessToken = await userLogin(server, user)
50 } 47 }
51 }) 48 })
@@ -272,11 +269,6 @@ describe('Test video captions API validator', function () {
272 }) 269 })
273 270
274 after(async function () { 271 after(async function () {
275 killallServers([ server ]) 272 await cleanupTests([ server ])
276
277 // Keep the logs if the test failed
278 if (this['ok']) {
279 await flushTests()
280 }
281 }) 273 })
282}) 274})
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 14e4deaf7..65bc20613 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -4,29 +4,25 @@ import * as chai from 'chai'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import 'mocha' 5import 'mocha'
6import { 6import {
7 cleanupTests,
7 createUser, 8 createUser,
8 deleteVideoChannel, 9 deleteVideoChannel,
9 flushTests, 10 flushAndRunServer,
10 getAccountVideoChannelsList, 11 getAccountVideoChannelsList,
11 getMyUserInformation,
12 getVideoChannelsList,
13 immutableAssign, 12 immutableAssign,
14 killallServers,
15 makeGetRequest, 13 makeGetRequest,
16 makePostBodyRequest, 14 makePostBodyRequest,
17 makePutBodyRequest, 15 makePutBodyRequest,
18 makeUploadRequest, 16 makeUploadRequest,
19 runServer,
20 ServerInfo, 17 ServerInfo,
21 setAccessTokensToServers, 18 setAccessTokensToServers,
22 userLogin 19 userLogin
23} from '../../../../shared/utils' 20} from '../../../../shared/extra-utils'
24import { 21import {
25 checkBadCountPagination, 22 checkBadCountPagination,
26 checkBadSortPagination, 23 checkBadSortPagination,
27 checkBadStartPagination 24 checkBadStartPagination
28} from '../../../../shared/utils/requests/check-api-params' 25} from '../../../../shared/extra-utils/requests/check-api-params'
29import { User } from '../../../../shared/models/users'
30import { join } from 'path' 26import { join } from 'path'
31 27
32const expect = chai.expect 28const expect = chai.expect
@@ -41,9 +37,7 @@ describe('Test video channels API validator', function () {
41 before(async function () { 37 before(async function () {
42 this.timeout(30000) 38 this.timeout(30000)
43 39
44 await flushTests() 40 server = await flushAndRunServer(1)
45
46 server = await runServer(1)
47 41
48 await setAccessTokensToServers([ server ]) 42 await setAccessTokensToServers([ server ])
49 43
@@ -53,7 +47,7 @@ describe('Test video channels API validator', function () {
53 } 47 }
54 48
55 { 49 {
56 await createUser(server.url, server.accessToken, user.username, user.password) 50 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
57 accessTokenUser = await userLogin(server, user) 51 accessTokenUser = await userLogin(server, user)
58 } 52 }
59 }) 53 })
@@ -313,11 +307,6 @@ describe('Test video channels API validator', function () {
313 }) 307 })
314 308
315 after(async function () { 309 after(async function () {
316 killallServers([ server ]) 310 await cleanupTests([ server ])
317
318 // Keep the logs if the test failed
319 if (this['ok']) {
320 await flushTests()
321 }
322 }) 311 })
323}) 312})
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index 5981780ed..5cf90bacc 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -3,16 +3,23 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, 8 flushAndRunServer,
8 uploadVideo, userLogin 9 makeDeleteRequest,
9} from '../../../../shared/utils' 10 makeGetRequest,
11 makePostBodyRequest,
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo,
15 userLogin
16} from '../../../../shared/extra-utils'
10import { 17import {
11 checkBadCountPagination, 18 checkBadCountPagination,
12 checkBadSortPagination, 19 checkBadSortPagination,
13 checkBadStartPagination 20 checkBadStartPagination
14} from '../../../../shared/utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
15import { addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' 22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
16 23
17const expect = chai.expect 24const expect = chai.expect
18 25
@@ -29,9 +36,7 @@ describe('Test video comments API validator', function () {
29 before(async function () { 36 before(async function () {
30 this.timeout(30000) 37 this.timeout(30000)
31 38
32 await flushTests() 39 server = await flushAndRunServer(1)
33
34 server = await runServer(1)
35 40
36 await setAccessTokensToServers([ server ]) 41 await setAccessTokensToServers([ server ])
37 42
@@ -52,7 +57,7 @@ describe('Test video comments API validator', function () {
52 username: 'user1', 57 username: 'user1',
53 password: 'my super password' 58 password: 'my super password'
54 } 59 }
55 await createUser(server.url, server.accessToken, user.username, user.password) 60 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
56 userAccessToken = await userLogin(server, user) 61 userAccessToken = await userLogin(server, user)
57 } 62 }
58 }) 63 })
@@ -254,11 +259,6 @@ describe('Test video comments API validator', function () {
254 }) 259 })
255 260
256 after(async function () { 261 after(async function () {
257 killallServers([ server ]) 262 await cleanupTests([ server ])
258
259 // Keep the logs if the test failed
260 if (this['ok']) {
261 await flushTests()
262 }
263 }) 263 })
264}) 264})
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 7bf187007..8ff115e7b 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -5,26 +5,25 @@ import 'mocha'
5import { join } from 'path' 5import { join } from 'path'
6import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 6import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
7import { 7import {
8 cleanupTests,
8 createUser, 9 createUser,
9 flushTests, 10 flushAndRunServer,
10 getMyUserInformation, 11 getMyUserInformation,
11 immutableAssign, 12 immutableAssign,
12 killallServers,
13 makeGetRequest, 13 makeGetRequest,
14 makePostBodyRequest, 14 makePostBodyRequest,
15 makeUploadRequest, 15 makeUploadRequest,
16 runServer,
17 ServerInfo, 16 ServerInfo,
18 setAccessTokensToServers, 17 setAccessTokensToServers,
19 updateCustomSubConfig, 18 updateCustomSubConfig,
20 userLogin 19 userLogin
21} from '../../../../shared/utils' 20} from '../../../../shared/extra-utils'
22import { 21import {
23 checkBadCountPagination, 22 checkBadCountPagination,
24 checkBadSortPagination, 23 checkBadSortPagination,
25 checkBadStartPagination 24 checkBadStartPagination
26} from '../../../../shared/utils/requests/check-api-params' 25} from '../../../../shared/extra-utils/requests/check-api-params'
27import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/utils/videos/video-imports' 26import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
28 27
29describe('Test video imports API validator', function () { 28describe('Test video imports API validator', function () {
30 const path = '/api/v1/videos/imports' 29 const path = '/api/v1/videos/imports'
@@ -38,15 +37,13 @@ describe('Test video imports API validator', function () {
38 before(async function () { 37 before(async function () {
39 this.timeout(30000) 38 this.timeout(30000)
40 39
41 await flushTests() 40 server = await flushAndRunServer(1)
42
43 server = await runServer(1)
44 41
45 await setAccessTokensToServers([ server ]) 42 await setAccessTokensToServers([ server ])
46 43
47 const username = 'user1' 44 const username = 'user1'
48 const password = 'my super password' 45 const password = 'my super password'
49 await createUser(server.url, server.accessToken, username, password) 46 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
50 userAccessToken = await userLogin(server, { username, password }) 47 userAccessToken = await userLogin(server, { username, password })
51 48
52 { 49 {
@@ -88,6 +85,7 @@ describe('Test video imports API validator', function () {
88 language: 'pt', 85 language: 'pt',
89 nsfw: false, 86 nsfw: false,
90 commentsEnabled: true, 87 commentsEnabled: true,
88 downloadEnabled: true,
91 waitTranscoding: true, 89 waitTranscoding: true,
92 description: 'my super description', 90 description: 'my super description',
93 support: 'my super support text', 91 support: 'my super support text',
@@ -166,7 +164,7 @@ describe('Test video imports API validator', function () {
166 username: 'fake', 164 username: 'fake',
167 password: 'fake_password' 165 password: 'fake_password'
168 } 166 }
169 await createUser(server.url, server.accessToken, user.username, user.password) 167 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
170 168
171 const accessTokenUser = await userLogin(server, user) 169 const accessTokenUser = await userLogin(server, user)
172 const res = await getMyUserInformation(server.url, accessTokenUser) 170 const res = await getMyUserInformation(server.url, accessTokenUser)
@@ -313,11 +311,6 @@ describe('Test video imports API validator', function () {
313 }) 311 })
314 312
315 after(async function () { 313 after(async function () {
316 killallServers([ server ]) 314 await cleanupTests([ server ])
317
318 // Keep the logs if the test failed
319 if (this['ok']) {
320 await flushTests()
321 }
322 }) 315 })
323}) 316})
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
new file mode 100644
index 000000000..b7b94c035
--- /dev/null
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -0,0 +1,674 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import {
5 addVideoInPlaylist,
6 cleanupTests,
7 createVideoPlaylist,
8 deleteVideoPlaylist,
9 flushAndRunServer,
10 generateUserAccessToken,
11 getAccountPlaylistsListWithToken,
12 getVideoPlaylist,
13 immutableAssign,
14 makeGetRequest,
15 removeVideoFromPlaylist,
16 reorderVideosPlaylist,
17 ServerInfo,
18 setAccessTokensToServers,
19 setDefaultVideoChannel,
20 updateVideoPlaylist,
21 updateVideoPlaylistElement,
22 uploadVideoAndGetId
23} from '../../../../shared/extra-utils'
24import {
25 checkBadCountPagination,
26 checkBadSortPagination,
27 checkBadStartPagination
28} from '../../../../shared/extra-utils/requests/check-api-params'
29import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
30import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
31
32describe('Test video playlists API validator', function () {
33 let server: ServerInfo
34 let userAccessToken: string
35 let playlistUUID: string
36 let privatePlaylistUUID: string
37 let watchLaterPlaylistId: number
38 let videoId: number
39 let videoId2: number
40
41 // ---------------------------------------------------------------
42
43 before(async function () {
44 this.timeout(30000)
45
46 server = await flushAndRunServer(1)
47
48 await setAccessTokensToServers([ server ])
49 await setDefaultVideoChannel([ server ])
50
51 userAccessToken = await generateUserAccessToken(server, 'user1')
52 videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id
53 videoId2 = (await uploadVideoAndGetId({ server, videoName: 'video 2' })).id
54
55 {
56 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root',0, 5, VideoPlaylistType.WATCH_LATER)
57 watchLaterPlaylistId = res.body.data[0].id
58 }
59
60 {
61 const res = await createVideoPlaylist({
62 url: server.url,
63 token: server.accessToken,
64 playlistAttrs: {
65 displayName: 'super playlist',
66 privacy: VideoPlaylistPrivacy.PUBLIC,
67 videoChannelId: server.videoChannel.id
68 }
69 })
70 playlistUUID = res.body.videoPlaylist.uuid
71 }
72
73 {
74 const res = await createVideoPlaylist({
75 url: server.url,
76 token: server.accessToken,
77 playlistAttrs: {
78 displayName: 'private',
79 privacy: VideoPlaylistPrivacy.PRIVATE
80 }
81 })
82 privatePlaylistUUID = res.body.videoPlaylist.uuid
83 }
84 })
85
86 describe('When listing playlists', function () {
87 const globalPath = '/api/v1/video-playlists'
88 const accountPath = '/api/v1/accounts/root/video-playlists'
89 const videoChannelPath = '/api/v1/video-channels/root_channel/video-playlists'
90
91 it('Should fail with a bad start pagination', async function () {
92 await checkBadStartPagination(server.url, globalPath, server.accessToken)
93 await checkBadStartPagination(server.url, accountPath, server.accessToken)
94 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
95 })
96
97 it('Should fail with a bad count pagination', async function () {
98 await checkBadCountPagination(server.url, globalPath, server.accessToken)
99 await checkBadCountPagination(server.url, accountPath, server.accessToken)
100 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
101 })
102
103 it('Should fail with an incorrect sort', async function () {
104 await checkBadSortPagination(server.url, globalPath, server.accessToken)
105 await checkBadSortPagination(server.url, accountPath, server.accessToken)
106 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
107 })
108
109 it('Should fail with a bad playlist type', async function () {
110 await makeGetRequest({ url: server.url, path: globalPath, query: { playlistType: 3 } })
111 await makeGetRequest({ url: server.url, path: accountPath, query: { playlistType: 3 } })
112 await makeGetRequest({ url: server.url, path: videoChannelPath, query: { playlistType: 3 } })
113 })
114
115 it('Should fail with a bad account parameter', async function () {
116 const accountPath = '/api/v1/accounts/root2/video-playlists'
117
118 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken })
119 })
120
121 it('Should fail with a bad video channel parameter', async function () {
122 const accountPath = '/api/v1/video-channels/bad_channel/video-playlists'
123
124 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken })
125 })
126
127 it('Should success with the correct parameters', async function () {
128 await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: 200, token: server.accessToken })
129 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 200, token: server.accessToken })
130 await makeGetRequest({ url: server.url, path: videoChannelPath, statusCodeExpected: 200, token: server.accessToken })
131 })
132 })
133
134 describe('When listing videos of a playlist', function () {
135 const path = '/api/v1/video-playlists'
136
137 it('Should fail with a bad start pagination', async function () {
138 await checkBadStartPagination(server.url, path, server.accessToken)
139 })
140
141 it('Should fail with a bad count pagination', async function () {
142 await checkBadCountPagination(server.url, path, server.accessToken)
143 })
144
145 it('Should fail with a bad filter', async function () {
146 await checkBadSortPagination(server.url, path, server.accessToken)
147 })
148 })
149
150 describe('When getting a video playlist', function () {
151 it('Should fail with a bad id or uuid', async function () {
152 await getVideoPlaylist(server.url, 'toto', 400)
153 })
154
155 it('Should fail with an unknown playlist', async function () {
156 await getVideoPlaylist(server.url, 42, 404)
157 })
158
159 it('Should fail to get an unlisted playlist with the number id', async function () {
160 const res = await createVideoPlaylist({
161 url: server.url,
162 token: server.accessToken,
163 playlistAttrs: {
164 displayName: 'super playlist',
165 privacy: VideoPlaylistPrivacy.UNLISTED
166 }
167 })
168 const playlist = res.body.videoPlaylist
169
170 await getVideoPlaylist(server.url, playlist.id, 404)
171 await getVideoPlaylist(server.url, playlist.uuid, 200)
172 })
173
174 it('Should succeed with the correct params', async function () {
175 await getVideoPlaylist(server.url, playlistUUID, 200)
176 })
177 })
178
179 describe('When creating/updating a video playlist', function () {
180 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => {
181 return Object.assign({
182 expectedStatus: 400,
183 url: server.url,
184 token: server.accessToken,
185 playlistAttrs: Object.assign({
186 displayName: 'display name',
187 privacy: VideoPlaylistPrivacy.UNLISTED,
188 thumbnailfile: 'thumbnail.jpg',
189 videoChannelId: server.videoChannel.id
190 }, playlistAttrs)
191 }, wrapper)
192 }
193 const getUpdate = (params: any, playlistId: number | string) => {
194 return immutableAssign(params, { playlistId: playlistId })
195 }
196
197 it('Should fail with an unauthenticated user', async function () {
198 const params = getBase({}, { token: null, expectedStatus: 401 })
199
200 await createVideoPlaylist(params)
201 await updateVideoPlaylist(getUpdate(params, playlistUUID))
202 })
203
204 it('Should fail without displayName', async function () {
205 const params = getBase({ displayName: undefined })
206
207 await createVideoPlaylist(params)
208 await updateVideoPlaylist(getUpdate(params, playlistUUID))
209 })
210
211 it('Should fail with an incorrect display name', async function () {
212 const params = getBase({ displayName: 's'.repeat(300) })
213
214 await createVideoPlaylist(params)
215 await updateVideoPlaylist(getUpdate(params, playlistUUID))
216 })
217
218 it('Should fail with an incorrect description', async function () {
219 const params = getBase({ description: 't' })
220
221 await createVideoPlaylist(params)
222 await updateVideoPlaylist(getUpdate(params, playlistUUID))
223 })
224
225 it('Should fail with an incorrect privacy', async function () {
226 const params = getBase({ privacy: 45 })
227
228 await createVideoPlaylist(params)
229 await updateVideoPlaylist(getUpdate(params, playlistUUID))
230 })
231
232 it('Should fail with an unknown video channel id', async function () {
233 const params = getBase({ videoChannelId: 42 }, { expectedStatus: 404 })
234
235 await createVideoPlaylist(params)
236 await updateVideoPlaylist(getUpdate(params, playlistUUID))
237 })
238
239 it('Should fail with an incorrect thumbnail file', async function () {
240 const params = getBase({ thumbnailfile: 'avatar.png' })
241
242 await createVideoPlaylist(params)
243 await updateVideoPlaylist(getUpdate(params, playlistUUID))
244 })
245
246 it('Should fail to set "public" a playlist not assigned to a channel', async function () {
247 const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: undefined })
248 const params2 = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: 'null' })
249 const params3 = getBase({ privacy: undefined, videoChannelId: 'null' })
250
251 await createVideoPlaylist(params)
252 await createVideoPlaylist(params2)
253 await updateVideoPlaylist(getUpdate(params, privatePlaylistUUID))
254 await updateVideoPlaylist(getUpdate(params2, playlistUUID))
255 await updateVideoPlaylist(getUpdate(params3, playlistUUID))
256 })
257
258 it('Should fail with an unknown playlist to update', async function () {
259 await updateVideoPlaylist(getUpdate(
260 getBase({}, { expectedStatus: 404 }),
261 42
262 ))
263 })
264
265 it('Should fail to update a playlist of another user', async function () {
266 await updateVideoPlaylist(getUpdate(
267 getBase({}, { token: userAccessToken, expectedStatus: 403 }),
268 playlistUUID
269 ))
270 })
271
272 it('Should fail to update to private a public/unlisted playlist', async function () {
273 const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC }, { expectedStatus: 200 })
274
275 const res = await createVideoPlaylist(params)
276 const playlist = res.body.videoPlaylist
277
278 const paramsUpdate = getBase({ privacy: VideoPlaylistPrivacy.PRIVATE }, { expectedStatus: 400 })
279
280 await updateVideoPlaylist(getUpdate(paramsUpdate, playlist.id))
281 })
282
283 it('Should fail to update the watch later playlist', async function () {
284 await updateVideoPlaylist(getUpdate(
285 getBase({}, { expectedStatus: 400 }),
286 watchLaterPlaylistId
287 ))
288 })
289
290 it('Should succeed with the correct params', async function () {
291 {
292 const params = getBase({}, { expectedStatus: 200 })
293 await createVideoPlaylist(params)
294 }
295
296 {
297 const params = getBase({}, { expectedStatus: 204 })
298 await updateVideoPlaylist(getUpdate(params, playlistUUID))
299 }
300 })
301 })
302
303 describe('When adding an element in a playlist', function () {
304 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
305 return Object.assign({
306 expectedStatus: 400,
307 url: server.url,
308 token: server.accessToken,
309 playlistId: playlistUUID,
310 elementAttrs: Object.assign({
311 videoId: videoId,
312 startTimestamp: 2,
313 stopTimestamp: 3
314 }, elementAttrs)
315 }, wrapper)
316 }
317
318 it('Should fail with an unauthenticated user', async function () {
319 const params = getBase({}, { token: null, expectedStatus: 401 })
320 await addVideoInPlaylist(params)
321 })
322
323 it('Should fail with the playlist of another user', async function () {
324 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
325 await addVideoInPlaylist(params)
326 })
327
328 it('Should fail with an unknown or incorrect playlist id', async function () {
329 {
330 const params = getBase({}, { playlistId: 'toto' })
331 await addVideoInPlaylist(params)
332 }
333
334 {
335 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
336 await addVideoInPlaylist(params)
337 }
338 })
339
340 it('Should fail with an unknown or incorrect video id', async function () {
341 const params = getBase({ videoId: 42 }, { expectedStatus: 404 })
342 await addVideoInPlaylist(params)
343 })
344
345 it('Should fail with a bad start/stop timestamp', async function () {
346 {
347 const params = getBase({ startTimestamp: -42 })
348 await addVideoInPlaylist(params)
349 }
350
351 {
352 const params = getBase({ stopTimestamp: 'toto' as any })
353 await addVideoInPlaylist(params)
354 }
355 })
356
357 it('Succeed with the correct params', async function () {
358 const params = getBase({}, { expectedStatus: 200 })
359 await addVideoInPlaylist(params)
360 })
361
362 it('Should fail if the video was already added in the playlist', async function () {
363 const params = getBase({}, { expectedStatus: 409 })
364 await addVideoInPlaylist(params)
365 })
366 })
367
368 describe('When updating an element in a playlist', function () {
369 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
370 return Object.assign({
371 url: server.url,
372 token: server.accessToken,
373 elementAttrs: Object.assign({
374 startTimestamp: 1,
375 stopTimestamp: 2
376 }, elementAttrs),
377 videoId: videoId,
378 playlistId: playlistUUID,
379 expectedStatus: 400
380 }, wrapper)
381 }
382
383 it('Should fail with an unauthenticated user', async function () {
384 const params = getBase({}, { token: null, expectedStatus: 401 })
385 await updateVideoPlaylistElement(params)
386 })
387
388 it('Should fail with the playlist of another user', async function () {
389 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
390 await updateVideoPlaylistElement(params)
391 })
392
393 it('Should fail with an unknown or incorrect playlist id', async function () {
394 {
395 const params = getBase({}, { playlistId: 'toto' })
396 await updateVideoPlaylistElement(params)
397 }
398
399 {
400 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
401 await updateVideoPlaylistElement(params)
402 }
403 })
404
405 it('Should fail with an unknown or incorrect video id', async function () {
406 {
407 const params = getBase({}, { videoId: 'toto' })
408 await updateVideoPlaylistElement(params)
409 }
410
411 {
412 const params = getBase({}, { videoId: 42, expectedStatus: 404 })
413 await updateVideoPlaylistElement(params)
414 }
415 })
416
417 it('Should fail with a bad start/stop timestamp', async function () {
418 {
419 const params = getBase({ startTimestamp: 'toto' as any })
420 await updateVideoPlaylistElement(params)
421 }
422
423 {
424 const params = getBase({ stopTimestamp: -42 })
425 await updateVideoPlaylistElement(params)
426 }
427 })
428
429 it('Should fail with an unknown element', async function () {
430 const params = getBase({}, { videoId: videoId2, expectedStatus: 404 })
431 await updateVideoPlaylistElement(params)
432 })
433
434 it('Succeed with the correct params', async function () {
435 const params = getBase({}, { expectedStatus: 204 })
436 await updateVideoPlaylistElement(params)
437 })
438 })
439
440 describe('When reordering elements of a playlist', function () {
441 let videoId3: number
442 let videoId4: number
443
444 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
445 return Object.assign({
446 url: server.url,
447 token: server.accessToken,
448 playlistId: playlistUUID,
449 elementAttrs: Object.assign({
450 startPosition: 1,
451 insertAfterPosition: 2,
452 reorderLength: 3
453 }, elementAttrs),
454 expectedStatus: 400
455 }, wrapper)
456 }
457
458 before(async function () {
459 videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id
460 videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id
461
462 for (let id of [ videoId3, videoId4 ]) {
463 await addVideoInPlaylist({
464 url: server.url,
465 token: server.accessToken,
466 playlistId: playlistUUID,
467 elementAttrs: { videoId: id }
468 })
469 }
470 })
471
472 it('Should fail with an unauthenticated user', async function () {
473 const params = getBase({}, { token: null, expectedStatus: 401 })
474 await reorderVideosPlaylist(params)
475 })
476
477 it('Should fail with the playlist of another user', async function () {
478 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 })
479 await reorderVideosPlaylist(params)
480 })
481
482 it('Should fail with an invalid playlist', async function () {
483 {
484 const params = getBase({}, { playlistId: 'toto' })
485 await reorderVideosPlaylist(params)
486 }
487
488 {
489 const params = getBase({}, { playlistId: 42, expectedStatus: 404 })
490 await reorderVideosPlaylist(params)
491 }
492 })
493
494 it('Should fail with an invalid start position', async function () {
495 {
496 const params = getBase({ startPosition: -1 })
497 await reorderVideosPlaylist(params)
498 }
499
500 {
501 const params = getBase({ startPosition: 'toto' as any })
502 await reorderVideosPlaylist(params)
503 }
504
505 {
506 const params = getBase({ startPosition: 42 })
507 await reorderVideosPlaylist(params)
508 }
509 })
510
511 it('Should fail with an invalid insert after position', async function () {
512 {
513 const params = getBase({ insertAfterPosition: 'toto' as any })
514 await reorderVideosPlaylist(params)
515 }
516
517 {
518 const params = getBase({ insertAfterPosition: -2 })
519 await reorderVideosPlaylist(params)
520 }
521
522 {
523 const params = getBase({ insertAfterPosition: 42 })
524 await reorderVideosPlaylist(params)
525 }
526 })
527
528 it('Should fail with an invalid reorder length', async function () {
529 {
530 const params = getBase({ reorderLength: 'toto' as any })
531 await reorderVideosPlaylist(params)
532 }
533
534 {
535 const params = getBase({ reorderLength: -2 })
536 await reorderVideosPlaylist(params)
537 }
538
539 {
540 const params = getBase({ reorderLength: 42 })
541 await reorderVideosPlaylist(params)
542 }
543 })
544
545 it('Succeed with the correct params', async function () {
546 const params = getBase({}, { expectedStatus: 204 })
547 await reorderVideosPlaylist(params)
548 })
549 })
550
551 describe('When checking exists in playlist endpoint', function () {
552 const path = '/api/v1/users/me/video-playlists/videos-exist'
553
554 it('Should fail with an unauthenticated user', async function () {
555 await makeGetRequest({
556 url: server.url,
557 path,
558 query: { videoIds: [ 1, 2 ] },
559 statusCodeExpected: 401
560 })
561 })
562
563 it('Should fail with invalid video ids', async function () {
564 await makeGetRequest({
565 url: server.url,
566 token: server.accessToken,
567 path,
568 query: { videoIds: 'toto' }
569 })
570
571 await makeGetRequest({
572 url: server.url,
573 token: server.accessToken,
574 path,
575 query: { videoIds: [ 'toto' ] }
576 })
577
578 await makeGetRequest({
579 url: server.url,
580 token: server.accessToken,
581 path,
582 query: { videoIds: [ 1, 'toto' ] }
583 })
584 })
585
586 it('Should succeed with the correct params', async function () {
587 await makeGetRequest({
588 url: server.url,
589 token: server.accessToken,
590 path,
591 query: { videoIds: [ 1, 2 ] },
592 statusCodeExpected: 200
593 })
594 })
595 })
596
597 describe('When deleting an element in a playlist', function () {
598 const getBase = (wrapper: any = {}) => {
599 return Object.assign({
600 url: server.url,
601 token: server.accessToken,
602 videoId: videoId,
603 playlistId: playlistUUID,
604 expectedStatus: 400
605 }, wrapper)
606 }
607
608 it('Should fail with an unauthenticated user', async function () {
609 const params = getBase({ token: null, expectedStatus: 401 })
610 await removeVideoFromPlaylist(params)
611 })
612
613 it('Should fail with the playlist of another user', async function () {
614 const params = getBase({ token: userAccessToken, expectedStatus: 403 })
615 await removeVideoFromPlaylist(params)
616 })
617
618 it('Should fail with an unknown or incorrect playlist id', async function () {
619 {
620 const params = getBase({ playlistId: 'toto' })
621 await removeVideoFromPlaylist(params)
622 }
623
624 {
625 const params = getBase({ playlistId: 42, expectedStatus: 404 })
626 await removeVideoFromPlaylist(params)
627 }
628 })
629
630 it('Should fail with an unknown or incorrect video id', async function () {
631 {
632 const params = getBase({ videoId: 'toto' })
633 await removeVideoFromPlaylist(params)
634 }
635
636 {
637 const params = getBase({ videoId: 42, expectedStatus: 404 })
638 await removeVideoFromPlaylist(params)
639 }
640 })
641
642 it('Should fail with an unknown element', async function () {
643 const params = getBase({ videoId: videoId2, expectedStatus: 404 })
644 await removeVideoFromPlaylist(params)
645 })
646
647 it('Succeed with the correct params', async function () {
648 const params = getBase({ expectedStatus: 204 })
649 await removeVideoFromPlaylist(params)
650 })
651 })
652
653 describe('When deleting a playlist', function () {
654 it('Should fail with an unknown playlist', async function () {
655 await deleteVideoPlaylist(server.url, server.accessToken, 42, 404)
656 })
657
658 it('Should fail with a playlist of another user', async function () {
659 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403)
660 })
661
662 it('Should fail with the watch later playlist', async function () {
663 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, 400)
664 })
665
666 it('Should succeed with the correct params', async function () {
667 await deleteVideoPlaylist(server.url, server.accessToken, playlistUUID)
668 })
669 })
670
671 after(async function () {
672 await cleanupTests([ server ])
673 })
674})
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts
index e998c8a3d..babef8223 100644
--- a/server/tests/api/check-params/videos-filter.ts
+++ b/server/tests/api/check-params/videos-filter.ts
@@ -1,27 +1,27 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { 4import {
5 cleanupTests,
6 createUser, 6 createUser,
7 flushTests, 7 createVideoPlaylist,
8 killallServers, 8 flushAndRunServer,
9 makeGetRequest, 9 makeGetRequest,
10 runServer,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 userLogin 13 userLogin
14} from '../../../../shared/utils' 14} from '../../../../shared/extra-utils'
15import { UserRole } from '../../../../shared/models/users' 15import { UserRole } from '../../../../shared/models/users'
16import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
16 17
17const expect = chai.expect 18async function testEndpoints (server: ServerInfo, token: string, filter: string, playlistUUID: string, statusCodeExpected: number) {
18
19async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) {
20 const paths = [ 19 const paths = [
21 '/api/v1/video-channels/root_channel/videos', 20 '/api/v1/video-channels/root_channel/videos',
22 '/api/v1/accounts/root/videos', 21 '/api/v1/accounts/root/videos',
23 '/api/v1/videos', 22 '/api/v1/videos',
24 '/api/v1/search/videos' 23 '/api/v1/search/videos',
24 '/api/v1/video-playlists/' + playlistUUID + '/videos'
25 ] 25 ]
26 26
27 for (const path of paths) { 27 for (const path of paths) {
@@ -41,55 +41,68 @@ describe('Test videos filters', function () {
41 let server: ServerInfo 41 let server: ServerInfo
42 let userAccessToken: string 42 let userAccessToken: string
43 let moderatorAccessToken: string 43 let moderatorAccessToken: string
44 let playlistUUID: string
44 45
45 // --------------------------------------------------------------- 46 // ---------------------------------------------------------------
46 47
47 before(async function () { 48 before(async function () {
48 this.timeout(30000) 49 this.timeout(30000)
49 50
50 await flushTests() 51 server = await flushAndRunServer(1)
51
52 server = await runServer(1)
53 52
54 await setAccessTokensToServers([ server ]) 53 await setAccessTokensToServers([ server ])
54 await setDefaultVideoChannel([ server ])
55 55
56 const user = { username: 'user1', password: 'my super password' } 56 const user = { username: 'user1', password: 'my super password' }
57 await createUser(server.url, server.accessToken, user.username, user.password) 57 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
58 userAccessToken = await userLogin(server, user) 58 userAccessToken = await userLogin(server, user)
59 59
60 const moderator = { username: 'moderator', password: 'my super password' } 60 const moderator = { username: 'moderator', password: 'my super password' }
61 await createUser( 61 await createUser(
62 server.url, 62 {
63 server.accessToken, 63 url: server.url,
64 moderator.username, 64 accessToken: server.accessToken,
65 moderator.password, 65 username: moderator.username,
66 undefined, 66 password: moderator.password,
67 undefined, 67 videoQuota: undefined,
68 UserRole.MODERATOR 68 videoQuotaDaily: undefined,
69 role: UserRole.MODERATOR
70 }
69 ) 71 )
70 moderatorAccessToken = await userLogin(server, moderator) 72 moderatorAccessToken = await userLogin(server, moderator)
73
74 const res = await createVideoPlaylist({
75 url: server.url,
76 token: server.accessToken,
77 playlistAttrs: {
78 displayName: 'super playlist',
79 privacy: VideoPlaylistPrivacy.PUBLIC,
80 videoChannelId: server.videoChannel.id
81 }
82 })
83 playlistUUID = res.body.videoPlaylist.uuid
71 }) 84 })
72 85
73 describe('When setting a video filter', function () { 86 describe('When setting a video filter', function () {
74 87
75 it('Should fail with a bad filter', async function () { 88 it('Should fail with a bad filter', async function () {
76 await testEndpoints(server, server.accessToken, 'bad-filter', 400) 89 await testEndpoints(server, server.accessToken, 'bad-filter', playlistUUID, 400)
77 }) 90 })
78 91
79 it('Should succeed with a good filter', async function () { 92 it('Should succeed with a good filter', async function () {
80 await testEndpoints(server, server.accessToken,'local', 200) 93 await testEndpoints(server, server.accessToken,'local', playlistUUID, 200)
81 }) 94 })
82 95
83 it('Should fail to list all-local with a simple user', async function () { 96 it('Should fail to list all-local with a simple user', async function () {
84 await testEndpoints(server, userAccessToken, 'all-local', 401) 97 await testEndpoints(server, userAccessToken, 'all-local', playlistUUID, 401)
85 }) 98 })
86 99
87 it('Should succeed to list all-local with a moderator', async function () { 100 it('Should succeed to list all-local with a moderator', async function () {
88 await testEndpoints(server, moderatorAccessToken, 'all-local', 200) 101 await testEndpoints(server, moderatorAccessToken, 'all-local', playlistUUID, 200)
89 }) 102 })
90 103
91 it('Should succeed to list all-local with an admin', async function () { 104 it('Should succeed to list all-local with an admin', async function () {
92 await testEndpoints(server, server.accessToken, 'all-local', 200) 105 await testEndpoints(server, server.accessToken, 'all-local', playlistUUID, 200)
93 }) 106 })
94 107
95 // Because we cannot authenticate the user on the RSS endpoint 108 // Because we cannot authenticate the user on the RSS endpoint
@@ -104,7 +117,7 @@ describe('Test videos filters', function () {
104 }) 117 })
105 }) 118 })
106 119
107 it('Should succed on the feeds endpoint with the local filter', async function () { 120 it('Should succeed on the feeds endpoint with the local filter', async function () {
108 await makeGetRequest({ 121 await makeGetRequest({
109 url: server.url, 122 url: server.url,
110 path: '/feeds/videos.json', 123 path: '/feeds/videos.json',
@@ -117,11 +130,6 @@ describe('Test videos filters', function () {
117 }) 130 })
118 131
119 after(async function () { 132 after(async function () {
120 killallServers([ server ]) 133 await cleanupTests([ server ])
121
122 // Keep the logs if the test failed
123 if (this['ok']) {
124 await flushTests()
125 }
126 }) 134 })
127}) 135})
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts
index 8c079a956..3739e3fad 100644
--- a/server/tests/api/check-params/videos-history.ts
+++ b/server/tests/api/check-params/videos-history.ts
@@ -5,16 +5,15 @@ import 'mocha'
5import { 5import {
6 checkBadCountPagination, 6 checkBadCountPagination,
7 checkBadStartPagination, 7 checkBadStartPagination,
8 flushTests, 8 cleanupTests,
9 killallServers, 9 flushAndRunServer,
10 makeGetRequest, 10 makeGetRequest,
11 makePostBodyRequest, 11 makePostBodyRequest,
12 makePutBodyRequest, 12 makePutBodyRequest,
13 runServer,
14 ServerInfo, 13 ServerInfo,
15 setAccessTokensToServers, 14 setAccessTokensToServers,
16 uploadVideo 15 uploadVideo
17} from '../../../../shared/utils' 16} from '../../../../shared/extra-utils'
18 17
19const expect = chai.expect 18const expect = chai.expect
20 19
@@ -29,9 +28,7 @@ describe('Test videos history API validator', function () {
29 before(async function () { 28 before(async function () {
30 this.timeout(30000) 29 this.timeout(30000)
31 30
32 await flushTests() 31 server = await flushAndRunServer(1)
33
34 server = await runServer(1)
35 32
36 await setAccessTokensToServers([ server ]) 33 await setAccessTokensToServers([ server ])
37 34
@@ -129,11 +126,6 @@ describe('Test videos history API validator', function () {
129 }) 126 })
130 127
131 after(async function () { 128 after(async function () {
132 killallServers([ server ]) 129 await cleanupTests([ server ])
133
134 // Keep the logs if the test failed
135 if (this['ok']) {
136 await flushTests()
137 }
138 }) 130 })
139}) 131})
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index f26b91435..51e592a15 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -6,15 +6,28 @@ import 'mocha'
6import { join } from 'path' 6import { join } from 'path'
7import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 7import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
8import { 8import {
9 createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, 9 cleanupTests,
10 makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin 10 createUser,
11} from '../../../../shared/utils' 11 flushAndRunServer,
12 getMyUserInformation,
13 getVideo,
14 getVideosList,
15 immutableAssign,
16 makeDeleteRequest,
17 makeGetRequest,
18 makePutBodyRequest,
19 makeUploadRequest,
20 removeVideo,
21 ServerInfo,
22 setAccessTokensToServers,
23 userLogin,
24 root
25} from '../../../../shared/extra-utils'
12import { 26import {
13 checkBadCountPagination, 27 checkBadCountPagination,
14 checkBadSortPagination, 28 checkBadSortPagination,
15 checkBadStartPagination 29 checkBadStartPagination
16} from '../../../../shared/utils/requests/check-api-params' 30} from '../../../../shared/extra-utils/requests/check-api-params'
17import { getAccountsList } from '../../../../shared/utils/users/accounts'
18 31
19const expect = chai.expect 32const expect = chai.expect
20 33
@@ -32,15 +45,13 @@ describe('Test videos API validator', function () {
32 before(async function () { 45 before(async function () {
33 this.timeout(30000) 46 this.timeout(30000)
34 47
35 await flushTests() 48 server = await flushAndRunServer(1)
36
37 server = await runServer(1)
38 49
39 await setAccessTokensToServers([ server ]) 50 await setAccessTokensToServers([ server ])
40 51
41 const username = 'user1' 52 const username = 'user1'
42 const password = 'my super password' 53 const password = 'my super password'
43 await createUser(server.url, server.accessToken, username, password) 54 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
44 userAccessToken = await userLogin(server, { username, password }) 55 userAccessToken = await userLogin(server, { username, password })
45 56
46 { 57 {
@@ -167,7 +178,7 @@ describe('Test videos API validator', function () {
167 describe('When adding a video', function () { 178 describe('When adding a video', function () {
168 let baseCorrectParams 179 let baseCorrectParams
169 const baseCorrectAttaches = { 180 const baseCorrectAttaches = {
170 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm') 181 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
171 } 182 }
172 183
173 before(function () { 184 before(function () {
@@ -179,12 +190,14 @@ describe('Test videos API validator', function () {
179 language: 'pt', 190 language: 'pt',
180 nsfw: false, 191 nsfw: false,
181 commentsEnabled: true, 192 commentsEnabled: true,
193 downloadEnabled: true,
182 waitTranscoding: true, 194 waitTranscoding: true,
183 description: 'my super description', 195 description: 'my super description',
184 support: 'my super support text', 196 support: 'my super support text',
185 tags: [ 'tag1', 'tag2' ], 197 tags: [ 'tag1', 'tag2' ],
186 privacy: VideoPrivacy.PUBLIC, 198 privacy: VideoPrivacy.PUBLIC,
187 channelId: channelId 199 channelId: channelId,
200 originallyPublishedAt: new Date().toISOString()
188 } 201 }
189 }) 202 })
190 203
@@ -262,7 +275,7 @@ describe('Test videos API validator', function () {
262 username: 'fake', 275 username: 'fake',
263 password: 'fake_password' 276 password: 'fake_password'
264 } 277 }
265 await createUser(server.url, server.accessToken, user.username, user.password) 278 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
266 279
267 const accessTokenUser = await userLogin(server, user) 280 const accessTokenUser = await userLogin(server, user)
268 const res = await getMyUserInformation(server.url, accessTokenUser) 281 const res = await getMyUserInformation(server.url, accessTokenUser)
@@ -312,21 +325,28 @@ describe('Test videos API validator', function () {
312 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 325 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
313 }) 326 })
314 327
328 it('Should fail with a bad originally published at attribute', async function () {
329 const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' })
330 const attaches = baseCorrectAttaches
331
332 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
333 })
334
315 it('Should fail without an input file', async function () { 335 it('Should fail without an input file', async function () {
316 const fields = baseCorrectParams 336 const fields = baseCorrectParams
317 const attaches = {} 337 const attaches = {}
318 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 338 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
319 }) 339 })
320 340
321 it('Should fail without an incorrect input file', async function () { 341 it('Should fail with an incorrect input file', async function () {
322 const fields = baseCorrectParams 342 const fields = baseCorrectParams
323 let attaches = { 343 let attaches = {
324 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') 344 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm')
325 } 345 }
326 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 346 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
327 347
328 attaches = { 348 attaches = {
329 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv') 349 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv')
330 } 350 }
331 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 351 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
332 }) 352 })
@@ -334,8 +354,8 @@ describe('Test videos API validator', function () {
334 it('Should fail with an incorrect thumbnail file', async function () { 354 it('Should fail with an incorrect thumbnail file', async function () {
335 const fields = baseCorrectParams 355 const fields = baseCorrectParams
336 const attaches = { 356 const attaches = {
337 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'), 357 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
338 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') 358 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
339 } 359 }
340 360
341 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 361 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -344,8 +364,8 @@ describe('Test videos API validator', function () {
344 it('Should fail with a big thumbnail file', async function () { 364 it('Should fail with a big thumbnail file', async function () {
345 const fields = baseCorrectParams 365 const fields = baseCorrectParams
346 const attaches = { 366 const attaches = {
347 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), 367 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
348 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') 368 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
349 } 369 }
350 370
351 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 371 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -354,8 +374,8 @@ describe('Test videos API validator', function () {
354 it('Should fail with an incorrect preview file', async function () { 374 it('Should fail with an incorrect preview file', async function () {
355 const fields = baseCorrectParams 375 const fields = baseCorrectParams
356 const attaches = { 376 const attaches = {
357 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'), 377 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
358 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') 378 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
359 } 379 }
360 380
361 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 381 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -364,8 +384,8 @@ describe('Test videos API validator', function () {
364 it('Should fail with a big preview file', async function () { 384 it('Should fail with a big preview file', async function () {
365 const fields = baseCorrectParams 385 const fields = baseCorrectParams
366 const attaches = { 386 const attaches = {
367 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), 387 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
368 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') 388 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
369 } 389 }
370 390
371 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) 391 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -390,7 +410,7 @@ describe('Test videos API validator', function () {
390 410
391 { 411 {
392 const attaches = immutableAssign(baseCorrectAttaches, { 412 const attaches = immutableAssign(baseCorrectAttaches, {
393 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') 413 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
394 }) 414 })
395 415
396 await makeUploadRequest({ 416 await makeUploadRequest({
@@ -405,7 +425,7 @@ describe('Test videos API validator', function () {
405 425
406 { 426 {
407 const attaches = immutableAssign(baseCorrectAttaches, { 427 const attaches = immutableAssign(baseCorrectAttaches, {
408 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv') 428 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
409 }) 429 })
410 430
411 await makeUploadRequest({ 431 await makeUploadRequest({
@@ -428,6 +448,7 @@ describe('Test videos API validator', function () {
428 language: 'pt', 448 language: 'pt',
429 nsfw: false, 449 nsfw: false,
430 commentsEnabled: false, 450 commentsEnabled: false,
451 downloadEnabled: false,
431 description: 'my super description', 452 description: 'my super description',
432 privacy: VideoPrivacy.PUBLIC, 453 privacy: VideoPrivacy.PUBLIC,
433 tags: [ 'tag1', 'tag2' ] 454 tags: [ 'tag1', 'tag2' ]
@@ -532,10 +553,16 @@ describe('Test videos API validator', function () {
532 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) 553 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
533 }) 554 })
534 555
556 it('Should fail with a bad originally published at param', async function () {
557 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
558
559 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
560 })
561
535 it('Should fail with an incorrect thumbnail file', async function () { 562 it('Should fail with an incorrect thumbnail file', async function () {
536 const fields = baseCorrectParams 563 const fields = baseCorrectParams
537 const attaches = { 564 const attaches = {
538 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') 565 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
539 } 566 }
540 567
541 await makeUploadRequest({ 568 await makeUploadRequest({
@@ -551,7 +578,7 @@ describe('Test videos API validator', function () {
551 it('Should fail with a big thumbnail file', async function () { 578 it('Should fail with a big thumbnail file', async function () {
552 const fields = baseCorrectParams 579 const fields = baseCorrectParams
553 const attaches = { 580 const attaches = {
554 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') 581 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
555 } 582 }
556 583
557 await makeUploadRequest({ 584 await makeUploadRequest({
@@ -567,7 +594,7 @@ describe('Test videos API validator', function () {
567 it('Should fail with an incorrect preview file', async function () { 594 it('Should fail with an incorrect preview file', async function () {
568 const fields = baseCorrectParams 595 const fields = baseCorrectParams
569 const attaches = { 596 const attaches = {
570 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') 597 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
571 } 598 }
572 599
573 await makeUploadRequest({ 600 await makeUploadRequest({
@@ -583,7 +610,7 @@ describe('Test videos API validator', function () {
583 it('Should fail with a big preview file', async function () { 610 it('Should fail with a big preview file', async function () {
584 const fields = baseCorrectParams 611 const fields = baseCorrectParams
585 const attaches = { 612 const attaches = {
586 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') 613 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
587 } 614 }
588 615
589 await makeUploadRequest({ 616 await makeUploadRequest({
@@ -714,11 +741,6 @@ describe('Test videos API validator', function () {
714 }) 741 })
715 742
716 after(async function () { 743 after(async function () {
717 killallServers([ server ]) 744 await cleanupTests([ server ])
718
719 // Keep the logs if the test failed
720 if (this['ok']) {
721 await flushTests()
722 }
723 }) 745 })
724}) 746})
diff --git a/server/tests/api/index-1.ts b/server/tests/api/index-1.ts
index 80d752f42..75cdd9025 100644
--- a/server/tests/api/index-1.ts
+++ b/server/tests/api/index-1.ts
@@ -1,2 +1,3 @@
1import './check-params' 1import './check-params'
2import './notifications'
2import './search' 3import './search'
diff --git a/server/tests/api/notifications/index.ts b/server/tests/api/notifications/index.ts
new file mode 100644
index 000000000..95ac8fc51
--- /dev/null
+++ b/server/tests/api/notifications/index.ts
@@ -0,0 +1 @@
export * from './user-notifications'
diff --git a/server/tests/api/users/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 72b6a0aa2..f479e1785 100644
--- a/server/tests/api/users/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -4,25 +4,30 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 addVideoToBlacklist, 6 addVideoToBlacklist,
7 cleanupTests,
7 createUser, 8 createUser,
8 doubleFollow, 9 doubleFollow,
9 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
10 flushTests, 11 follow,
12 getCustomConfig,
11 getMyUserInformation, 13 getMyUserInformation,
14 getVideoCommentThreads,
15 getVideoThreadComments,
12 immutableAssign, 16 immutableAssign,
13 registerUser, 17 registerUser,
14 removeVideoFromBlacklist, 18 removeVideoFromBlacklist,
15 reportVideoAbuse, 19 reportVideoAbuse,
20 updateCustomConfig,
16 updateMyUser, 21 updateMyUser,
17 updateVideo, 22 updateVideo,
18 updateVideoChannel, 23 updateVideoChannel,
19 userLogin, 24 userLogin,
20 wait 25 wait
21} from '../../../../shared/utils' 26} from '../../../../shared/extra-utils'
22import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index' 27import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
23import { setAccessTokensToServers } from '../../../../shared/utils/users/login' 28import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
24import { waitJobs } from '../../../../shared/utils/server/jobs' 29import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
25import { getUserNotificationSocket } from '../../../../shared/utils/socket/socket-io' 30import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
26import { 31import {
27 checkCommentMention, 32 checkCommentMention,
28 CheckerBaseParams, 33 CheckerBaseParams,
@@ -30,16 +35,18 @@ import {
30 checkNewActorFollow, 35 checkNewActorFollow,
31 checkNewBlacklistOnMyVideo, 36 checkNewBlacklistOnMyVideo,
32 checkNewCommentOnMyVideo, 37 checkNewCommentOnMyVideo,
38 checkNewInstanceFollower,
33 checkNewVideoAbuseForModerators, 39 checkNewVideoAbuseForModerators,
34 checkNewVideoFromSubscription, 40 checkNewVideoFromSubscription,
35 checkUserRegistered, 41 checkUserRegistered,
42 checkVideoAutoBlacklistForModerators,
36 checkVideoIsPublished, 43 checkVideoIsPublished,
37 getLastNotification, 44 getLastNotification,
38 getUserNotifications, 45 getUserNotifications,
46 markAsReadAllNotifications,
39 markAsReadNotifications, 47 markAsReadNotifications,
40 updateMyNotificationSettings, 48 updateMyNotificationSettings
41 markAsReadAllNotifications 49} from '../../../../shared/extra-utils/users/user-notifications'
42} from '../../../../shared/utils/users/user-notifications'
43import { 50import {
44 User, 51 User,
45 UserNotification, 52 UserNotification,
@@ -47,13 +54,15 @@ import {
47 UserNotificationSettingValue, 54 UserNotificationSettingValue,
48 UserNotificationType 55 UserNotificationType
49} from '../../../../shared/models/users' 56} from '../../../../shared/models/users'
50import { MockSmtpServer } from '../../../../shared/utils/miscs/email' 57import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
51import { addUserSubscription, removeUserSubscription } from '../../../../shared/utils/users/user-subscriptions' 58import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions'
52import { VideoPrivacy } from '../../../../shared/models/videos' 59import { VideoPrivacy } from '../../../../shared/models/videos'
53import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/utils/videos/video-imports' 60import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
54import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' 61import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
55import * as uuidv4 from 'uuid/v4' 62import * as uuidv4 from 'uuid/v4'
56import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/utils/users/blocklist' 63import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
64import { CustomConfig } from '../../../../shared/models/server'
65import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
57 66
58const expect = chai.expect 67const expect = chai.expect
59 68
@@ -92,12 +101,14 @@ describe('Test users notifications', function () {
92 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 101 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
93 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 102 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
94 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 103 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
104 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
95 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 105 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
96 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 106 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
97 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 107 myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
98 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 108 commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
99 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 109 newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
100 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 110 newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
111 newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
101 } 112 }
102 113
103 before(async function () { 114 before(async function () {
@@ -105,14 +116,12 @@ describe('Test users notifications', function () {
105 116
106 await MockSmtpServer.Instance.collectEmails(emails) 117 await MockSmtpServer.Instance.collectEmails(emails)
107 118
108 await flushTests()
109
110 const overrideConfig = { 119 const overrideConfig = {
111 smtp: { 120 smtp: {
112 hostname: 'localhost' 121 hostname: 'localhost'
113 } 122 }
114 } 123 }
115 servers = await flushAndRunMultipleServers(2, overrideConfig) 124 servers = await flushAndRunMultipleServers(3, overrideConfig)
116 125
117 // Get the access tokens 126 // Get the access tokens
118 await setAccessTokensToServers(servers) 127 await setAccessTokensToServers(servers)
@@ -126,7 +135,13 @@ describe('Test users notifications', function () {
126 username: 'user_1', 135 username: 'user_1',
127 password: 'super password' 136 password: 'super password'
128 } 137 }
129 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000) 138 await createUser({
139 url: servers[ 0 ].url,
140 accessToken: servers[ 0 ].accessToken,
141 username: user.username,
142 password: user.password,
143 videoQuota: 10 * 1000 * 1000
144 })
130 userAccessToken = await userLogin(servers[0], user) 145 userAccessToken = await userLogin(servers[0], user)
131 146
132 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings) 147 await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)
@@ -165,6 +180,8 @@ describe('Test users notifications', function () {
165 }) 180 })
166 181
167 it('Should not send notifications if the user does not follow the video publisher', async function () { 182 it('Should not send notifications if the user does not follow the video publisher', async function () {
183 this.timeout(10000)
184
168 await uploadVideoByLocalAccount(servers) 185 await uploadVideoByLocalAccount(servers)
169 186
170 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken) 187 const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
@@ -214,7 +231,7 @@ describe('Test users notifications', function () {
214 }) 231 })
215 232
216 it('Should send a new video notification on a remote scheduled publication', async function () { 233 it('Should send a new video notification on a remote scheduled publication', async function () {
217 this.timeout(20000) 234 this.timeout(50000)
218 235
219 // In 2 seconds 236 // In 2 seconds
220 let updateAt = new Date(new Date().getTime() + 2000) 237 let updateAt = new Date(new Date().getTime() + 2000)
@@ -236,7 +253,7 @@ describe('Test users notifications', function () {
236 it('Should not send a notification before the video is published', async function () { 253 it('Should not send a notification before the video is published', async function () {
237 this.timeout(20000) 254 this.timeout(20000)
238 255
239 let updateAt = new Date(new Date().getTime() + 100000) 256 let updateAt = new Date(new Date().getTime() + 1000000)
240 257
241 const data = { 258 const data = {
242 privacy: VideoPrivacy.PRIVATE, 259 privacy: VideoPrivacy.PRIVATE,
@@ -303,7 +320,7 @@ describe('Test users notifications', function () {
303 }) 320 })
304 321
305 it('Should send a new video notification after a video import', async function () { 322 it('Should send a new video notification after a video import', async function () {
306 this.timeout(30000) 323 this.timeout(100000)
307 324
308 const name = 'video import ' + uuidv4() 325 const name = 'video import ' + uuidv4()
309 326
@@ -398,10 +415,14 @@ describe('Test users notifications', function () {
398 415
399 await waitJobs(servers) 416 await waitJobs(servers)
400 417
401 const resComment = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') 418 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
402 const commentId = resComment.body.comment.id
403 419
404 await waitJobs(servers) 420 await waitJobs(servers)
421
422 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
423 expect(resComment.body.data).to.have.lengthOf(1)
424 const commentId = resComment.body.data[0].id
425
405 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') 426 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
406 }) 427 })
407 428
@@ -428,13 +449,24 @@ describe('Test users notifications', function () {
428 const uuid = resVideo.body.video.uuid 449 const uuid = resVideo.body.video.uuid
429 await waitJobs(servers) 450 await waitJobs(servers)
430 451
431 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') 452 {
432 const threadId = resThread.body.comment.id 453 const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
433 454 const threadId = resThread.body.comment.id
434 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply') 455 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
435 const commentId = resComment.body.comment.id 456 }
436 457
437 await waitJobs(servers) 458 await waitJobs(servers)
459
460 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
461 expect(resThread.body.data).to.have.lengthOf(1)
462 const threadId = resThread.body.data[0].id
463
464 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
465 const tree = resComments.body as VideoCommentThreadTree
466
467 expect(tree.children).to.have.lengthOf(1)
468 const commentId = tree.children[0].comment.id
469
438 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') 470 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
439 }) 471 })
440 }) 472 })
@@ -547,17 +579,27 @@ describe('Test users notifications', function () {
547 579
548 await waitJobs(servers) 580 await waitJobs(servers)
549 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1') 581 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'hello @user_1@localhost:9001 1')
550 const threadId = resThread.body.comment.id 582 const server2ThreadId = resThread.body.comment.id
551 583
552 await waitJobs(servers) 584 await waitJobs(servers)
553 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'presence') 585
586 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
587 expect(resThread2.body.data).to.have.lengthOf(1)
588 const server1ThreadId = resThread2.body.data[0].id
589 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
554 590
555 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001' 591 const text = '@user_1@localhost:9001 hello 2 @root@localhost:9001'
556 const resComment = await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, text) 592 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text)
557 const commentId = resComment.body.comment.id
558 593
559 await waitJobs(servers) 594 await waitJobs(servers)
560 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root 2 name', 'presence') 595
596 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
597 const tree = resComments.body as VideoCommentThreadTree
598
599 expect(tree.children).to.have.lengthOf(1)
600 const commentId = tree.children[0].comment.id
601
602 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
561 }) 603 })
562 }) 604 })
563 605
@@ -658,6 +700,8 @@ describe('Test users notifications', function () {
658 }) 700 })
659 701
660 it('Should not send a notification if transcoding is not enabled', async function () { 702 it('Should not send a notification if transcoding is not enabled', async function () {
703 this.timeout(10000)
704
661 const { name, uuid } = await uploadVideoByLocalAccount(servers) 705 const { name, uuid } = await uploadVideoByLocalAccount(servers)
662 await waitJobs(servers) 706 await waitJobs(servers)
663 707
@@ -731,6 +775,24 @@ describe('Test users notifications', function () {
731 await wait(6000) 775 await wait(6000)
732 await checkVideoIsPublished(baseParams, name, uuid, 'presence') 776 await checkVideoIsPublished(baseParams, name, uuid, 'presence')
733 }) 777 })
778
779 it('Should not send a notification before the video is published', async function () {
780 this.timeout(20000)
781
782 let updateAt = new Date(new Date().getTime() + 100000)
783
784 const data = {
785 privacy: VideoPrivacy.PRIVATE,
786 scheduleUpdate: {
787 updateAt: updateAt.toISOString(),
788 privacy: VideoPrivacy.PUBLIC
789 }
790 }
791 const { name, uuid } = await uploadVideoByRemoteAccount(servers, data)
792
793 await wait(6000)
794 await checkVideoIsPublished(baseParams, name, uuid, 'absence')
795 })
734 }) 796 })
735 797
736 describe('My video is imported', function () { 798 describe('My video is imported', function () {
@@ -795,6 +857,8 @@ describe('Test users notifications', function () {
795 }) 857 })
796 858
797 it('Should send a notification only to moderators when a user registers on the instance', async function () { 859 it('Should send a notification only to moderators when a user registers on the instance', async function () {
860 this.timeout(10000)
861
798 await registerUser(servers[0].url, 'user_45', 'password') 862 await registerUser(servers[0].url, 'user_45', 'password')
799 863
800 await waitJobs(servers) 864 await waitJobs(servers)
@@ -806,6 +870,32 @@ describe('Test users notifications', function () {
806 }) 870 })
807 }) 871 })
808 872
873 describe('New instance follower', function () {
874 let baseParams: CheckerBaseParams
875
876 before(async () => {
877 baseParams = {
878 server: servers[0],
879 emails,
880 socketNotifications: adminNotifications,
881 token: servers[0].accessToken
882 }
883 })
884
885 it('Should send a notification only to admin when there is a new instance follower', async function () {
886 this.timeout(20000)
887
888 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
889
890 await waitJobs(servers)
891
892 await checkNewInstanceFollower(baseParams, 'localhost:9003', 'presence')
893
894 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
895 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:9003', 'absence')
896 })
897 })
898
809 describe('New actor follow', function () { 899 describe('New actor follow', function () {
810 let baseParams: CheckerBaseParams 900 let baseParams: CheckerBaseParams
811 let myChannelName = 'super channel name' 901 let myChannelName = 'super channel name'
@@ -863,6 +953,8 @@ describe('Test users notifications', function () {
863 }) 953 })
864 954
865 it('Should notify when a local account is following one of our channel', async function () { 955 it('Should notify when a local account is following one of our channel', async function () {
956 this.timeout(10000)
957
866 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001') 958 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:9001')
867 959
868 await waitJobs(servers) 960 await waitJobs(servers)
@@ -871,6 +963,8 @@ describe('Test users notifications', function () {
871 }) 963 })
872 964
873 it('Should notify when a remote account is following one of our channel', async function () { 965 it('Should notify when a remote account is following one of our channel', async function () {
966 this.timeout(10000)
967
874 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001') 968 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1@localhost:9001')
875 969
876 await waitJobs(servers) 970 await waitJobs(servers)
@@ -879,6 +973,180 @@ describe('Test users notifications', function () {
879 }) 973 })
880 }) 974 })
881 975
976 describe('Video-related notifications when video auto-blacklist is enabled', function () {
977 let userBaseParams: CheckerBaseParams
978 let adminBaseParamsServer1: CheckerBaseParams
979 let adminBaseParamsServer2: CheckerBaseParams
980 let videoUUID: string
981 let videoName: string
982 let currentCustomConfig: CustomConfig
983
984 before(async () => {
985
986 adminBaseParamsServer1 = {
987 server: servers[0],
988 emails,
989 socketNotifications: adminNotifications,
990 token: servers[0].accessToken
991 }
992
993 adminBaseParamsServer2 = {
994 server: servers[1],
995 emails,
996 socketNotifications: adminNotificationsServer2,
997 token: servers[1].accessToken
998 }
999
1000 userBaseParams = {
1001 server: servers[0],
1002 emails,
1003 socketNotifications: userNotifications,
1004 token: userAccessToken
1005 }
1006
1007 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken)
1008 currentCustomConfig = resCustomConfig.body
1009 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, {
1010 autoBlacklist: {
1011 videos: {
1012 ofUsers: {
1013 enabled: true
1014 }
1015 }
1016 }
1017 })
1018 // enable transcoding otherwise own publish notification after transcoding not expected
1019 autoBlacklistTestsCustomConfig.transcoding.enabled = true
1020 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig)
1021
1022 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1023 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1024
1025 })
1026
1027 it('Should send notification to moderators on new video with auto-blacklist', async function () {
1028 this.timeout(20000)
1029
1030 videoName = 'video with auto-blacklist ' + uuidv4()
1031 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName })
1032 videoUUID = resVideo.body.video.uuid
1033
1034 await waitJobs(servers)
1035 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
1036 })
1037
1038 it('Should not send video publish notification if auto-blacklisted', async function () {
1039 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
1040 })
1041
1042 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
1043 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
1044 })
1045
1046 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
1047 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
1048 })
1049
1050 it('Should send video published and unblacklist after video unblacklisted', async function () {
1051 this.timeout(20000)
1052
1053 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID)
1054
1055 await waitJobs(servers)
1056
1057 // FIXME: Can't test as two notifications sent to same user and util only checks last one
1058 // One notification might be better anyways
1059 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
1060 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
1061 })
1062
1063 it('Should send a local user subscription notification after removed from blacklist', async function () {
1064 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
1065 })
1066
1067 it('Should send a remote user subscription notification after removed from blacklist', async function () {
1068 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
1069 })
1070
1071 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
1072 this.timeout(20000)
1073
1074 let updateAt = new Date(new Date().getTime() + 100000)
1075
1076 const name = 'video with auto-blacklist and future schedule ' + uuidv4()
1077
1078 const data = {
1079 name,
1080 privacy: VideoPrivacy.PRIVATE,
1081 scheduleUpdate: {
1082 updateAt: updateAt.toISOString(),
1083 privacy: VideoPrivacy.PUBLIC
1084 }
1085 }
1086
1087 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1088 const uuid = resVideo.body.video.uuid
1089
1090 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid)
1091
1092 await waitJobs(servers)
1093 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
1094
1095 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
1096 // One notification might be better anyways
1097 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1098
1099 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1100 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1101 })
1102
1103 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
1104 this.timeout(20000)
1105
1106 // In 2 seconds
1107 let updateAt = new Date(new Date().getTime() + 2000)
1108
1109 const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
1110
1111 const data = {
1112 name,
1113 privacy: VideoPrivacy.PRIVATE,
1114 scheduleUpdate: {
1115 updateAt: updateAt.toISOString(),
1116 privacy: VideoPrivacy.PUBLIC
1117 }
1118 }
1119
1120 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
1121 const uuid = resVideo.body.video.uuid
1122
1123 await wait(6000)
1124 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
1125 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
1126 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
1127 })
1128
1129 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
1130 this.timeout(20000)
1131
1132 const name = 'video without auto-blacklist ' + uuidv4()
1133
1134 // admin with blacklist right will not be auto-blacklisted
1135 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name })
1136 const uuid = resVideo.body.video.uuid
1137
1138 await waitJobs(servers)
1139 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
1140 })
1141
1142 after(async () => {
1143 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig)
1144
1145 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:9001')
1146 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:9001')
1147 })
1148 })
1149
882 describe('Mark as read', function () { 1150 describe('Mark as read', function () {
883 it('Should mark as read some notifications', async function () { 1151 it('Should mark as read some notifications', async function () {
884 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3) 1152 const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
@@ -940,6 +1208,8 @@ describe('Test users notifications', function () {
940 }) 1208 })
941 1209
942 it('Should not have notifications', async function () { 1210 it('Should not have notifications', async function () {
1211 this.timeout(20000)
1212
943 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { 1213 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
944 newVideoFromSubscription: UserNotificationSettingValue.NONE 1214 newVideoFromSubscription: UserNotificationSettingValue.NONE
945 })) 1215 }))
@@ -957,6 +1227,8 @@ describe('Test users notifications', function () {
957 }) 1227 })
958 1228
959 it('Should only have web notifications', async function () { 1229 it('Should only have web notifications', async function () {
1230 this.timeout(20000)
1231
960 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { 1232 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
961 newVideoFromSubscription: UserNotificationSettingValue.WEB 1233 newVideoFromSubscription: UserNotificationSettingValue.WEB
962 })) 1234 }))
@@ -981,6 +1253,8 @@ describe('Test users notifications', function () {
981 }) 1253 })
982 1254
983 it('Should only have mail notifications', async function () { 1255 it('Should only have mail notifications', async function () {
1256 this.timeout(20000)
1257
984 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { 1258 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
985 newVideoFromSubscription: UserNotificationSettingValue.EMAIL 1259 newVideoFromSubscription: UserNotificationSettingValue.EMAIL
986 })) 1260 }))
@@ -1005,6 +1279,8 @@ describe('Test users notifications', function () {
1005 }) 1279 })
1006 1280
1007 it('Should have email and web notifications', async function () { 1281 it('Should have email and web notifications', async function () {
1282 this.timeout(20000)
1283
1008 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { 1284 await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, {
1009 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 1285 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
1010 })) 1286 }))
@@ -1026,6 +1302,6 @@ describe('Test users notifications', function () {
1026 after(async function () { 1302 after(async function () {
1027 MockSmtpServer.Instance.kill() 1303 MockSmtpServer.Instance.kill()
1028 1304
1029 killallServers(servers) 1305 await cleanupTests(servers)
1030 }) 1306 })
1031}) 1307})
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index 9d3ce8153..e31329c25 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -4,30 +4,36 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoDetails } from '../../../../shared/models/videos' 5import { VideoDetails } from '../../../../shared/models/videos'
6import { 6import {
7 checkSegmentHash,
8 checkVideoFilesWereRemoved, cleanupTests,
7 doubleFollow, 9 doubleFollow,
8 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
9 getFollowingListPaginationAndSort, 11 getFollowingListPaginationAndSort,
10 getVideo, 12 getVideo,
13 getVideoWithToken,
11 immutableAssign, 14 immutableAssign,
12 killallServers, makeGetRequest, 15 killallServers,
16 makeGetRequest,
17 removeVideo,
18 reRunServer,
13 root, 19 root,
14 ServerInfo, 20 ServerInfo,
15 setAccessTokensToServers, unfollow, 21 setAccessTokensToServers,
22 unfollow,
16 uploadVideo, 23 uploadVideo,
17 viewVideo, 24 viewVideo,
18 wait, 25 wait,
19 waitUntilLog, 26 waitUntilLog
20 checkVideoFilesWereRemoved, removeVideo, getVideoWithToken 27} from '../../../../shared/extra-utils'
21} from '../../../../shared/utils' 28import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22import { waitJobs } from '../../../../shared/utils/server/jobs'
23 29
24import * as magnetUtil from 'magnet-uri' 30import * as magnetUtil from 'magnet-uri'
25import { updateRedundancy } from '../../../../shared/utils/server/redundancy' 31import { updateRedundancy } from '../../../../shared/extra-utils/server/redundancy'
26import { ActorFollow } from '../../../../shared/models/actors' 32import { ActorFollow } from '../../../../shared/models/actors'
27import { readdir } from 'fs-extra' 33import { readdir } from 'fs-extra'
28import { join } from 'path' 34import { join } from 'path'
29import { VideoRedundancyStrategy } from '../../../../shared/models/redundancy' 35import { VideoRedundancyStrategy } from '../../../../shared/models/redundancy'
30import { getStats } from '../../../../shared/utils/server/stats' 36import { getStats } from '../../../../shared/extra-utils/server/stats'
31import { ServerStats } from '../../../../shared/models/server/server-stats.model' 37import { ServerStats } from '../../../../shared/models/server/server-stats.model'
32 38
33const expect = chai.expect 39const expect = chai.expect
@@ -46,8 +52,13 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe
46 expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) 52 expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length)
47} 53}
48 54
49async function runServers (strategy: VideoRedundancyStrategy, additionalParams: any = {}) { 55async function flushAndRunServers (strategy: VideoRedundancyStrategy, additionalParams: any = {}) {
50 const config = { 56 const config = {
57 transcoding: {
58 hls: {
59 enabled: true
60 }
61 },
51 redundancy: { 62 redundancy: {
52 videos: { 63 videos: {
53 check_interval: '5 seconds', 64 check_interval: '5 seconds',
@@ -85,7 +96,7 @@ async function runServers (strategy: VideoRedundancyStrategy, additionalParams:
85 await waitJobs(servers) 96 await waitJobs(servers)
86} 97}
87 98
88async function check1WebSeed (strategy: VideoRedundancyStrategy, videoUUID?: string) { 99async function check1WebSeed (videoUUID?: string) {
89 if (!videoUUID) videoUUID = video1Server2UUID 100 if (!videoUUID) videoUUID = video1Server2UUID
90 101
91 const webseeds = [ 102 const webseeds = [
@@ -93,47 +104,17 @@ async function check1WebSeed (strategy: VideoRedundancyStrategy, videoUUID?: str
93 ] 104 ]
94 105
95 for (const server of servers) { 106 for (const server of servers) {
96 { 107 // With token to avoid issues with video follow constraints
97 // With token to avoid issues with video follow constraints 108 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
98 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
99 109
100 const video: VideoDetails = res.body 110 const video: VideoDetails = res.body
101 for (const f of video.files) { 111 for (const f of video.files) {
102 checkMagnetWebseeds(f, webseeds, server) 112 checkMagnetWebseeds(f, webseeds, server)
103 }
104 } 113 }
105 } 114 }
106} 115}
107 116
108async function checkStatsWith2Webseed (strategy: VideoRedundancyStrategy) { 117async function check2Webseeds (videoUUID?: string) {
109 const res = await getStats(servers[0].url)
110 const data: ServerStats = res.body
111
112 expect(data.videosRedundancy).to.have.lengthOf(1)
113 const stat = data.videosRedundancy[0]
114
115 expect(stat.strategy).to.equal(strategy)
116 expect(stat.totalSize).to.equal(204800)
117 expect(stat.totalUsed).to.be.at.least(1).and.below(204801)
118 expect(stat.totalVideoFiles).to.equal(4)
119 expect(stat.totalVideos).to.equal(1)
120}
121
122async function checkStatsWith1Webseed (strategy: VideoRedundancyStrategy) {
123 const res = await getStats(servers[0].url)
124 const data: ServerStats = res.body
125
126 expect(data.videosRedundancy).to.have.lengthOf(1)
127
128 const stat = data.videosRedundancy[0]
129 expect(stat.strategy).to.equal(strategy)
130 expect(stat.totalSize).to.equal(204800)
131 expect(stat.totalUsed).to.equal(0)
132 expect(stat.totalVideoFiles).to.equal(0)
133 expect(stat.totalVideos).to.equal(0)
134}
135
136async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: string) {
137 if (!videoUUID) videoUUID = video1Server2UUID 118 if (!videoUUID) videoUUID = video1Server2UUID
138 119
139 const webseeds = [ 120 const webseeds = [
@@ -158,7 +139,7 @@ async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: st
158 await makeGetRequest({ 139 await makeGetRequest({
159 url: servers[1].url, 140 url: servers[1].url,
160 statusCodeExpected: 200, 141 statusCodeExpected: 200,
161 path: '/static/webseed/' + `${videoUUID}-${file.resolution.id}.mp4`, 142 path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`,
162 contentType: null 143 contentType: null
163 }) 144 })
164 } 145 }
@@ -174,6 +155,85 @@ async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: st
174 } 155 }
175} 156}
176 157
158async function check0PlaylistRedundancies (videoUUID?: string) {
159 if (!videoUUID) videoUUID = video1Server2UUID
160
161 for (const server of servers) {
162 // With token to avoid issues with video follow constraints
163 const res = await getVideoWithToken(server.url, server.accessToken, videoUUID)
164 const video: VideoDetails = res.body
165
166 expect(video.streamingPlaylists).to.be.an('array')
167 expect(video.streamingPlaylists).to.have.lengthOf(1)
168 expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(0)
169 }
170}
171
172async function check1PlaylistRedundancies (videoUUID?: string) {
173 if (!videoUUID) videoUUID = video1Server2UUID
174
175 for (const server of servers) {
176 const res = await getVideo(server.url, videoUUID)
177 const video: VideoDetails = res.body
178
179 expect(video.streamingPlaylists).to.have.lengthOf(1)
180 expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1)
181
182 const redundancy = video.streamingPlaylists[0].redundancies[0]
183
184 expect(redundancy.baseUrl).to.equal(servers[0].url + '/static/redundancy/hls/' + videoUUID)
185 }
186
187 const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls'
188 const baseUrlSegment = servers[0].url + '/static/redundancy/hls'
189
190 const res = await getVideo(servers[0].url, videoUUID)
191 const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0]
192
193 for (const resolution of [ 240, 360, 480, 720 ]) {
194 await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist)
195 }
196
197 for (const directory of [ 'test1/redundancy/hls', 'test2/streaming-playlists/hls' ]) {
198 const files = await readdir(join(root(), directory, videoUUID))
199 expect(files).to.have.length.at.least(4)
200
201 for (const resolution of [ 240, 360, 480, 720 ]) {
202 const filename = `${videoUUID}-${resolution}-fragmented.mp4`
203
204 expect(files.find(f => f === filename)).to.not.be.undefined
205 }
206 }
207}
208
209async function checkStatsWith2Webseed (strategy: VideoRedundancyStrategy) {
210 const res = await getStats(servers[0].url)
211 const data: ServerStats = res.body
212
213 expect(data.videosRedundancy).to.have.lengthOf(1)
214 const stat = data.videosRedundancy[0]
215
216 expect(stat.strategy).to.equal(strategy)
217 expect(stat.totalSize).to.equal(204800)
218 expect(stat.totalUsed).to.be.at.least(1).and.below(204801)
219 expect(stat.totalVideoFiles).to.equal(4)
220 expect(stat.totalVideos).to.equal(1)
221}
222
223async function checkStatsWith1Webseed (strategy: VideoRedundancyStrategy) {
224 const res = await getStats(servers[0].url)
225 const data: ServerStats = res.body
226
227 expect(data.videosRedundancy).to.have.lengthOf(1)
228
229 const stat = data.videosRedundancy[0]
230 expect(stat.strategy).to.equal(strategy)
231 expect(stat.totalSize).to.equal(204800)
232 expect(stat.totalUsed).to.equal(0)
233 expect(stat.totalVideoFiles).to.equal(0)
234 expect(stat.totalVideos).to.equal(0)
235}
236
177async function enableRedundancyOnServer1 () { 237async function enableRedundancyOnServer1 () {
178 await updateRedundancy(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ].host, true) 238 await updateRedundancy(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ].host, true)
179 239
@@ -204,10 +264,6 @@ async function disableRedundancyOnServer1 () {
204 expect(server2.following.hostRedundancyAllowed).to.be.false 264 expect(server2.following.hostRedundancyAllowed).to.be.false
205} 265}
206 266
207async function cleanServers () {
208 killallServers(servers)
209}
210
211describe('Test videos redundancy', function () { 267describe('Test videos redundancy', function () {
212 268
213 describe('With most-views strategy', function () { 269 describe('With most-views strategy', function () {
@@ -216,11 +272,12 @@ describe('Test videos redundancy', function () {
216 before(function () { 272 before(function () {
217 this.timeout(120000) 273 this.timeout(120000)
218 274
219 return runServers(strategy) 275 return flushAndRunServers(strategy)
220 }) 276 })
221 277
222 it('Should have 1 webseed on the first video', async function () { 278 it('Should have 1 webseed on the first video', async function () {
223 await check1WebSeed(strategy) 279 await check1WebSeed()
280 await check0PlaylistRedundancies()
224 await checkStatsWith1Webseed(strategy) 281 await checkStatsWith1Webseed(strategy)
225 }) 282 })
226 283
@@ -229,31 +286,33 @@ describe('Test videos redundancy', function () {
229 }) 286 })
230 287
231 it('Should have 2 webseeds on the first video', async function () { 288 it('Should have 2 webseeds on the first video', async function () {
232 this.timeout(40000) 289 this.timeout(80000)
233 290
234 await waitJobs(servers) 291 await waitJobs(servers)
235 await waitUntilLog(servers[0], 'Duplicated ', 4) 292 await waitUntilLog(servers[0], 'Duplicated ', 5)
236 await waitJobs(servers) 293 await waitJobs(servers)
237 294
238 await check2Webseeds(strategy) 295 await check2Webseeds()
296 await check1PlaylistRedundancies()
239 await checkStatsWith2Webseed(strategy) 297 await checkStatsWith2Webseed(strategy)
240 }) 298 })
241 299
242 it('Should undo redundancy on server 1 and remove duplicated videos', async function () { 300 it('Should undo redundancy on server 1 and remove duplicated videos', async function () {
243 this.timeout(40000) 301 this.timeout(80000)
244 302
245 await disableRedundancyOnServer1() 303 await disableRedundancyOnServer1()
246 304
247 await waitJobs(servers) 305 await waitJobs(servers)
248 await wait(5000) 306 await wait(5000)
249 307
250 await check1WebSeed(strategy) 308 await check1WebSeed()
309 await check0PlaylistRedundancies()
251 310
252 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) 311 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos', join('playlists', 'hls') ])
253 }) 312 })
254 313
255 after(function () { 314 after(async function () {
256 return cleanServers() 315 return cleanupTests(servers)
257 }) 316 })
258 }) 317 })
259 318
@@ -263,11 +322,12 @@ describe('Test videos redundancy', function () {
263 before(function () { 322 before(function () {
264 this.timeout(120000) 323 this.timeout(120000)
265 324
266 return runServers(strategy) 325 return flushAndRunServers(strategy)
267 }) 326 })
268 327
269 it('Should have 1 webseed on the first video', async function () { 328 it('Should have 1 webseed on the first video', async function () {
270 await check1WebSeed(strategy) 329 await check1WebSeed()
330 await check0PlaylistRedundancies()
271 await checkStatsWith1Webseed(strategy) 331 await checkStatsWith1Webseed(strategy)
272 }) 332 })
273 333
@@ -276,31 +336,33 @@ describe('Test videos redundancy', function () {
276 }) 336 })
277 337
278 it('Should have 2 webseeds on the first video', async function () { 338 it('Should have 2 webseeds on the first video', async function () {
279 this.timeout(40000) 339 this.timeout(80000)
280 340
281 await waitJobs(servers) 341 await waitJobs(servers)
282 await waitUntilLog(servers[0], 'Duplicated ', 4) 342 await waitUntilLog(servers[0], 'Duplicated ', 5)
283 await waitJobs(servers) 343 await waitJobs(servers)
284 344
285 await check2Webseeds(strategy) 345 await check2Webseeds()
346 await check1PlaylistRedundancies()
286 await checkStatsWith2Webseed(strategy) 347 await checkStatsWith2Webseed(strategy)
287 }) 348 })
288 349
289 it('Should unfollow on server 1 and remove duplicated videos', async function () { 350 it('Should unfollow on server 1 and remove duplicated videos', async function () {
290 this.timeout(40000) 351 this.timeout(80000)
291 352
292 await unfollow(servers[0].url, servers[0].accessToken, servers[1]) 353 await unfollow(servers[0].url, servers[0].accessToken, servers[1])
293 354
294 await waitJobs(servers) 355 await waitJobs(servers)
295 await wait(5000) 356 await wait(5000)
296 357
297 await check1WebSeed(strategy) 358 await check1WebSeed()
359 await check0PlaylistRedundancies()
298 360
299 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) 361 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ])
300 }) 362 })
301 363
302 after(function () { 364 after(async function () {
303 return cleanServers() 365 await cleanupTests(servers)
304 }) 366 })
305 }) 367 })
306 368
@@ -310,11 +372,12 @@ describe('Test videos redundancy', function () {
310 before(function () { 372 before(function () {
311 this.timeout(120000) 373 this.timeout(120000)
312 374
313 return runServers(strategy, { min_views: 3 }) 375 return flushAndRunServers(strategy, { min_views: 3 })
314 }) 376 })
315 377
316 it('Should have 1 webseed on the first video', async function () { 378 it('Should have 1 webseed on the first video', async function () {
317 await check1WebSeed(strategy) 379 await check1WebSeed()
380 await check0PlaylistRedundancies()
318 await checkStatsWith1Webseed(strategy) 381 await checkStatsWith1Webseed(strategy)
319 }) 382 })
320 383
@@ -323,18 +386,19 @@ describe('Test videos redundancy', function () {
323 }) 386 })
324 387
325 it('Should still have 1 webseed on the first video', async function () { 388 it('Should still have 1 webseed on the first video', async function () {
326 this.timeout(40000) 389 this.timeout(80000)
327 390
328 await waitJobs(servers) 391 await waitJobs(servers)
329 await wait(15000) 392 await wait(15000)
330 await waitJobs(servers) 393 await waitJobs(servers)
331 394
332 await check1WebSeed(strategy) 395 await check1WebSeed()
396 await check0PlaylistRedundancies()
333 await checkStatsWith1Webseed(strategy) 397 await checkStatsWith1Webseed(strategy)
334 }) 398 })
335 399
336 it('Should view 2 times the first video to have > min_views config', async function () { 400 it('Should view 2 times the first video to have > min_views config', async function () {
337 this.timeout(40000) 401 this.timeout(80000)
338 402
339 await viewVideo(servers[ 0 ].url, video1Server2UUID) 403 await viewVideo(servers[ 0 ].url, video1Server2UUID)
340 await viewVideo(servers[ 2 ].url, video1Server2UUID) 404 await viewVideo(servers[ 2 ].url, video1Server2UUID)
@@ -344,13 +408,14 @@ describe('Test videos redundancy', function () {
344 }) 408 })
345 409
346 it('Should have 2 webseeds on the first video', async function () { 410 it('Should have 2 webseeds on the first video', async function () {
347 this.timeout(40000) 411 this.timeout(80000)
348 412
349 await waitJobs(servers) 413 await waitJobs(servers)
350 await waitUntilLog(servers[0], 'Duplicated ', 4) 414 await waitUntilLog(servers[0], 'Duplicated ', 5)
351 await waitJobs(servers) 415 await waitJobs(servers)
352 416
353 await check2Webseeds(strategy) 417 await check2Webseeds()
418 await check1PlaylistRedundancies()
354 await checkStatsWith2Webseed(strategy) 419 await checkStatsWith2Webseed(strategy)
355 }) 420 })
356 421
@@ -366,8 +431,8 @@ describe('Test videos redundancy', function () {
366 } 431 }
367 }) 432 })
368 433
369 after(function () { 434 after(async function () {
370 return cleanServers() 435 await cleanupTests(servers)
371 }) 436 })
372 }) 437 })
373 438
@@ -399,13 +464,13 @@ describe('Test videos redundancy', function () {
399 before(async function () { 464 before(async function () {
400 this.timeout(120000) 465 this.timeout(120000)
401 466
402 await runServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) 467 await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
403 468
404 await enableRedundancyOnServer1() 469 await enableRedundancyOnServer1()
405 }) 470 })
406 471
407 it('Should still have 2 webseeds after 10 seconds', async function () { 472 it('Should still have 2 webseeds after 10 seconds', async function () {
408 this.timeout(40000) 473 this.timeout(80000)
409 474
410 await wait(10000) 475 await wait(10000)
411 476
@@ -420,7 +485,7 @@ describe('Test videos redundancy', function () {
420 }) 485 })
421 486
422 it('Should stop server 1 and expire video redundancy', async function () { 487 it('Should stop server 1 and expire video redundancy', async function () {
423 this.timeout(40000) 488 this.timeout(80000)
424 489
425 killallServers([ servers[0] ]) 490 killallServers([ servers[0] ])
426 491
@@ -429,8 +494,8 @@ describe('Test videos redundancy', function () {
429 await checkNotContains([ servers[1], servers[2] ], 'http%3A%2F%2Flocalhost%3A9001') 494 await checkNotContains([ servers[1], servers[2] ], 'http%3A%2F%2Flocalhost%3A9001')
430 }) 495 })
431 496
432 after(function () { 497 after(async function () {
433 return killallServers([ servers[1], servers[2] ]) 498 await cleanupTests(servers)
434 }) 499 })
435 }) 500 })
436 501
@@ -441,15 +506,16 @@ describe('Test videos redundancy', function () {
441 before(async function () { 506 before(async function () {
442 this.timeout(120000) 507 this.timeout(120000)
443 508
444 await runServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) 509 await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 })
445 510
446 await enableRedundancyOnServer1() 511 await enableRedundancyOnServer1()
447 512
448 await waitJobs(servers) 513 await waitJobs(servers)
449 await waitUntilLog(servers[0], 'Duplicated ', 4) 514 await waitUntilLog(servers[0], 'Duplicated ', 5)
450 await waitJobs(servers) 515 await waitJobs(servers)
451 516
452 await check2Webseeds(strategy) 517 await check2Webseeds()
518 await check1PlaylistRedundancies()
453 await checkStatsWith2Webseed(strategy) 519 await checkStatsWith2Webseed(strategy)
454 520
455 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 2 server 2' }) 521 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 2 server 2' })
@@ -467,8 +533,10 @@ describe('Test videos redundancy', function () {
467 await wait(1000) 533 await wait(1000)
468 534
469 try { 535 try {
470 await check1WebSeed(strategy, video1Server2UUID) 536 await check1WebSeed(video1Server2UUID)
471 await check2Webseeds(strategy, video2Server2UUID) 537 await check0PlaylistRedundancies(video1Server2UUID)
538 await check2Webseeds(video2Server2UUID)
539 await check1PlaylistRedundancies(video2Server2UUID)
472 540
473 checked = true 541 checked = true
474 } catch { 542 } catch {
@@ -477,8 +545,28 @@ describe('Test videos redundancy', function () {
477 } 545 }
478 }) 546 })
479 547
480 after(function () { 548 it('Should disable strategy and remove redundancies', async function () {
481 return cleanServers() 549 this.timeout(80000)
550
551 await waitJobs(servers)
552
553 killallServers([ servers[ 0 ] ])
554 await reRunServer(servers[ 0 ], {
555 redundancy: {
556 videos: {
557 check_interval: '1 second',
558 strategies: []
559 }
560 }
561 })
562
563 await waitJobs(servers)
564
565 await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ join('redundancy', 'hls') ])
566 })
567
568 after(async function () {
569 await cleanupTests(servers)
482 }) 570 })
483 }) 571 })
484}) 572})
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
index a411e973b..4d1ceb767 100644
--- a/server/tests/api/search/search-activitypub-video-channels.ts
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -3,7 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 addVideoChannel, 6 addVideoChannel, cleanupTests,
7 createUser, 7 createUser,
8 deleteVideoChannel, 8 deleteVideoChannel,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -17,10 +17,10 @@ import {
17 uploadVideo, 17 uploadVideo,
18 userLogin, 18 userLogin,
19 wait 19 wait
20} from '../../../../shared/utils' 20} from '../../../../shared/extra-utils'
21import { waitJobs } from '../../../../shared/utils/server/jobs' 21import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22import { VideoChannel } from '../../../../shared/models/videos' 22import { VideoChannel } from '../../../../shared/models/videos'
23import { searchVideoChannel } from '../../../../shared/utils/search/video-channels' 23import { searchVideoChannel } from '../../../../shared/extra-utils/search/video-channels'
24 24
25const expect = chai.expect 25const expect = chai.expect
26 26
@@ -33,14 +33,12 @@ describe('Test a ActivityPub video channels search', function () {
33 before(async function () { 33 before(async function () {
34 this.timeout(120000) 34 this.timeout(120000)
35 35
36 await flushTests()
37
38 servers = await flushAndRunMultipleServers(2) 36 servers = await flushAndRunMultipleServers(2)
39 37
40 await setAccessTokensToServers(servers) 38 await setAccessTokensToServers(servers)
41 39
42 { 40 {
43 await createUser(servers[0].url, servers[0].accessToken, 'user1_server1', 'password') 41 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'user1_server1', password: 'password' })
44 const channel = { 42 const channel = {
45 name: 'channel1_server1', 43 name: 'channel1_server1',
46 displayName: 'Channel 1 server 1' 44 displayName: 'Channel 1 server 1'
@@ -50,7 +48,7 @@ describe('Test a ActivityPub video channels search', function () {
50 48
51 { 49 {
52 const user = { username: 'user1_server2', password: 'password' } 50 const user = { username: 'user1_server2', password: 'password' }
53 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) 51 await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
54 userServer2Token = await userLogin(servers[1], user) 52 userServer2Token = await userLogin(servers[1], user)
55 53
56 const channel = { 54 const channel = {
@@ -208,11 +206,6 @@ describe('Test a ActivityPub video channels search', function () {
208 }) 206 })
209 207
210 after(async function () { 208 after(async function () {
211 killallServers(servers) 209 await cleanupTests(servers)
212
213 // Keep the logs if the test failed
214 if (this['ok']) {
215 await flushTests()
216 }
217 }) 210 })
218}) 211})
diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts
index f881917e7..e039961cb 100644
--- a/server/tests/api/search/search-activitypub-videos.ts
+++ b/server/tests/api/search/search-activitypub-videos.ts
@@ -15,9 +15,9 @@ import {
15 updateVideo, 15 updateVideo,
16 uploadVideo, 16 uploadVideo,
17 wait, 17 wait,
18 searchVideo 18 searchVideo, cleanupTests
19} from '../../../../shared/utils' 19} from '../../../../shared/extra-utils'
20import { waitJobs } from '../../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21import { Video, VideoPrivacy } from '../../../../shared/models/videos' 21import { Video, VideoPrivacy } from '../../../../shared/models/videos'
22 22
23const expect = chai.expect 23const expect = chai.expect
@@ -30,8 +30,6 @@ describe('Test a ActivityPub videos search', function () {
30 before(async function () { 30 before(async function () {
31 this.timeout(120000) 31 this.timeout(120000)
32 32
33 await flushTests()
34
35 servers = await flushAndRunMultipleServers(2) 33 servers = await flushAndRunMultipleServers(2)
36 34
37 await setAccessTokensToServers(servers) 35 await setAccessTokensToServers(servers)
@@ -152,11 +150,6 @@ describe('Test a ActivityPub videos search', function () {
152 }) 150 })
153 151
154 after(async function () { 152 after(async function () {
155 killallServers(servers) 153 await cleanupTests(servers)
156
157 // Keep the logs if the test failed
158 if (this['ok']) {
159 await flushTests()
160 }
161 }) 154 })
162}) 155})
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts
index 50da837da..1a086b33a 100644
--- a/server/tests/api/search/search-videos.ts
+++ b/server/tests/api/search/search-videos.ts
@@ -6,14 +6,15 @@ import {
6 advancedVideosSearch, 6 advancedVideosSearch,
7 flushTests, 7 flushTests,
8 killallServers, 8 killallServers,
9 runServer, 9 flushAndRunServer,
10 searchVideo, 10 searchVideo,
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 uploadVideo, 13 uploadVideo,
14 wait, 14 wait,
15 immutableAssign 15 immutableAssign,
16} from '../../../../shared/utils' 16 cleanupTests
17} from '../../../../shared/extra-utils'
17 18
18const expect = chai.expect 19const expect = chai.expect
19 20
@@ -24,9 +25,7 @@ describe('Test a videos search', function () {
24 before(async function () { 25 before(async function () {
25 this.timeout(30000) 26 this.timeout(30000)
26 27
27 await flushTests() 28 server = await flushAndRunServer(1)
28
29 server = await runServer(1)
30 29
31 await setAccessTokensToServers([ server ]) 30 await setAccessTokensToServers([ server ])
32 31
@@ -60,7 +59,10 @@ describe('Test a videos search', function () {
60 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] }) 59 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] })
61 await uploadVideo(server.url, server.accessToken, attributes6) 60 await uploadVideo(server.url, server.accessToken, attributes6)
62 61
63 const attributes7 = immutableAssign(attributes1, { name: attributes1.name + ' - 7' }) 62 const attributes7 = immutableAssign(attributes1, {
63 name: attributes1.name + ' - 7',
64 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
65 })
64 await uploadVideo(server.url, server.accessToken, attributes7) 66 await uploadVideo(server.url, server.accessToken, attributes7)
65 67
66 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) 68 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
@@ -343,12 +345,68 @@ describe('Test a videos search', function () {
343 expect(videos[0].name).to.equal('1111 2222 3333') 345 expect(videos[0].name).to.equal('1111 2222 3333')
344 }) 346 })
345 347
346 after(async function () { 348 it('Should search on originally published date', async function () {
347 killallServers([ server ]) 349 const baseQuery = {
350 search: '1111 2222 3333',
351 languageOneOf: [ 'pl', 'fr' ],
352 durationMax: 4,
353 nsfw: 'false' as 'false',
354 licenceOneOf: [ 1, 4 ]
355 }
356
357 {
358 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
359 const res = await advancedVideosSearch(server.url, query)
360
361 expect(res.body.total).to.equal(1)
362 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
363 }
364
365 {
366 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
367 const res = await advancedVideosSearch(server.url, query)
368
369 expect(res.body.total).to.equal(1)
370 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
371 }
348 372
349 // Keep the logs if the test failed 373 {
350 if (this['ok']) { 374 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
351 await flushTests() 375 const res = await advancedVideosSearch(server.url, query)
376
377 expect(res.body.total).to.equal(0)
378 }
379
380 {
381 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
382 const res = await advancedVideosSearch(server.url, query)
383
384 expect(res.body.total).to.equal(0)
385 }
386
387 {
388 const query = immutableAssign(baseQuery, {
389 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
390 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
391 })
392 const res = await advancedVideosSearch(server.url, query)
393
394 expect(res.body.total).to.equal(0)
395 }
396
397 {
398 const query = immutableAssign(baseQuery, {
399 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
400 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
401 })
402 const res = await advancedVideosSearch(server.url, query)
403
404 expect(res.body.total).to.equal(1)
405 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
352 } 406 }
353 }) 407 })
408
409 after(async function () {
410 await cleanupTests([ server ])
411 })
354}) 412})
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index bebfc7398..c0d11914b 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -5,18 +5,18 @@ import * as chai from 'chai'
5import { About } from '../../../../shared/models/server/about.model' 5import { About } from '../../../../shared/models/server/about.model'
6import { CustomConfig } from '../../../../shared/models/server/custom-config.model' 6import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
7import { 7import {
8 cleanupTests,
8 deleteCustomConfig, 9 deleteCustomConfig,
10 flushAndRunServer,
9 getAbout, 11 getAbout,
10 killallServers,
11 reRunServer,
12 flushTests,
13 getConfig, 12 getConfig,
14 getCustomConfig, 13 getCustomConfig,
14 killallServers,
15 registerUser, 15 registerUser,
16 runServer, 16 reRunServer,
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 updateCustomConfig 18 updateCustomConfig
19} from '../../../../shared/utils' 19} from '../../../../shared/extra-utils'
20import { ServerConfig } from '../../../../shared/models' 20import { ServerConfig } from '../../../../shared/models'
21 21
22const expect = chai.expect 22const expect = chai.expect
@@ -30,6 +30,7 @@ function checkInitialConfig (data: CustomConfig) {
30 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') 30 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
31 expect(data.instance.terms).to.equal('No terms for now.') 31 expect(data.instance.terms).to.equal('No terms for now.')
32 expect(data.instance.defaultClientRoute).to.equal('/videos/trending') 32 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
33 expect(data.instance.isNSFW).to.be.false
33 expect(data.instance.defaultNSFWPolicy).to.equal('display') 34 expect(data.instance.defaultNSFWPolicy).to.equal('display')
34 expect(data.instance.customizations.css).to.be.empty 35 expect(data.instance.customizations.css).to.be.empty
35 expect(data.instance.customizations.javascript).to.be.empty 36 expect(data.instance.customizations.javascript).to.be.empty
@@ -57,8 +58,14 @@ function checkInitialConfig (data: CustomConfig) {
57 expect(data.transcoding.resolutions['480p']).to.be.true 58 expect(data.transcoding.resolutions['480p']).to.be.true
58 expect(data.transcoding.resolutions['720p']).to.be.true 59 expect(data.transcoding.resolutions['720p']).to.be.true
59 expect(data.transcoding.resolutions['1080p']).to.be.true 60 expect(data.transcoding.resolutions['1080p']).to.be.true
61 expect(data.transcoding.hls.enabled).to.be.true
62
60 expect(data.import.videos.http.enabled).to.be.true 63 expect(data.import.videos.http.enabled).to.be.true
61 expect(data.import.videos.torrent.enabled).to.be.true 64 expect(data.import.videos.torrent.enabled).to.be.true
65 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
66
67 expect(data.followers.instance.enabled).to.be.true
68 expect(data.followers.instance.manualApproval).to.be.false
62} 69}
63 70
64function checkUpdatedConfig (data: CustomConfig) { 71function checkUpdatedConfig (data: CustomConfig) {
@@ -67,6 +74,7 @@ function checkUpdatedConfig (data: CustomConfig) {
67 expect(data.instance.description).to.equal('my super description') 74 expect(data.instance.description).to.equal('my super description')
68 expect(data.instance.terms).to.equal('my super terms') 75 expect(data.instance.terms).to.equal('my super terms')
69 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') 76 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
77 expect(data.instance.isNSFW).to.be.true
70 expect(data.instance.defaultNSFWPolicy).to.equal('blur') 78 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
71 expect(data.instance.customizations.javascript).to.equal('alert("coucou")') 79 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
72 expect(data.instance.customizations.css).to.equal('body { background-color: red; }') 80 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
@@ -79,7 +87,7 @@ function checkUpdatedConfig (data: CustomConfig) {
79 87
80 expect(data.signup.enabled).to.be.false 88 expect(data.signup.enabled).to.be.false
81 expect(data.signup.limit).to.equal(5) 89 expect(data.signup.limit).to.equal(5)
82 expect(data.signup.requiresEmailVerification).to.be.true 90 expect(data.signup.requiresEmailVerification).to.be.false
83 91
84 expect(data.admin.email).to.equal('superadmin1@example.com') 92 expect(data.admin.email).to.equal('superadmin1@example.com')
85 expect(data.contactForm.enabled).to.be.false 93 expect(data.contactForm.enabled).to.be.false
@@ -95,9 +103,14 @@ function checkUpdatedConfig (data: CustomConfig) {
95 expect(data.transcoding.resolutions['480p']).to.be.true 103 expect(data.transcoding.resolutions['480p']).to.be.true
96 expect(data.transcoding.resolutions['720p']).to.be.false 104 expect(data.transcoding.resolutions['720p']).to.be.false
97 expect(data.transcoding.resolutions['1080p']).to.be.false 105 expect(data.transcoding.resolutions['1080p']).to.be.false
106 expect(data.transcoding.hls.enabled).to.be.false
98 107
99 expect(data.import.videos.http.enabled).to.be.false 108 expect(data.import.videos.http.enabled).to.be.false
100 expect(data.import.videos.torrent.enabled).to.be.false 109 expect(data.import.videos.torrent.enabled).to.be.false
110 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
111
112 expect(data.followers.instance.enabled).to.be.false
113 expect(data.followers.instance.manualApproval).to.be.true
101} 114}
102 115
103describe('Test config', function () { 116describe('Test config', function () {
@@ -105,9 +118,7 @@ describe('Test config', function () {
105 118
106 before(async function () { 119 before(async function () {
107 this.timeout(30000) 120 this.timeout(30000)
108 121 server = await flushAndRunServer(1)
109 await flushTests()
110 server = await runServer(1)
111 await setAccessTokensToServers([ server ]) 122 await setAccessTokensToServers([ server ])
112 }) 123 })
113 124
@@ -160,6 +171,7 @@ describe('Test config', function () {
160 description: 'my super description', 171 description: 'my super description',
161 terms: 'my super terms', 172 terms: 'my super terms',
162 defaultClientRoute: '/videos/recently-added', 173 defaultClientRoute: '/videos/recently-added',
174 isNSFW: true,
163 defaultNSFWPolicy: 'blur' as 'blur', 175 defaultNSFWPolicy: 'blur' as 'blur',
164 customizations: { 176 customizations: {
165 javascript: 'alert("coucou")', 177 javascript: 'alert("coucou")',
@@ -183,7 +195,7 @@ describe('Test config', function () {
183 signup: { 195 signup: {
184 enabled: false, 196 enabled: false,
185 limit: 5, 197 limit: 5,
186 requiresEmailVerification: true 198 requiresEmailVerification: false
187 }, 199 },
188 admin: { 200 admin: {
189 email: 'superadmin1@example.com' 201 email: 'superadmin1@example.com'
@@ -205,6 +217,9 @@ describe('Test config', function () {
205 '480p': true, 217 '480p': true,
206 '720p': false, 218 '720p': false,
207 '1080p': false 219 '1080p': false
220 },
221 hls: {
222 enabled: false
208 } 223 }
209 }, 224 },
210 import: { 225 import: {
@@ -216,6 +231,19 @@ describe('Test config', function () {
216 enabled: false 231 enabled: false
217 } 232 }
218 } 233 }
234 },
235 autoBlacklist: {
236 videos: {
237 ofUsers: {
238 enabled: true
239 }
240 }
241 },
242 followers: {
243 instance: {
244 enabled: false,
245 manualApproval: true
246 }
219 } 247 }
220 } 248 }
221 await updateCustomConfig(server.url, server.accessToken, newCustomConfig) 249 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
@@ -273,6 +301,6 @@ describe('Test config', function () {
273 }) 301 })
274 302
275 after(async function () { 303 after(async function () {
276 killallServers([ server ]) 304 await cleanupTests([ server ])
277 }) 305 })
278}) 306})
diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts
index 06a2f89b0..ba51198b3 100644
--- a/server/tests/api/server/contact-form.ts
+++ b/server/tests/api/server/contact-form.ts
@@ -2,10 +2,18 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/utils' 5import {
6import { MockSmtpServer } from '../../../../shared/utils/miscs/email' 6 flushTests,
7import { waitJobs } from '../../../../shared/utils/server/jobs' 7 killallServers,
8import { sendContactForm } from '../../../../shared/utils/server/contact-form' 8 flushAndRunServer,
9 ServerInfo,
10 setAccessTokensToServers,
11 wait,
12 cleanupTests
13} from '../../../../shared/extra-utils'
14import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
15import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
16import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form'
9 17
10const expect = chai.expect 18const expect = chai.expect
11 19
@@ -18,14 +26,12 @@ describe('Test contact form', function () {
18 26
19 await MockSmtpServer.Instance.collectEmails(emails) 27 await MockSmtpServer.Instance.collectEmails(emails)
20 28
21 await flushTests()
22
23 const overrideConfig = { 29 const overrideConfig = {
24 smtp: { 30 smtp: {
25 hostname: 'localhost' 31 hostname: 'localhost'
26 } 32 }
27 } 33 }
28 server = await runServer(1, overrideConfig) 34 server = await flushAndRunServer(1, overrideConfig)
29 await setAccessTokensToServers([ server ]) 35 await setAccessTokensToServers([ server ])
30 }) 36 })
31 37
@@ -82,6 +88,7 @@ describe('Test contact form', function () {
82 88
83 after(async function () { 89 after(async function () {
84 MockSmtpServer.Instance.kill() 90 MockSmtpServer.Instance.kill()
85 killallServers([ server ]) 91
92 await cleanupTests([ server ])
86 }) 93 })
87}) 94})
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index f8f16f54f..bacdf1b1b 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -10,7 +10,7 @@ import {
10 createUser, removeVideoFromBlacklist, 10 createUser, removeVideoFromBlacklist,
11 reportVideoAbuse, 11 reportVideoAbuse,
12 resetPassword, 12 resetPassword,
13 runServer, 13 flushAndRunServer,
14 unblockUser, 14 unblockUser,
15 uploadVideo, 15 uploadVideo,
16 userLogin, 16 userLogin,
@@ -18,10 +18,10 @@ import {
18 flushTests, 18 flushTests,
19 killallServers, 19 killallServers,
20 ServerInfo, 20 ServerInfo,
21 setAccessTokensToServers 21 setAccessTokensToServers, cleanupTests
22} from '../../../../shared/utils' 22} from '../../../../shared/extra-utils'
23import { MockSmtpServer } from '../../../../shared/utils/miscs/email' 23import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
24import { waitJobs } from '../../../../shared/utils/server/jobs' 24import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
25 25
26const expect = chai.expect 26const expect = chai.expect
27 27
@@ -43,18 +43,16 @@ describe('Test emails', function () {
43 43
44 await MockSmtpServer.Instance.collectEmails(emails) 44 await MockSmtpServer.Instance.collectEmails(emails)
45 45
46 await flushTests()
47
48 const overrideConfig = { 46 const overrideConfig = {
49 smtp: { 47 smtp: {
50 hostname: 'localhost' 48 hostname: 'localhost'
51 } 49 }
52 } 50 }
53 server = await runServer(1, overrideConfig) 51 server = await flushAndRunServer(1, overrideConfig)
54 await setAccessTokensToServers([ server ]) 52 await setAccessTokensToServers([ server ])
55 53
56 { 54 {
57 const res = await createUser(server.url, server.accessToken, user.username, user.password) 55 const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
58 userId = res.body.user.id 56 userId = res.body.user.id
59 57
60 userAccessToken = await userLogin(server, user) 58 userAccessToken = await userLogin(server, user)
@@ -142,7 +140,8 @@ describe('Test emails', function () {
142 }) 140 })
143 }) 141 })
144 142
145 describe('When blocking/unblocking user', async function () { 143 describe('When blocking/unblocking user', function () {
144
146 it('Should send the notification email when blocking a user', async function () { 145 it('Should send the notification email when blocking a user', async function () {
147 this.timeout(10000) 146 this.timeout(10000)
148 147
@@ -259,6 +258,7 @@ describe('Test emails', function () {
259 258
260 after(async function () { 259 after(async function () {
261 MockSmtpServer.Instance.kill() 260 MockSmtpServer.Instance.kill()
262 killallServers([ server ]) 261
262 await cleanupTests([ server ])
263 }) 263 })
264}) 264})
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts
index 8bb073c41..4285a9e7a 100644
--- a/server/tests/api/server/follow-constraints.ts
+++ b/server/tests/api/server/follow-constraints.ts
@@ -12,11 +12,11 @@ import {
12 killallServers, 12 killallServers,
13 ServerInfo, 13 ServerInfo,
14 setAccessTokensToServers, 14 setAccessTokensToServers,
15 uploadVideo 15 uploadVideo, cleanupTests
16} from '../../../../shared/utils' 16} from '../../../../shared/extra-utils'
17import { unfollow } from '../../../../shared/utils/server/follows' 17import { unfollow } from '../../../../shared/extra-utils/server/follows'
18import { userLogin } from '../../../../shared/utils/users/login' 18import { userLogin } from '../../../../shared/extra-utils/users/login'
19import { createUser } from '../../../../shared/utils/users/users' 19import { createUser } from '../../../../shared/extra-utils/users/users'
20 20
21const expect = chai.expect 21const expect = chai.expect
22 22
@@ -47,7 +47,7 @@ describe('Test follow constraints', function () {
47 username: 'user1', 47 username: 'user1',
48 password: 'super_password' 48 password: 'super_password'
49 } 49 }
50 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) 50 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
51 userAccessToken = await userLogin(servers[0], user) 51 userAccessToken = await userLogin(servers[0], user)
52 52
53 await doubleFollow(servers[0], servers[1]) 53 await doubleFollow(servers[0], servers[1])
@@ -220,6 +220,6 @@ describe('Test follow constraints', function () {
220 }) 220 })
221 221
222 after(async function () { 222 after(async function () {
223 killallServers(servers) 223 await cleanupTests(servers)
224 }) 224 })
225}) 225})
diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts
new file mode 100644
index 000000000..2a3a4d5c8
--- /dev/null
+++ b/server/tests/api/server/follows-moderation.ts
@@ -0,0 +1,195 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 acceptFollower, cleanupTests,
7 flushAndRunMultipleServers,
8 killallServers,
9 ServerInfo,
10 setAccessTokensToServers,
11 updateCustomSubConfig
12} from '../../../../shared/extra-utils/index'
13import {
14 follow,
15 getFollowersListPaginationAndSort,
16 getFollowingListPaginationAndSort,
17 removeFollower,
18 rejectFollower
19} from '../../../../shared/extra-utils/server/follows'
20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21import { ActorFollow } from '../../../../shared/models/actors'
22
23const expect = chai.expect
24
25async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') {
26 {
27 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
28 expect(res.body.total).to.equal(1)
29
30 const follow = res.body.data[0] as ActorFollow
31 expect(follow.state).to.equal(state)
32 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
33 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
34 }
35
36 {
37 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
38 expect(res.body.total).to.equal(1)
39
40 const follow = res.body.data[0] as ActorFollow
41 expect(follow.state).to.equal(state)
42 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
43 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
44 }
45}
46
47async function checkNoFollowers (servers: ServerInfo[]) {
48 {
49 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt')
50 expect(res.body.total).to.equal(0)
51 }
52
53 {
54 const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, 'createdAt')
55 expect(res.body.total).to.equal(0)
56 }
57}
58
59describe('Test follows moderation', function () {
60 let servers: ServerInfo[] = []
61
62 before(async function () {
63 this.timeout(30000)
64
65 servers = await flushAndRunMultipleServers(3)
66
67 // Get the access tokens
68 await setAccessTokensToServers(servers)
69 })
70
71 it('Should have server 1 following server 2', async function () {
72 this.timeout(30000)
73
74 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
75
76 await waitJobs(servers)
77 })
78
79 it('Should have correct follows', async function () {
80 await checkServer1And2HasFollowers(servers)
81 })
82
83 it('Should remove follower on server 2', async function () {
84 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
85
86 await waitJobs(servers)
87 })
88
89 it('Should not not have follows anymore', async function () {
90 await checkNoFollowers(servers)
91 })
92
93 it('Should disable followers on server 2', async function () {
94 const subConfig = {
95 followers: {
96 instance: {
97 enabled: false,
98 manualApproval: false
99 }
100 }
101 }
102
103 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
104
105 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
106 await waitJobs(servers)
107
108 await checkNoFollowers(servers)
109 })
110
111 it('Should re enable followers on server 2', async function () {
112 const subConfig = {
113 followers: {
114 instance: {
115 enabled: true,
116 manualApproval: false
117 }
118 }
119 }
120
121 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
122
123 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
124 await waitJobs(servers)
125
126 await checkServer1And2HasFollowers(servers)
127 })
128
129 it('Should manually approve followers', async function () {
130 this.timeout(20000)
131
132 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
133 await waitJobs(servers)
134
135 const subConfig = {
136 followers: {
137 instance: {
138 enabled: true,
139 manualApproval: true
140 }
141 }
142 }
143
144 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
145 await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig)
146
147 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
148 await waitJobs(servers)
149
150 await checkServer1And2HasFollowers(servers, 'pending')
151 })
152
153 it('Should accept a follower', async function () {
154 await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:9001')
155 await waitJobs(servers)
156
157 await checkServer1And2HasFollowers(servers)
158 })
159
160 it('Should reject another follower', async function () {
161 this.timeout(20000)
162
163 await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
164 await waitJobs(servers)
165
166 {
167 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
168 expect(res.body.total).to.equal(2)
169 }
170
171 {
172 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
173 expect(res.body.total).to.equal(1)
174 }
175
176 {
177 const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 5, 'createdAt')
178 expect(res.body.total).to.equal(1)
179 }
180
181 await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:9001')
182 await waitJobs(servers)
183
184 await checkServer1And2HasFollowers(servers)
185
186 {
187 const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt')
188 expect(res.body.total).to.equal(0)
189 }
190 })
191
192 after(async function () {
193 await cleanupTests(servers)
194 })
195})
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index b0fc5d293..397093cdb 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -4,7 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { Video, VideoPrivacy } from '../../../../shared/models/videos' 5import { Video, VideoPrivacy } from '../../../../shared/models/videos'
6import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 6import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
7import { completeVideoCheck } from '../../../../shared/utils' 7import { cleanupTests, completeVideoCheck } from '../../../../shared/extra-utils'
8import { 8import {
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getVideosList, 10 getVideosList,
@@ -12,26 +12,26 @@ import {
12 ServerInfo, 12 ServerInfo,
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 uploadVideo 14 uploadVideo
15} from '../../../../shared/utils/index' 15} from '../../../../shared/extra-utils/index'
16import { dateIsValid } from '../../../../shared/utils/miscs/miscs' 16import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
17import { 17import {
18 follow, 18 follow,
19 getFollowersListPaginationAndSort, 19 getFollowersListPaginationAndSort,
20 getFollowingListPaginationAndSort, 20 getFollowingListPaginationAndSort,
21 unfollow 21 unfollow
22} from '../../../../shared/utils/server/follows' 22} from '../../../../shared/extra-utils/server/follows'
23import { expectAccountFollows } from '../../../../shared/utils/users/accounts' 23import { expectAccountFollows } from '../../../../shared/extra-utils/users/accounts'
24import { userLogin } from '../../../../shared/utils/users/login' 24import { userLogin } from '../../../../shared/extra-utils/users/login'
25import { createUser } from '../../../../shared/utils/users/users' 25import { createUser } from '../../../../shared/extra-utils/users/users'
26import { 26import {
27 addVideoCommentReply, 27 addVideoCommentReply,
28 addVideoCommentThread, 28 addVideoCommentThread,
29 getVideoCommentThreads, 29 getVideoCommentThreads,
30 getVideoThreadComments 30 getVideoThreadComments
31} from '../../../../shared/utils/videos/video-comments' 31} from '../../../../shared/extra-utils/videos/video-comments'
32import { rateVideo } from '../../../../shared/utils/videos/videos' 32import { rateVideo } from '../../../../shared/extra-utils/videos/videos'
33import { waitJobs } from '../../../../shared/utils/server/jobs' 33import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
34import { createVideoCaption, listVideoCaptions, testCaptionFile } from '../../../../shared/utils/videos/video-captions' 34import { createVideoCaption, listVideoCaptions, testCaptionFile } from '../../../../shared/extra-utils/videos/video-captions'
35import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' 35import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
36 36
37const expect = chai.expect 37const expect = chai.expect
@@ -241,7 +241,7 @@ describe('Test follows', function () {
241 expect(res.body.data[0].name).to.equal('server3') 241 expect(res.body.data[0].name).to.equal('server3')
242 }) 242 })
243 243
244 describe('Should propagate data on a new following', async function () { 244 describe('Should propagate data on a new following', function () {
245 let video4: Video 245 let video4: Video
246 246
247 before(async function () { 247 before(async function () {
@@ -263,7 +263,7 @@ describe('Test follows', function () {
263 263
264 { 264 {
265 const user = { username: 'captain', password: 'password' } 265 const user = { username: 'captain', password: 'password' }
266 await createUser(servers[ 2 ].url, servers[ 2 ].accessToken, user.username, user.password) 266 await createUser({ url: servers[ 2 ].url, accessToken: servers[ 2 ].accessToken, username: user.username, password: user.password })
267 const userAccessToken = await userLogin(servers[ 2 ], user) 267 const userAccessToken = await userLogin(servers[ 2 ], user)
268 268
269 const resVideos = await getVideosList(servers[ 2 ].url) 269 const resVideos = await getVideosList(servers[ 2 ].url)
@@ -348,6 +348,7 @@ describe('Test follows', function () {
348 }, 348 },
349 isLocal, 349 isLocal,
350 commentsEnabled: true, 350 commentsEnabled: true,
351 downloadEnabled: true,
351 duration: 5, 352 duration: 5,
352 tags: [ 'tag1', 'tag2', 'tag3' ], 353 tags: [ 'tag1', 'tag2', 'tag3' ],
353 privacy: VideoPrivacy.PUBLIC, 354 privacy: VideoPrivacy.PUBLIC,
@@ -435,6 +436,6 @@ describe('Test follows', function () {
435 }) 436 })
436 437
437 after(async function () { 438 after(async function () {
438 killallServers(servers) 439 await cleanupTests(servers)
439 }) 440 })
440}) 441})
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts
index cd7baadad..19010dbc1 100644
--- a/server/tests/api/server/handle-down.ts
+++ b/server/tests/api/server/handle-down.ts
@@ -7,6 +7,7 @@ import { VideoPrivacy } from '../../../../shared/models/videos'
7import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 7import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
8 8
9import { 9import {
10 cleanupTests,
10 completeVideoCheck, 11 completeVideoCheck,
11 flushAndRunMultipleServers, 12 flushAndRunMultipleServers,
12 getVideo, 13 getVideo,
@@ -20,15 +21,15 @@ import {
20 updateVideo, 21 updateVideo,
21 uploadVideo, 22 uploadVideo,
22 wait 23 wait
23} from '../../../../shared/utils' 24} from '../../../../shared/extra-utils'
24import { follow, getFollowersListPaginationAndSort } from '../../../../shared/utils/server/follows' 25import { follow, getFollowersListPaginationAndSort } from '../../../../shared/extra-utils/server/follows'
25import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/utils/server/jobs' 26import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
26import { 27import {
27 addVideoCommentReply, 28 addVideoCommentReply,
28 addVideoCommentThread, 29 addVideoCommentThread,
29 getVideoCommentThreads, 30 getVideoCommentThreads,
30 getVideoThreadComments 31 getVideoThreadComments
31} from '../../../../shared/utils/videos/video-comments' 32} from '../../../../shared/extra-utils/videos/video-comments'
32 33
33const expect = chai.expect 34const expect = chai.expect
34 35
@@ -76,6 +77,7 @@ describe('Test handle downs', function () {
76 tags: [ 'tag1p1', 'tag2p1' ], 77 tags: [ 'tag1p1', 'tag2p1' ],
77 privacy: VideoPrivacy.PUBLIC, 78 privacy: VideoPrivacy.PUBLIC,
78 commentsEnabled: true, 79 commentsEnabled: true,
80 downloadEnabled: true,
79 channel: { 81 channel: {
80 name: 'root_channel', 82 name: 'root_channel',
81 displayName: 'Main root channel', 83 displayName: 'Main root channel',
@@ -296,6 +298,6 @@ describe('Test handle downs', function () {
296 }) 298 })
297 299
298 after(async function () { 300 after(async function () {
299 killallServers(servers) 301 await cleanupTests(servers)
300 }) 302 })
301}) 303})
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts
index 1f80cc6cf..94c15e0d0 100644
--- a/server/tests/api/server/index.ts
+++ b/server/tests/api/server/index.ts
@@ -3,8 +3,10 @@ import './contact-form'
3import './email' 3import './email'
4import './follow-constraints' 4import './follow-constraints'
5import './follows' 5import './follows'
6import './follows-moderation'
6import './handle-down' 7import './handle-down'
7import './jobs' 8import './jobs'
9import './logs'
8import './reverse-proxy' 10import './reverse-proxy'
9import './stats' 11import './stats'
10import './tracker' 12import './tracker'
diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts
index 52948b1d6..634654626 100644
--- a/server/tests/api/server/jobs.ts
+++ b/server/tests/api/server/jobs.ts
@@ -2,12 +2,12 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index' 5import { cleanupTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
6import { doubleFollow } from '../../../../shared/utils/server/follows' 6import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
7import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/utils/server/jobs' 7import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
8import { flushAndRunMultipleServers } from '../../../../shared/utils/server/servers' 8import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers'
9import { uploadVideo } from '../../../../shared/utils/videos/videos' 9import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
10import { dateIsValid } from '../../../../shared/utils/miscs/miscs' 10import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
11 11
12const expect = chai.expect 12const expect = chai.expect
13 13
@@ -57,6 +57,6 @@ describe('Test jobs', function () {
57 }) 57 })
58 58
59 after(async function () { 59 after(async function () {
60 killallServers(servers) 60 await cleanupTests(servers)
61 }) 61 })
62}) 62})
diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts
new file mode 100644
index 000000000..3644fa0d3
--- /dev/null
+++ b/server/tests/api/server/logs.ts
@@ -0,0 +1,97 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 flushTests,
7 killallServers,
8 flushAndRunServer,
9 ServerInfo,
10 setAccessTokensToServers,
11 cleanupTests
12} from '../../../../shared/extra-utils/index'
13import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
14import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
15import { getLogs } from '../../../../shared/extra-utils/logs/logs'
16
17const expect = chai.expect
18
19describe('Test logs', function () {
20 let server: ServerInfo
21
22 before(async function () {
23 this.timeout(30000)
24
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
27 })
28
29 it('Should get logs with a start date', async function () {
30 this.timeout(10000)
31
32 await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
33 await waitJobs([ server ])
34
35 const now = new Date()
36
37 await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
38 await waitJobs([ server ])
39
40 const res = await getLogs(server.url, server.accessToken, now)
41 const logsString = JSON.stringify(res.body)
42
43 expect(logsString.includes('video 1')).to.be.false
44 expect(logsString.includes('video 2')).to.be.true
45 })
46
47 it('Should get logs with an end date', async function () {
48 this.timeout(10000)
49
50 await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
51 await waitJobs([ server ])
52
53 const now1 = new Date()
54
55 await uploadVideo(server.url, server.accessToken, { name: 'video 4' })
56 await waitJobs([ server ])
57
58 const now2 = new Date()
59
60 await uploadVideo(server.url, server.accessToken, { name: 'video 5' })
61 await waitJobs([ server ])
62
63 const res = await getLogs(server.url, server.accessToken, now1, now2)
64 const logsString = JSON.stringify(res.body)
65
66 expect(logsString.includes('video 3')).to.be.false
67 expect(logsString.includes('video 4')).to.be.true
68 expect(logsString.includes('video 5')).to.be.false
69 })
70
71 it('Should get filter by level', async function () {
72 this.timeout(10000)
73
74 const now = new Date()
75
76 await uploadVideo(server.url, server.accessToken, { name: 'video 6' })
77 await waitJobs([ server ])
78
79 {
80 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
81 const logsString = JSON.stringify(res.body)
82
83 expect(logsString.includes('video 6')).to.be.true
84 }
85
86 {
87 const res = await getLogs(server.url, server.accessToken, now, undefined, 'warn')
88 const logsString = JSON.stringify(res.body)
89
90 expect(logsString.includes('video 6')).to.be.false
91 }
92 })
93
94 after(async function () {
95 await cleanupTests([ server ])
96 })
97})
diff --git a/server/tests/api/server/no-client.ts b/server/tests/api/server/no-client.ts
index 3b95ce945..86edeb289 100644
--- a/server/tests/api/server/no-client.ts
+++ b/server/tests/api/server/no-client.ts
@@ -1,11 +1,7 @@
1import 'mocha' 1import 'mocha'
2import * as request from 'supertest' 2import * as request from 'supertest'
3import { 3import { ServerInfo } from '../../../../shared/extra-utils'
4 flushTests, 4import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
5 killallServers,
6 ServerInfo
7} from '../../../../shared/utils'
8import { runServer } from '../../../../shared/utils/server/servers'
9 5
10describe('Start and stop server without web client routes', function () { 6describe('Start and stop server without web client routes', function () {
11 let server: ServerInfo 7 let server: ServerInfo
@@ -13,9 +9,7 @@ describe('Start and stop server without web client routes', function () {
13 before(async function () { 9 before(async function () {
14 this.timeout(30000) 10 this.timeout(30000)
15 11
16 await flushTests() 12 server = await flushAndRunServer(1, {}, ['--no-client'])
17
18 server = await runServer(1, {}, ['--no-client'])
19 }) 13 })
20 14
21 it('Should fail getting the client', function () { 15 it('Should fail getting the client', function () {
@@ -26,11 +20,6 @@ describe('Start and stop server without web client routes', function () {
26 }) 20 })
27 21
28 after(async function () { 22 after(async function () {
29 killallServers([ server ]) 23 await cleanupTests([ server ])
30
31 // Keep the logs if the test failed
32 if (this['ok']) {
33 await flushTests()
34 }
35 }) 24 })
36}) 25})
diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts
index d4c08c346..987538237 100644
--- a/server/tests/api/server/reverse-proxy.ts
+++ b/server/tests/api/server/reverse-proxy.ts
@@ -2,28 +2,10 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { About } from '../../../../shared/models/server/about.model' 5import { cleanupTests, getVideo, uploadVideo, userLogin, viewVideo, wait } from '../../../../shared/extra-utils'
6import { CustomConfig } from '../../../../shared/models/server/custom-config.model' 6import { flushAndRunServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
7import {
8 deleteCustomConfig,
9 getAbout,
10 getVideo,
11 killallServers,
12 login,
13 reRunServer,
14 uploadVideo,
15 userLogin,
16 viewVideo,
17 wait
18} from '../../../../shared/utils'
19const expect = chai.expect
20 7
21import { 8const expect = chai.expect
22 getConfig,
23 flushTests,
24 runServer,
25 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
26} from '../../../../shared/utils/index'
27 9
28describe('Test application behind a reverse proxy', function () { 10describe('Test application behind a reverse proxy', function () {
29 let server = null 11 let server = null
@@ -31,9 +13,7 @@ describe('Test application behind a reverse proxy', function () {
31 13
32 before(async function () { 14 before(async function () {
33 this.timeout(30000) 15 this.timeout(30000)
34 16 server = await flushAndRunServer(1)
35 await flushTests()
36 server = await runServer(1)
37 await setAccessTokensToServers([ server ]) 17 await setAccessTokensToServers([ server ])
38 18
39 const { body } = await uploadVideo(server.url, server.accessToken, {}) 19 const { body } = await uploadVideo(server.url, server.accessToken, {})
@@ -95,7 +75,7 @@ describe('Test application behind a reverse proxy', function () {
95 it('Should rate limit logins', async function () { 75 it('Should rate limit logins', async function () {
96 const user = { username: 'root', password: 'fail' } 76 const user = { username: 'root', password: 'fail' }
97 77
98 for (let i = 0; i < 14; i++) { 78 for (let i = 0; i < 19; i++) {
99 await userLogin(server, user, 400) 79 await userLogin(server, user, 400)
100 } 80 }
101 81
@@ -103,6 +83,6 @@ describe('Test application behind a reverse proxy', function () {
103 }) 83 })
104 84
105 after(async function () { 85 after(async function () {
106 killallServers([ server ]) 86 await cleanupTests([ server ])
107 }) 87 })
108}) 88})
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index aaa6c62f7..a01cd4b38 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -4,6 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { ServerStats } from '../../../../shared/models/server/server-stats.model' 5import { ServerStats } from '../../../../shared/models/server/server-stats.model'
6import { 6import {
7 cleanupTests,
7 createUser, 8 createUser,
8 doubleFollow, 9 doubleFollow,
9 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -13,11 +14,11 @@ import {
13 uploadVideo, 14 uploadVideo,
14 viewVideo, 15 viewVideo,
15 wait 16 wait
16} from '../../../../shared/utils' 17} from '../../../../shared/extra-utils'
17import { flushTests, setAccessTokensToServers } from '../../../../shared/utils/index' 18import { flushTests, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
18import { getStats } from '../../../../shared/utils/server/stats' 19import { getStats } from '../../../../shared/extra-utils/server/stats'
19import { addVideoCommentThread } from '../../../../shared/utils/videos/video-comments' 20import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
20import { waitJobs } from '../../../../shared/utils/server/jobs' 21import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21 22
22const expect = chai.expect 23const expect = chai.expect
23 24
@@ -26,8 +27,6 @@ describe('Test stats (excluding redundancy)', function () {
26 27
27 before(async function () { 28 before(async function () {
28 this.timeout(60000) 29 this.timeout(60000)
29
30 await flushTests()
31 servers = await flushAndRunMultipleServers(3) 30 servers = await flushAndRunMultipleServers(3)
32 await setAccessTokensToServers(servers) 31 await setAccessTokensToServers(servers)
33 32
@@ -37,7 +36,7 @@ describe('Test stats (excluding redundancy)', function () {
37 username: 'user1', 36 username: 'user1',
38 password: 'super_password' 37 password: 'super_password'
39 } 38 }
40 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) 39 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
41 40
42 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) 41 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
43 const videoUUID = resVideo.body.video.uuid 42 const videoUUID = resVideo.body.video.uuid
@@ -98,6 +97,6 @@ describe('Test stats (excluding redundancy)', function () {
98 }) 97 })
99 98
100 after(async function () { 99 after(async function () {
101 killallServers(servers) 100 await cleanupTests(servers)
102 }) 101 })
103}) 102})
diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts
index 25ca00029..9d7eec8ca 100644
--- a/server/tests/api/server/tracker.ts
+++ b/server/tests/api/server/tracker.ts
@@ -2,8 +2,16 @@
2 2
3import * as magnetUtil from 'magnet-uri' 3import * as magnetUtil from 'magnet-uri'
4import 'mocha' 4import 'mocha'
5import { getVideo, killallServers, runServer, ServerInfo, uploadVideo } from '../../../../shared/utils' 5import {
6import { flushTests, setAccessTokensToServers } from '../../../../shared/utils/index' 6 cleanupTests,
7 flushAndRunServer,
8 getVideo,
9 killallServers,
10 reRunServer,
11 ServerInfo,
12 uploadVideo
13} from '../../../../shared/extra-utils'
14import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
7import { VideoDetails } from '../../../../shared/models/videos' 15import { VideoDetails } from '../../../../shared/models/videos'
8import * as WebTorrent from 'webtorrent' 16import * as WebTorrent from 'webtorrent'
9 17
@@ -14,9 +22,7 @@ describe('Test tracker', function () {
14 22
15 before(async function () { 23 before(async function () {
16 this.timeout(60000) 24 this.timeout(60000)
17 25 server = await flushAndRunServer(1)
18 await flushTests()
19 server = await runServer(1)
20 await setAccessTokensToServers([ server ]) 26 await setAccessTokensToServers([ server ])
21 27
22 { 28 {
@@ -34,7 +40,7 @@ describe('Test tracker', function () {
34 } 40 }
35 }) 41 })
36 42
37 it('Should return an error when adding an incorrect infohash', done => { 43 it('Should return an error when adding an incorrect infohash', function (done) {
38 this.timeout(10000) 44 this.timeout(10000)
39 const webtorrent = new WebTorrent() 45 const webtorrent = new WebTorrent()
40 46
@@ -49,7 +55,7 @@ describe('Test tracker', function () {
49 torrent.on('done', () => done(new Error('No error on infohash'))) 55 torrent.on('done', () => done(new Error('No error on infohash')))
50 }) 56 })
51 57
52 it('Should succeed with the correct infohash', done => { 58 it('Should succeed with the correct infohash', function (done) {
53 this.timeout(10000) 59 this.timeout(10000)
54 const webtorrent = new WebTorrent() 60 const webtorrent = new WebTorrent()
55 61
@@ -64,7 +70,27 @@ describe('Test tracker', function () {
64 torrent.on('done', done) 70 torrent.on('done', done)
65 }) 71 })
66 72
67 after(async function () { 73 it('Should disable the tracker', function (done) {
74 this.timeout(20000)
75
68 killallServers([ server ]) 76 killallServers([ server ])
77 reRunServer(server, { tracker: { enabled: false } })
78 .then(() => {
79 const webtorrent = new WebTorrent()
80
81 const torrent = webtorrent.add(goodMagnet)
82
83 torrent.on('error', done)
84 torrent.on('warning', warn => {
85 const message = typeof warn === 'string' ? warn : warn.message
86 if (message.indexOf('disabled ') !== -1) return done()
87 })
88
89 torrent.on('done', () => done(new Error('Tracker is enabled')))
90 })
91 })
92
93 after(async function () {
94 await cleanupTests([ server ])
69 }) 95 })
70}) 96})
diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts
index 4bca27a94..fbc57e0ef 100644
--- a/server/tests/api/users/blocklist.ts
+++ b/server/tests/api/users/blocklist.ts
@@ -4,6 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { AccountBlock, ServerBlock, Video } from '../../../../shared/index' 5import { AccountBlock, ServerBlock, Video } from '../../../../shared/index'
6import { 6import {
7 cleanupTests,
7 createUser, 8 createUser,
8 doubleFollow, 9 doubleFollow,
9 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -12,16 +13,16 @@ import {
12 ServerInfo, 13 ServerInfo,
13 uploadVideo, 14 uploadVideo,
14 userLogin 15 userLogin
15} from '../../../../shared/utils/index' 16} from '../../../../shared/extra-utils/index'
16import { setAccessTokensToServers } from '../../../../shared/utils/users/login' 17import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
17import { getVideosListWithToken, getVideosList } from '../../../../shared/utils/videos/videos' 18import { getVideosListWithToken, getVideosList } from '../../../../shared/extra-utils/videos/videos'
18import { 19import {
19 addVideoCommentReply, 20 addVideoCommentReply,
20 addVideoCommentThread, 21 addVideoCommentThread,
21 getVideoCommentThreads, 22 getVideoCommentThreads,
22 getVideoThreadComments 23 getVideoThreadComments
23} from '../../../../shared/utils/videos/video-comments' 24} from '../../../../shared/extra-utils/videos/video-comments'
24import { waitJobs } from '../../../../shared/utils/server/jobs' 25import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
25import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 26import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
26import { 27import {
27 addAccountToAccountBlocklist, 28 addAccountToAccountBlocklist,
@@ -36,7 +37,7 @@ import {
36 removeAccountFromServerBlocklist, 37 removeAccountFromServerBlocklist,
37 removeServerFromAccountBlocklist, 38 removeServerFromAccountBlocklist,
38 removeServerFromServerBlocklist 39 removeServerFromServerBlocklist
39} from '../../../../shared/utils/users/blocklist' 40} from '../../../../shared/extra-utils/users/blocklist'
40 41
41const expect = chai.expect 42const expect = chai.expect
42 43
@@ -79,14 +80,12 @@ describe('Test blocklist', function () {
79 before(async function () { 80 before(async function () {
80 this.timeout(60000) 81 this.timeout(60000)
81 82
82 await flushTests()
83
84 servers = await flushAndRunMultipleServers(2) 83 servers = await flushAndRunMultipleServers(2)
85 await setAccessTokensToServers(servers) 84 await setAccessTokensToServers(servers)
86 85
87 { 86 {
88 const user = { username: 'user1', password: 'password' } 87 const user = { username: 'user1', password: 'password' }
89 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) 88 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
90 89
91 userToken1 = await userLogin(servers[0], user) 90 userToken1 = await userLogin(servers[0], user)
92 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) 91 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
@@ -94,14 +93,14 @@ describe('Test blocklist', function () {
94 93
95 { 94 {
96 const user = { username: 'moderator', password: 'password' } 95 const user = { username: 'moderator', password: 'password' }
97 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) 96 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
98 97
99 userModeratorToken = await userLogin(servers[0], user) 98 userModeratorToken = await userLogin(servers[0], user)
100 } 99 }
101 100
102 { 101 {
103 const user = { username: 'user2', password: 'password' } 102 const user = { username: 'user2', password: 'password' }
104 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) 103 await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
105 104
106 userToken2 = await userLogin(servers[1], user) 105 userToken2 = await userLogin(servers[1], user)
107 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) 106 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
@@ -501,11 +500,6 @@ describe('Test blocklist', function () {
501 }) 500 })
502 501
503 after(async function () { 502 after(async function () {
504 killallServers(servers) 503 await cleanupTests(servers)
505
506 // Keep the logs if the test failed
507 if (this[ 'ok' ]) {
508 await flushTests()
509 }
510 }) 504 })
511}) 505})
diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts
index 52ba6984e..fcd022429 100644
--- a/server/tests/api/users/index.ts
+++ b/server/tests/api/users/index.ts
@@ -1,5 +1,4 @@
1import './users-verification' 1import './users-verification'
2import './user-notifications'
3import './blocklist' 2import './blocklist'
4import './user-subscriptions' 3import './user-subscriptions'
5import './users' 4import './users'
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index 88a7187d6..48811e647 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -3,6 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -11,18 +12,18 @@ import {
11 unfollow, 12 unfollow,
12 updateVideo, 13 updateVideo,
13 userLogin 14 userLogin
14} from '../../../../shared/utils' 15} from '../../../../shared/extra-utils'
15import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/utils/index' 16import { killallServers, ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
16import { setAccessTokensToServers } from '../../../../shared/utils/users/login' 17import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
17import { Video, VideoChannel } from '../../../../shared/models/videos' 18import { Video, VideoChannel } from '../../../../shared/models/videos'
18import { waitJobs } from '../../../../shared/utils/server/jobs' 19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
19import { 20import {
20 addUserSubscription, 21 addUserSubscription,
21 listUserSubscriptions, 22 listUserSubscriptions,
22 listUserSubscriptionVideos, 23 listUserSubscriptionVideos,
23 removeUserSubscription, 24 removeUserSubscription,
24 getUserSubscription, areSubscriptionsExist 25 getUserSubscription, areSubscriptionsExist
25} from '../../../../shared/utils/users/user-subscriptions' 26} from '../../../../shared/extra-utils/users/user-subscriptions'
26 27
27const expect = chai.expect 28const expect = chai.expect
28 29
@@ -45,7 +46,7 @@ describe('Test users subscriptions', function () {
45 { 46 {
46 for (const server of servers) { 47 for (const server of servers) {
47 const user = { username: 'user' + server.serverNumber, password: 'password' } 48 const user = { username: 'user' + server.serverNumber, password: 'password' }
48 await createUser(server.url, server.accessToken, user.username, user.password) 49 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
49 50
50 const accessToken = await userLogin(server, user) 51 const accessToken = await userLogin(server, user)
51 users.push({ accessToken }) 52 users.push({ accessToken })
@@ -369,6 +370,6 @@ describe('Test users subscriptions', function () {
369 }) 370 })
370 371
371 after(async function () { 372 after(async function () {
372 killallServers(servers) 373 await cleanupTests(servers)
373 }) 374 })
374}) 375})
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index 006d6cdf0..9a971adb3 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -4,7 +4,8 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { Account } from '../../../../shared/models/actors' 5import { Account } from '../../../../shared/models/actors'
6import { 6import {
7 checkVideoFilesWereRemoved, 7 checkTmpIsEmpty,
8 checkVideoFilesWereRemoved, cleanupTests,
8 createUser, 9 createUser,
9 doubleFollow, 10 doubleFollow,
10 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
@@ -13,13 +14,20 @@ import {
13 removeUser, 14 removeUser,
14 updateMyUser, 15 updateMyUser,
15 userLogin 16 userLogin
16} from '../../../../shared/utils' 17} from '../../../../shared/extra-utils'
17import { getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/utils/index' 18import {
18import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/utils/users/accounts' 19 getMyUserInformation,
19import { setAccessTokensToServers } from '../../../../shared/utils/users/login' 20 killallServers,
21 ServerInfo,
22 testImage,
23 updateMyAvatar,
24 uploadVideo
25} from '../../../../shared/extra-utils/index'
26import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts'
27import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
20import { User } from '../../../../shared/models/users' 28import { User } from '../../../../shared/models/users'
21import { VideoChannel } from '../../../../shared/models/videos' 29import { VideoChannel } from '../../../../shared/models/videos'
22import { waitJobs } from '../../../../shared/utils/server/jobs' 30import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23 31
24const expect = chai.expect 32const expect = chai.expect
25 33
@@ -56,7 +64,12 @@ describe('Test users with multiple servers', function () {
56 username: 'user1', 64 username: 'user1',
57 password: 'password' 65 password: 'password'
58 } 66 }
59 const res = await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, user.username, user.password) 67 const res = await createUser({
68 url: servers[ 0 ].url,
69 accessToken: servers[ 0 ].accessToken,
70 username: user.username,
71 password: user.password
72 })
60 userId = res.body.user.id 73 userId = res.body.user.id
61 userAccessToken = await userLogin(servers[ 0 ], user) 74 userAccessToken = await userLogin(servers[ 0 ], user)
62 } 75 }
@@ -216,7 +229,13 @@ describe('Test users with multiple servers', function () {
216 } 229 }
217 }) 230 })
218 231
232 it('Should have an empty tmp directory', async function () {
233 for (const server of servers) {
234 await checkTmpIsEmpty(server)
235 }
236 })
237
219 after(async function () { 238 after(async function () {
220 killallServers(servers) 239 await cleanupTests(servers)
221 }) 240 })
222}) 241})
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index babeda2b8..514acf2e7 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -4,11 +4,11 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, 6 registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers,
7 userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait 7 userLogin, login, flushAndRunServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait, cleanupTests
8} from '../../../../shared/utils' 8} from '../../../../shared/extra-utils'
9import { setAccessTokensToServers } from '../../../../shared/utils/users/login' 9import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
10import { MockSmtpServer } from '../../../../shared/utils/miscs/email' 10import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
11import { waitJobs } from '../../../../shared/utils/server/jobs' 11import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
12 12
13const expect = chai.expect 13const expect = chai.expect
14 14
@@ -32,14 +32,12 @@ describe('Test users account verification', function () {
32 32
33 await MockSmtpServer.Instance.collectEmails(emails) 33 await MockSmtpServer.Instance.collectEmails(emails)
34 34
35 await flushTests()
36
37 const overrideConfig = { 35 const overrideConfig = {
38 smtp: { 36 smtp: {
39 hostname: 'localhost' 37 hostname: 'localhost'
40 } 38 }
41 } 39 }
42 server = await runServer(1, overrideConfig) 40 server = await flushAndRunServer(1, overrideConfig)
43 41
44 await setAccessTokensToServers([ server ]) 42 await setAccessTokensToServers([ server ])
45 }) 43 })
@@ -124,11 +122,7 @@ describe('Test users account verification', function () {
124 122
125 after(async function () { 123 after(async function () {
126 MockSmtpServer.Instance.kill() 124 MockSmtpServer.Instance.kill()
127 killallServers([ server ])
128 125
129 // Keep the logs if the test failed 126 await cleanupTests([ server ])
130 if (this[ 'ok' ]) {
131 await flushTests()
132 }
133 }) 127 })
134}) 128})
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index ad98ab1c7..c8e32f3f5 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -2,12 +2,14 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { User, UserRole } from '../../../../shared/index' 5import { User, UserRole, Video } from '../../../../shared/index'
6import { 6import {
7 blockUser, 7 blockUser,
8 cleanupTests,
8 createUser, 9 createUser,
9 deleteMe, 10 deleteMe,
10 flushTests, 11 flushAndRunServer,
12 getAccountRatings,
11 getBlacklistedVideosList, 13 getBlacklistedVideosList,
12 getMyUserInformation, 14 getMyUserInformation,
13 getMyUserVideoQuotaUsed, 15 getMyUserVideoQuotaUsed,
@@ -16,14 +18,12 @@ import {
16 getUsersList, 18 getUsersList,
17 getUsersListPaginationAndSort, 19 getUsersListPaginationAndSort,
18 getVideosList, 20 getVideosList,
19 killallServers,
20 login, 21 login,
21 makePutBodyRequest, 22 makePutBodyRequest,
22 rateVideo, 23 rateVideo,
23 registerUser, 24 registerUser,
24 removeUser, 25 removeUser,
25 removeVideo, 26 removeVideo,
26 runServer,
27 ServerInfo, 27 ServerInfo,
28 testImage, 28 testImage,
29 unblockUser, 29 unblockUser,
@@ -32,10 +32,11 @@ import {
32 updateUser, 32 updateUser,
33 uploadVideo, 33 uploadVideo,
34 userLogin 34 userLogin
35} from '../../../../shared/utils/index' 35} from '../../../../shared/extra-utils'
36import { follow } from '../../../../shared/utils/server/follows' 36import { follow } from '../../../../shared/extra-utils/server/follows'
37import { setAccessTokensToServers } from '../../../../shared/utils/users/login' 37import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
38import { getMyVideos } from '../../../../shared/utils/videos/videos' 38import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
39import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
39 40
40const expect = chai.expect 41const expect = chai.expect
41 42
@@ -52,537 +53,633 @@ describe('Test users', function () {
52 53
53 before(async function () { 54 before(async function () {
54 this.timeout(30000) 55 this.timeout(30000)
55 56 server = await flushAndRunServer(1)
56 await flushTests()
57 server = await runServer(1)
58 57
59 await setAccessTokensToServers([ server ]) 58 await setAccessTokensToServers([ server ])
60 }) 59 })
61 60
62 it('Should create a new client') 61 describe('OAuth client', function () {
62 it('Should create a new client')
63 63
64 it('Should return the first client') 64 it('Should return the first client')
65 65
66 it('Should remove the last client') 66 it('Should remove the last client')
67 67
68 it('Should not login with an invalid client id', async function () { 68 it('Should not login with an invalid client id', async function () {
69 const client = { id: 'client', secret: server.client.secret } 69 const client = { id: 'client', secret: server.client.secret }
70 const res = await login(server.url, client, server.user, 400) 70 const res = await login(server.url, client, server.user, 400)
71 71
72 expect(res.body.error).to.contain('client is invalid') 72 expect(res.body.error).to.contain('client is invalid')
73 }) 73 })
74 74
75 it('Should not login with an invalid client secret', async function () { 75 it('Should not login with an invalid client secret', async function () {
76 const client = { id: server.client.id, secret: 'coucou' } 76 const client = { id: server.client.id, secret: 'coucou' }
77 const res = await login(server.url, client, server.user, 400) 77 const res = await login(server.url, client, server.user, 400)
78 78
79 expect(res.body.error).to.contain('client is invalid') 79 expect(res.body.error).to.contain('client is invalid')
80 })
80 }) 81 })
81 82
82 it('Should not login with an invalid username', async function () { 83 describe('Login', function () {
83 const user = { username: 'captain crochet', password: server.user.password }
84 const res = await login(server.url, server.client, user, 400)
85 84
86 expect(res.body.error).to.contain('credentials are invalid') 85 it('Should not login with an invalid username', async function () {
87 }) 86 const user = { username: 'captain crochet', password: server.user.password }
88 87 const res = await login(server.url, server.client, user, 400)
89 it('Should not login with an invalid password', async function () {
90 const user = { username: server.user.username, password: 'mew_three' }
91 const res = await login(server.url, server.client, user, 400)
92 88
93 expect(res.body.error).to.contain('credentials are invalid') 89 expect(res.body.error).to.contain('credentials are invalid')
94 }) 90 })
95 91
96 it('Should not be able to upload a video', async function () { 92 it('Should not login with an invalid password', async function () {
97 accessToken = 'my_super_token' 93 const user = { username: server.user.username, password: 'mew_three' }
94 const res = await login(server.url, server.client, user, 400)
98 95
99 const videoAttributes = {} 96 expect(res.body.error).to.contain('credentials are invalid')
100 await uploadVideo(server.url, accessToken, videoAttributes, 401) 97 })
101 })
102 98
103 it('Should not be able to follow', async function () { 99 it('Should not be able to upload a video', async function () {
104 accessToken = 'my_super_token' 100 accessToken = 'my_super_token'
105 await follow(server.url, [ 'http://example.com' ], accessToken, 401)
106 })
107 101
108 it('Should not be able to unfollow') 102 const videoAttributes = {}
103 await uploadVideo(server.url, accessToken, videoAttributes, 401)
104 })
109 105
110 it('Should be able to login', async function () { 106 it('Should not be able to follow', async function () {
111 const res = await login(server.url, server.client, server.user, 200) 107 accessToken = 'my_super_token'
108 await follow(server.url, [ 'http://example.com' ], accessToken, 401)
109 })
112 110
113 accessToken = res.body.access_token 111 it('Should not be able to unfollow')
114 })
115 112
116 it('Should upload the video with the correct token', async function () { 113 it('Should be able to login', async function () {
117 const videoAttributes = {} 114 const res = await login(server.url, server.client, server.user, 200)
118 await uploadVideo(server.url, accessToken, videoAttributes)
119 const res = await getVideosList(server.url)
120 const video = res.body.data[ 0 ]
121 115
122 expect(video.account.name).to.equal('root') 116 accessToken = res.body.access_token
123 videoId = video.id 117 })
124 }) 118 })
125 119
126 it('Should upload the video again with the correct token', async function () { 120 describe('Upload', function () {
127 const videoAttributes = {}
128 await uploadVideo(server.url, accessToken, videoAttributes)
129 })
130 121
131 it('Should retrieve a video rating', async function () { 122 it('Should upload the video with the correct token', async function () {
132 await rateVideo(server.url, accessToken, videoId, 'like') 123 const videoAttributes = {}
133 const res = await getMyUserVideoRating(server.url, accessToken, videoId) 124 await uploadVideo(server.url, accessToken, videoAttributes)
134 const rating = res.body 125 const res = await getVideosList(server.url)
126 const video = res.body.data[ 0 ]
135 127
136 expect(rating.videoId).to.equal(videoId) 128 expect(video.account.name).to.equal('root')
137 expect(rating.rating).to.equal('like') 129 videoId = video.id
138 }) 130 })
139 131
140 it('Should not be able to remove the video with an incorrect token', async function () { 132 it('Should upload the video again with the correct token', async function () {
141 await removeVideo(server.url, 'bad_token', videoId, 401) 133 const videoAttributes = {}
134 await uploadVideo(server.url, accessToken, videoAttributes)
135 })
142 }) 136 })
143 137
144 it('Should not be able to remove the video with the token of another account') 138 describe('Ratings', function () {
145 139
146 it('Should be able to remove the video with the correct token', async function () { 140 it('Should retrieve a video rating', async function () {
147 await removeVideo(server.url, accessToken, videoId) 141 await rateVideo(server.url, accessToken, videoId, 'like')
148 }) 142 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
143 const rating = res.body
149 144
150 it('Should logout (revoke token)') 145 expect(rating.videoId).to.equal(videoId)
151 146 expect(rating.rating).to.equal('like')
152 it('Should not be able to get the user information') 147 })
153 148
154 it('Should not be able to upload a video') 149 it('Should retrieve ratings list', async function () {
150 await rateVideo(server.url, accessToken, videoId, 'like')
155 151
156 it('Should not be able to remove a video') 152 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200)
153 const ratings = res.body
157 154
158 it('Should not be able to rate a video', async function () { 155 expect(ratings.total).to.equal(1)
159 const path = '/api/v1/videos/' 156 expect(ratings.data[ 0 ].video.id).to.equal(videoId)
160 const data = { 157 expect(ratings.data[ 0 ].rating).to.equal('like')
161 rating: 'likes' 158 })
162 }
163 159
164 const options = { 160 it('Should retrieve ratings list by rating type', async function () {
165 url: server.url, 161 {
166 path: path + videoId, 162 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
167 token: 'wrong token', 163 const ratings = res.body
168 fields: data, 164 expect(ratings.data.length).to.equal(1)
169 statusCodeExpected: 401 165 }
170 } 166
171 await makePutBodyRequest(options) 167 {
168 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
169 const ratings = res.body
170 expect(ratings.data.length).to.equal(0)
171 }
172 })
172 }) 173 })
173 174
174 it('Should be able to login again') 175 describe('Remove video', function () {
176 it('Should not be able to remove the video with an incorrect token', async function () {
177 await removeVideo(server.url, 'bad_token', videoId, 401)
178 })
175 179
176 it('Should have an expired access token') 180 it('Should not be able to remove the video with the token of another account')
177 181
178 it('Should refresh the token') 182 it('Should be able to remove the video with the correct token', async function () {
183 await removeVideo(server.url, accessToken, videoId)
184 })
185 })
179 186
180 it('Should be able to upload a video again') 187 describe('Logout', function () {
188 it('Should logout (revoke token)')
181 189
182 it('Should be able to create a new user', async function () { 190 it('Should not be able to get the user information')
183 await createUser(server.url, accessToken, user.username, user.password, 2 * 1024 * 1024)
184 })
185 191
186 it('Should be able to login with this user', async function () { 192 it('Should not be able to upload a video')
187 accessTokenUser = await userLogin(server, user)
188 })
189 193
190 it('Should be able to get the user information', async function () { 194 it('Should not be able to remove a video')
191 const res = await getMyUserInformation(server.url, accessTokenUser)
192 const user = res.body
193
194 expect(user.username).to.equal('user_1')
195 expect(user.email).to.equal('user_1@example.com')
196 expect(user.nsfwPolicy).to.equal('display')
197 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
198 expect(user.roleLabel).to.equal('User')
199 expect(user.id).to.be.a('number')
200 expect(user.account.displayName).to.equal('user_1')
201 expect(user.account.description).to.be.null
202 })
203 195
204 it('Should be able to upload a video with this user', async function () { 196 it('Should not be able to rate a video', async function () {
205 this.timeout(5000) 197 const path = '/api/v1/videos/'
198 const data = {
199 rating: 'likes'
200 }
206 201
207 const videoAttributes = { 202 const options = {
208 name: 'super user video', 203 url: server.url,
209 fixture: 'video_short.webm' 204 path: path + videoId,
210 } 205 token: 'wrong token',
211 await uploadVideo(server.url, accessTokenUser, videoAttributes) 206 fields: data,
212 }) 207 statusCodeExpected: 401
208 }
209 await makePutBodyRequest(options)
210 })
213 211
214 it('Should have video quota updated', async function () { 212 it('Should be able to login again')
215 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
216 const data = res.body
217 213
218 expect(data.videoQuotaUsed).to.equal(218910) 214 it('Should have an expired access token')
219 215
220 const resUsers = await getUsersList(server.url, server.accessToken) 216 it('Should refresh the token')
221 217
222 const users: User[] = resUsers.body.data 218 it('Should be able to upload a video again')
223 const tmpUser = users.find(u => u.username === user.username)
224 expect(tmpUser.videoQuotaUsed).to.equal(218910)
225 }) 219 })
226 220
227 it('Should be able to list my videos', async function () { 221 describe('Creating a user', function () {
228 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
229 expect(res.body.total).to.equal(1)
230 222
231 const videos = res.body.data 223 it('Should be able to create a new user', async function () {
232 expect(videos).to.have.lengthOf(1) 224 await createUser({
225 url: server.url,
226 accessToken: accessToken,
227 username: user.username,
228 password: user.password,
229 videoQuota: 2 * 1024 * 1024,
230 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
231 })
232 })
233 233
234 expect(videos[ 0 ].name).to.equal('super user video') 234 it('Should be able to login with this user', async function () {
235 accessTokenUser = await userLogin(server, user)
236 })
237
238 it('Should be able to get user information', async function () {
239 const res1 = await getMyUserInformation(server.url, accessTokenUser)
240 const userMe: User = res1.body
241
242 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id)
243 const userGet: User = res2.body
244
245 for (const user of [ userMe, userGet ]) {
246 expect(user.username).to.equal('user_1')
247 expect(user.email).to.equal('user_1@example.com')
248 expect(user.nsfwPolicy).to.equal('display')
249 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
250 expect(user.roleLabel).to.equal('User')
251 expect(user.id).to.be.a('number')
252 expect(user.account.displayName).to.equal('user_1')
253 expect(user.account.description).to.be.null
254 }
255
256 expect(userMe.adminFlags).to.be.undefined
257 expect(userGet.adminFlags).to.equal(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)
258 })
235 }) 259 })
236 260
237 it('Should list all the users', async function () { 261 describe('My videos & quotas', function () {
238 const res = await getUsersList(server.url, server.accessToken)
239 const result = res.body
240 const total = result.total
241 const users = result.data
242 262
243 expect(total).to.equal(2) 263 it('Should be able to upload a video with this user', async function () {
244 expect(users).to.be.an('array') 264 this.timeout(5000)
245 expect(users.length).to.equal(2)
246 265
247 const user = users[ 0 ] 266 const videoAttributes = {
248 expect(user.username).to.equal('user_1') 267 name: 'super user video',
249 expect(user.email).to.equal('user_1@example.com') 268 fixture: 'video_short.webm'
250 expect(user.nsfwPolicy).to.equal('display') 269 }
270 await uploadVideo(server.url, accessTokenUser, videoAttributes)
271 })
251 272
252 const rootUser = users[ 1 ] 273 it('Should have video quota updated', async function () {
253 expect(rootUser.username).to.equal('root') 274 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
254 expect(rootUser.email).to.equal('admin1@example.com') 275 const data = res.body
255 expect(user.nsfwPolicy).to.equal('display')
256 276
257 userId = user.id 277 expect(data.videoQuotaUsed).to.equal(218910)
258 })
259 278
260 it('Should list only the first user by username asc', async function () { 279 const resUsers = await getUsersList(server.url, server.accessToken)
261 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
262 280
263 const result = res.body 281 const users: User[] = resUsers.body.data
264 const total = result.total 282 const tmpUser = users.find(u => u.username === user.username)
265 const users = result.data 283 expect(tmpUser.videoQuotaUsed).to.equal(218910)
284 })
266 285
267 expect(total).to.equal(2) 286 it('Should be able to list my videos', async function () {
268 expect(users.length).to.equal(1) 287 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
288 expect(res.body.total).to.equal(1)
289
290 const videos = res.body.data
291 expect(videos).to.have.lengthOf(1)
269 292
270 const user = users[ 0 ] 293 const video: Video = videos[ 0 ]
271 expect(user.username).to.equal('root') 294 expect(video.name).to.equal('super user video')
272 expect(user.email).to.equal('admin1@example.com') 295 expect(video.thumbnailPath).to.not.be.null
273 expect(user.roleLabel).to.equal('Administrator') 296 expect(video.previewPath).to.not.be.null
274 expect(user.nsfwPolicy).to.equal('display') 297 })
275 }) 298 })
276 299
277 it('Should list only the first user by username desc', async function () { 300 describe('Users listing', function () {
278 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
279 const result = res.body
280 const total = result.total
281 const users = result.data
282 301
283 expect(total).to.equal(2) 302 it('Should list all the users', async function () {
284 expect(users.length).to.equal(1) 303 const res = await getUsersList(server.url, server.accessToken)
304 const result = res.body
305 const total = result.total
306 const users = result.data
285 307
286 const user = users[ 0 ] 308 expect(total).to.equal(2)
287 expect(user.username).to.equal('user_1') 309 expect(users).to.be.an('array')
288 expect(user.email).to.equal('user_1@example.com') 310 expect(users.length).to.equal(2)
289 expect(user.nsfwPolicy).to.equal('display')
290 })
291 311
292 it('Should list only the second user by createdAt desc', async function () { 312 const user = users[ 0 ]
293 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') 313 expect(user.username).to.equal('user_1')
294 const result = res.body 314 expect(user.email).to.equal('user_1@example.com')
295 const total = result.total 315 expect(user.nsfwPolicy).to.equal('display')
296 const users = result.data
297 316
298 expect(total).to.equal(2) 317 const rootUser = users[ 1 ]
299 expect(users.length).to.equal(1) 318 expect(rootUser.username).to.equal('root')
319 expect(rootUser.email).to.equal('admin1@example.com')
320 expect(user.nsfwPolicy).to.equal('display')
300 321
301 const user = users[ 0 ] 322 userId = user.id
302 expect(user.username).to.equal('user_1') 323 })
303 expect(user.email).to.equal('user_1@example.com')
304 expect(user.nsfwPolicy).to.equal('display')
305 })
306 324
307 it('Should list all the users by createdAt asc', async function () { 325 it('Should list only the first user by username asc', async function () {
308 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') 326 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
309 const result = res.body
310 const total = result.total
311 const users = result.data
312 327
313 expect(total).to.equal(2) 328 const result = res.body
314 expect(users.length).to.equal(2) 329 const total = result.total
330 const users = result.data
315 331
316 expect(users[ 0 ].username).to.equal('root') 332 expect(total).to.equal(2)
317 expect(users[ 0 ].email).to.equal('admin1@example.com') 333 expect(users.length).to.equal(1)
318 expect(users[ 0 ].nsfwPolicy).to.equal('display')
319 334
320 expect(users[ 1 ].username).to.equal('user_1') 335 const user = users[ 0 ]
321 expect(users[ 1 ].email).to.equal('user_1@example.com') 336 expect(user.username).to.equal('root')
322 expect(users[ 1 ].nsfwPolicy).to.equal('display') 337 expect(user.email).to.equal('admin1@example.com')
323 }) 338 expect(user.roleLabel).to.equal('Administrator')
339 expect(user.nsfwPolicy).to.equal('display')
340 })
324 341
325 it('Should search user by username', async function () { 342 it('Should list only the first user by username desc', async function () {
326 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') 343 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
327 const users = res.body.data as User[] 344 const result = res.body
345 const total = result.total
346 const users = result.data
328 347
329 expect(res.body.total).to.equal(1) 348 expect(total).to.equal(2)
330 expect(users.length).to.equal(1) 349 expect(users.length).to.equal(1)
331 350
332 expect(users[ 0 ].username).to.equal('root') 351 const user = users[ 0 ]
333 }) 352 expect(user.username).to.equal('user_1')
353 expect(user.email).to.equal('user_1@example.com')
354 expect(user.nsfwPolicy).to.equal('display')
355 })
334 356
335 it('Should search user by email', async function () { 357 it('Should list only the second user by createdAt desc', async function () {
336 { 358 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
337 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') 359 const result = res.body
338 const users = res.body.data as User[] 360 const total = result.total
361 const users = result.data
339 362
340 expect(res.body.total).to.equal(1) 363 expect(total).to.equal(2)
341 expect(users.length).to.equal(1) 364 expect(users.length).to.equal(1)
342 365
343 expect(users[ 0 ].username).to.equal('user_1') 366 const user = users[ 0 ]
344 expect(users[ 0 ].email).to.equal('user_1@example.com') 367 expect(user.username).to.equal('user_1')
345 } 368 expect(user.email).to.equal('user_1@example.com')
369 expect(user.nsfwPolicy).to.equal('display')
370 })
346 371
347 { 372 it('Should list all the users by createdAt asc', async function () {
348 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') 373 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
349 const users = res.body.data as User[] 374 const result = res.body
375 const total = result.total
376 const users = result.data
350 377
351 expect(res.body.total).to.equal(2) 378 expect(total).to.equal(2)
352 expect(users.length).to.equal(2) 379 expect(users.length).to.equal(2)
353 380
354 expect(users[ 0 ].username).to.equal('root') 381 expect(users[ 0 ].username).to.equal('root')
355 expect(users[ 1 ].username).to.equal('user_1') 382 expect(users[ 0 ].email).to.equal('admin1@example.com')
356 } 383 expect(users[ 0 ].nsfwPolicy).to.equal('display')
357 })
358 384
359 it('Should update my password', async function () { 385 expect(users[ 1 ].username).to.equal('user_1')
360 await updateMyUser({ 386 expect(users[ 1 ].email).to.equal('user_1@example.com')
361 url: server.url, 387 expect(users[ 1 ].nsfwPolicy).to.equal('display')
362 accessToken: accessTokenUser,
363 currentPassword: 'super password',
364 newPassword: 'new password'
365 }) 388 })
366 user.password = 'new password'
367 389
368 await userLogin(server, user, 200) 390 it('Should search user by username', async function () {
369 }) 391 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
392 const users = res.body.data as User[]
393
394 expect(res.body.total).to.equal(1)
395 expect(users.length).to.equal(1)
370 396
371 it('Should be able to change the NSFW display attribute', async function () { 397 expect(users[ 0 ].username).to.equal('root')
372 await updateMyUser({
373 url: server.url,
374 accessToken: accessTokenUser,
375 nsfwPolicy: 'do_not_list'
376 }) 398 })
377 399
378 const res = await getMyUserInformation(server.url, accessTokenUser) 400 it('Should search user by email', async function () {
379 const user = res.body 401 {
402 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
403 const users = res.body.data as User[]
380 404
381 expect(user.username).to.equal('user_1') 405 expect(res.body.total).to.equal(1)
382 expect(user.email).to.equal('user_1@example.com') 406 expect(users.length).to.equal(1)
383 expect(user.nsfwPolicy).to.equal('do_not_list')
384 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
385 expect(user.id).to.be.a('number')
386 expect(user.account.displayName).to.equal('user_1')
387 expect(user.account.description).to.be.null
388 })
389 407
390 it('Should be able to change the autoPlayVideo attribute', async function () { 408 expect(users[ 0 ].username).to.equal('user_1')
391 await updateMyUser({ 409 expect(users[ 0 ].email).to.equal('user_1@example.com')
392 url: server.url, 410 }
393 accessToken: accessTokenUser,
394 autoPlayVideo: false
395 })
396 411
397 const res = await getMyUserInformation(server.url, accessTokenUser) 412 {
398 const user = res.body 413 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
414 const users = res.body.data as User[]
399 415
400 expect(user.autoPlayVideo).to.be.false 416 expect(res.body.total).to.equal(2)
417 expect(users.length).to.equal(2)
418
419 expect(users[ 0 ].username).to.equal('root')
420 expect(users[ 1 ].username).to.equal('user_1')
421 }
422 })
401 }) 423 })
402 424
403 it('Should be able to change the email display attribute', async function () { 425 describe('Update my account', function () {
404 await updateMyUser({ 426 it('Should update my password', async function () {
405 url: server.url, 427 await updateMyUser({
406 accessToken: accessTokenUser, 428 url: server.url,
407 email: 'updated@example.com' 429 accessToken: accessTokenUser,
430 currentPassword: 'super password',
431 newPassword: 'new password'
432 })
433 user.password = 'new password'
434
435 await userLogin(server, user, 200)
408 }) 436 })
409 437
410 const res = await getMyUserInformation(server.url, accessTokenUser) 438 it('Should be able to change the NSFW display attribute', async function () {
411 const user = res.body 439 await updateMyUser({
440 url: server.url,
441 accessToken: accessTokenUser,
442 nsfwPolicy: 'do_not_list'
443 })
444
445 const res = await getMyUserInformation(server.url, accessTokenUser)
446 const user = res.body
447
448 expect(user.username).to.equal('user_1')
449 expect(user.email).to.equal('user_1@example.com')
450 expect(user.nsfwPolicy).to.equal('do_not_list')
451 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
452 expect(user.id).to.be.a('number')
453 expect(user.account.displayName).to.equal('user_1')
454 expect(user.account.description).to.be.null
455 })
412 456
413 expect(user.username).to.equal('user_1') 457 it('Should be able to change the autoPlayVideo attribute', async function () {
414 expect(user.email).to.equal('updated@example.com') 458 await updateMyUser({
415 expect(user.nsfwPolicy).to.equal('do_not_list') 459 url: server.url,
416 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 460 accessToken: accessTokenUser,
417 expect(user.id).to.be.a('number') 461 autoPlayVideo: false
418 expect(user.account.displayName).to.equal('user_1') 462 })
419 expect(user.account.description).to.be.null 463
420 }) 464 const res = await getMyUserInformation(server.url, accessTokenUser)
465 const user = res.body
421 466
422 it('Should be able to update my avatar', async function () { 467 expect(user.autoPlayVideo).to.be.false
423 const fixture = 'avatar.png' 468 })
424 469
425 await updateMyAvatar({ 470 it('Should be able to change the email display attribute', async function () {
426 url: server.url, 471 await updateMyUser({
427 accessToken: accessTokenUser, 472 url: server.url,
428 fixture 473 accessToken: accessTokenUser,
474 email: 'updated@example.com'
475 })
476
477 const res = await getMyUserInformation(server.url, accessTokenUser)
478 const user = res.body
479
480 expect(user.username).to.equal('user_1')
481 expect(user.email).to.equal('updated@example.com')
482 expect(user.nsfwPolicy).to.equal('do_not_list')
483 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
484 expect(user.id).to.be.a('number')
485 expect(user.account.displayName).to.equal('user_1')
486 expect(user.account.description).to.be.null
429 }) 487 })
430 488
431 const res = await getMyUserInformation(server.url, accessTokenUser) 489 it('Should be able to update my avatar', async function () {
432 const user = res.body 490 const fixture = 'avatar.png'
433 491
434 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') 492 await updateMyAvatar({
435 }) 493 url: server.url,
494 accessToken: accessTokenUser,
495 fixture
496 })
497
498 const res = await getMyUserInformation(server.url, accessTokenUser)
499 const user = res.body
436 500
437 it('Should be able to update my display name', async function () { 501 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')
438 await updateMyUser({
439 url: server.url,
440 accessToken: accessTokenUser,
441 displayName: 'new display name'
442 }) 502 })
443 503
444 const res = await getMyUserInformation(server.url, accessTokenUser) 504 it('Should be able to update my display name', async function () {
445 const user = res.body 505 await updateMyUser({
506 url: server.url,
507 accessToken: accessTokenUser,
508 displayName: 'new display name'
509 })
510
511 const res = await getMyUserInformation(server.url, accessTokenUser)
512 const user = res.body
513
514 expect(user.username).to.equal('user_1')
515 expect(user.email).to.equal('updated@example.com')
516 expect(user.nsfwPolicy).to.equal('do_not_list')
517 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
518 expect(user.id).to.be.a('number')
519 expect(user.account.displayName).to.equal('new display name')
520 expect(user.account.description).to.be.null
521 })
446 522
447 expect(user.username).to.equal('user_1') 523 it('Should be able to update my description', async function () {
448 expect(user.email).to.equal('updated@example.com') 524 await updateMyUser({
449 expect(user.nsfwPolicy).to.equal('do_not_list') 525 url: server.url,
450 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 526 accessToken: accessTokenUser,
451 expect(user.id).to.be.a('number') 527 description: 'my super description updated'
452 expect(user.account.displayName).to.equal('new display name') 528 })
453 expect(user.account.description).to.be.null 529
530 const res = await getMyUserInformation(server.url, accessTokenUser)
531 const user = res.body
532
533 expect(user.username).to.equal('user_1')
534 expect(user.email).to.equal('updated@example.com')
535 expect(user.nsfwPolicy).to.equal('do_not_list')
536 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
537 expect(user.id).to.be.a('number')
538 expect(user.account.displayName).to.equal('new display name')
539 expect(user.account.description).to.equal('my super description updated')
540 })
454 }) 541 })
455 542
456 it('Should be able to update my description', async function () { 543 describe('Updating another user', function () {
457 await updateMyUser({ 544
458 url: server.url, 545 it('Should be able to update another user', async function () {
459 accessToken: accessTokenUser, 546 await updateUser({
460 description: 'my super description updated' 547 url: server.url,
548 userId,
549 accessToken,
550 email: 'updated2@example.com',
551 emailVerified: true,
552 videoQuota: 42,
553 role: UserRole.MODERATOR,
554 adminFlags: UserAdminFlag.NONE
555 })
556
557 const res = await getUserInformation(server.url, accessToken, userId)
558 const user = res.body
559
560 expect(user.username).to.equal('user_1')
561 expect(user.email).to.equal('updated2@example.com')
562 expect(user.emailVerified).to.be.true
563 expect(user.nsfwPolicy).to.equal('do_not_list')
564 expect(user.videoQuota).to.equal(42)
565 expect(user.roleLabel).to.equal('Moderator')
566 expect(user.id).to.be.a('number')
567 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
461 }) 568 })
462 569
463 const res = await getMyUserInformation(server.url, accessTokenUser) 570 it('Should have removed the user token', async function () {
464 const user = res.body 571 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
465 572
466 expect(user.username).to.equal('user_1') 573 accessTokenUser = await userLogin(server, user)
467 expect(user.email).to.equal('updated@example.com') 574 })
468 expect(user.nsfwPolicy).to.equal('do_not_list')
469 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
470 expect(user.id).to.be.a('number')
471 expect(user.account.displayName).to.equal('new display name')
472 expect(user.account.description).to.equal('my super description updated')
473 })
474 575
475 it('Should be able to update another user', async function () { 576 it('Should be able to update another user password', async function () {
476 await updateUser({ 577 await updateUser({
477 url: server.url, 578 url: server.url,
478 userId, 579 userId,
479 accessToken, 580 accessToken,
480 email: 'updated2@example.com', 581 password: 'password updated'
481 emailVerified: true, 582 })
482 videoQuota: 42,
483 role: UserRole.MODERATOR
484 })
485
486 const res = await getUserInformation(server.url, accessToken, userId)
487 const user = res.body
488
489 expect(user.username).to.equal('user_1')
490 expect(user.email).to.equal('updated2@example.com')
491 expect(user.emailVerified).to.be.true
492 expect(user.nsfwPolicy).to.equal('do_not_list')
493 expect(user.videoQuota).to.equal(42)
494 expect(user.roleLabel).to.equal('Moderator')
495 expect(user.id).to.be.a('number')
496 })
497 583
498 it('Should have removed the user token', async function () { 584 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
499 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
500 585
501 accessTokenUser = await userLogin(server, user) 586 await userLogin(server, user, 400)
502 })
503 587
504 it('Should be able to list video blacklist by a moderator', async function () { 588 user.password = 'password updated'
505 await getBlacklistedVideosList(server.url, accessTokenUser) 589 accessTokenUser = await userLogin(server, user)
590 })
506 }) 591 })
507 592
508 it('Should be able to remove this user', async function () { 593 describe('Video blacklists', function () {
509 await removeUser(server.url, userId, accessToken) 594 it('Should be able to list video blacklist by a moderator', async function () {
595 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
596 })
510 }) 597 })
511 598
512 it('Should not be able to login with this user', async function () { 599 describe('Remove a user', function () {
513 await userLogin(server, user, 400) 600 it('Should be able to remove this user', async function () {
514 }) 601 await removeUser(server.url, userId, accessToken)
602 })
515 603
516 it('Should not have videos of this user', async function () { 604 it('Should not be able to login with this user', async function () {
517 const res = await getVideosList(server.url) 605 await userLogin(server, user, 400)
606 })
518 607
519 expect(res.body.total).to.equal(1) 608 it('Should not have videos of this user', async function () {
609 const res = await getVideosList(server.url)
520 610
521 const video = res.body.data[ 0 ] 611 expect(res.body.total).to.equal(1)
522 expect(video.account.name).to.equal('root')
523 })
524 612
525 it('Should register a new user', async function () { 613 const video = res.body.data[ 0 ]
526 await registerUser(server.url, 'user_15', 'my super password') 614 expect(video.account.name).to.equal('root')
615 })
527 }) 616 })
528 617
529 it('Should be able to login with this registered user', async function () { 618 describe('Registering a new user', function () {
530 const user15 = { 619 it('Should register a new user', async function () {
531 username: 'user_15', 620 await registerUser(server.url, 'user_15', 'my super password')
532 password: 'my super password' 621 })
533 }
534 622
535 accessToken = await userLogin(server, user15) 623 it('Should be able to login with this registered user', async function () {
536 }) 624 const user15 = {
625 username: 'user_15',
626 password: 'my super password'
627 }
537 628
538 it('Should have the correct video quota', async function () { 629 accessToken = await userLogin(server, user15)
539 const res = await getMyUserInformation(server.url, accessToken) 630 })
540 const user = res.body
541 631
542 expect(user.videoQuota).to.equal(5 * 1024 * 1024) 632 it('Should have the correct video quota', async function () {
543 }) 633 const res = await getMyUserInformation(server.url, accessToken)
634 const user = res.body
544 635
545 it('Should remove me', async function () { 636 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
546 { 637 })
547 const res = await getUsersList(server.url, server.accessToken)
548 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
549 }
550 638
551 await deleteMe(server.url, accessToken) 639 it('Should remove me', async function () {
640 {
641 const res = await getUsersList(server.url, server.accessToken)
642 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
643 }
552 644
553 { 645 await deleteMe(server.url, accessToken)
554 const res = await getUsersList(server.url, server.accessToken) 646
555 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined 647 {
556 } 648 const res = await getUsersList(server.url, server.accessToken)
649 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
650 }
651 })
557 }) 652 })
558 653
559 it('Should block and unblock a user', async function () { 654 describe('User blocking', function () {
560 const user16 = { 655 it('Should block and unblock a user', async function () {
561 username: 'user_16', 656 const user16 = {
562 password: 'my super password' 657 username: 'user_16',
563 } 658 password: 'my super password'
564 const resUser = await createUser(server.url, server.accessToken, user16.username, user16.password) 659 }
565 const user16Id = resUser.body.user.id 660 const resUser = await createUser({
661 url: server.url,
662 accessToken: server.accessToken,
663 username: user16.username,
664 password: user16.password
665 })
666 const user16Id = resUser.body.user.id
566 667
567 accessToken = await userLogin(server, user16) 668 accessToken = await userLogin(server, user16)
568 669
569 await getMyUserInformation(server.url, accessToken, 200) 670 await getMyUserInformation(server.url, accessToken, 200)
570 await blockUser(server.url, user16Id, server.accessToken) 671 await blockUser(server.url, user16Id, server.accessToken)
571 672
572 await getMyUserInformation(server.url, accessToken, 401) 673 await getMyUserInformation(server.url, accessToken, 401)
573 await userLogin(server, user16, 400) 674 await userLogin(server, user16, 400)
574 675
575 await unblockUser(server.url, user16Id, server.accessToken) 676 await unblockUser(server.url, user16Id, server.accessToken)
576 accessToken = await userLogin(server, user16) 677 accessToken = await userLogin(server, user16)
577 await getMyUserInformation(server.url, accessToken, 200) 678 await getMyUserInformation(server.url, accessToken, 200)
679 })
578 }) 680 })
579 681
580 after(async function () { 682 after(async function () {
581 killallServers([ server ]) 683 await cleanupTests([ server ])
582
583 // Keep the logs if the test failed
584 if (this[ 'ok' ]) {
585 await flushTests()
586 }
587 }) 684 })
588}) 685})
diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts
index 97f467aae..93e1f3e98 100644
--- a/server/tests/api/videos/index.ts
+++ b/server/tests/api/videos/index.ts
@@ -8,11 +8,14 @@ import './video-change-ownership'
8import './video-channels' 8import './video-channels'
9import './video-comments' 9import './video-comments'
10import './video-description' 10import './video-description'
11import './video-hls'
11import './video-imports' 12import './video-imports'
12import './video-nsfw' 13import './video-nsfw'
14import './video-playlists'
13import './video-privacy' 15import './video-privacy'
14import './video-schedule-update' 16import './video-schedule-update'
15import './video-transcoder' 17import './video-transcoder'
16import './videos-filter' 18import './videos-filter'
17import './videos-history' 19import './videos-history'
18import './videos-overview' 20import './videos-overview'
21import './videos-views-cleaner'
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 6c281e49e..68c1e9a8d 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -9,7 +9,7 @@ import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/
9import { 9import {
10 addVideoChannel, 10 addVideoChannel,
11 checkTmpIsEmpty, 11 checkTmpIsEmpty,
12 checkVideoFilesWereRemoved, 12 checkVideoFilesWereRemoved, cleanupTests,
13 completeVideoCheck, 13 completeVideoCheck,
14 createUser, 14 createUser,
15 dateIsValid, 15 dateIsValid,
@@ -32,15 +32,15 @@ import {
32 viewVideo, 32 viewVideo,
33 wait, 33 wait,
34 webtorrentAdd 34 webtorrentAdd
35} from '../../../../shared/utils' 35} from '../../../../shared/extra-utils'
36import { 36import {
37 addVideoCommentReply, 37 addVideoCommentReply,
38 addVideoCommentThread, 38 addVideoCommentThread,
39 deleteVideoComment, 39 deleteVideoComment,
40 getVideoCommentThreads, 40 getVideoCommentThreads,
41 getVideoThreadComments 41 getVideoThreadComments
42} from '../../../../shared/utils/videos/video-comments' 42} from '../../../../shared/extra-utils/videos/video-comments'
43import { waitJobs } from '../../../../shared/utils/server/jobs' 43import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
44 44
45const expect = chai.expect 45const expect = chai.expect
46 46
@@ -98,6 +98,7 @@ describe('Test multiple servers', function () {
98 nsfw: true, 98 nsfw: true,
99 description: 'my super description for server 1', 99 description: 'my super description for server 1',
100 support: 'my super support text for server 1', 100 support: 'my super support text for server 1',
101 originallyPublishedAt: '2019-02-10T13:38:14.449Z',
101 tags: [ 'tag1p1', 'tag2p1' ], 102 tags: [ 'tag1p1', 'tag2p1' ],
102 channelId: videoChannelId, 103 channelId: videoChannelId,
103 fixture: 'video_short1.webm' 104 fixture: 'video_short1.webm'
@@ -118,6 +119,7 @@ describe('Test multiple servers', function () {
118 nsfw: true, 119 nsfw: true,
119 description: 'my super description for server 1', 120 description: 'my super description for server 1',
120 support: 'my super support text for server 1', 121 support: 'my super support text for server 1',
122 originallyPublishedAt: '2019-02-10T13:38:14.449Z',
121 account: { 123 account: {
122 name: 'root', 124 name: 'root',
123 host: 'localhost:9001' 125 host: 'localhost:9001'
@@ -128,6 +130,7 @@ describe('Test multiple servers', function () {
128 tags: [ 'tag1p1', 'tag2p1' ], 130 tags: [ 'tag1p1', 'tag2p1' ],
129 privacy: VideoPrivacy.PUBLIC, 131 privacy: VideoPrivacy.PUBLIC,
130 commentsEnabled: true, 132 commentsEnabled: true,
133 downloadEnabled: true,
131 channel: { 134 channel: {
132 displayName: 'my channel', 135 displayName: 'my channel',
133 name: 'super_channel_name', 136 name: 'super_channel_name',
@@ -161,7 +164,7 @@ describe('Test multiple servers', function () {
161 username: 'user1', 164 username: 'user1',
162 password: 'super_password' 165 password: 'super_password'
163 } 166 }
164 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) 167 await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
165 const userAccessToken = await userLogin(servers[1], user) 168 const userAccessToken = await userLogin(servers[1], user)
166 169
167 const videoAttributes = { 170 const videoAttributes = {
@@ -199,6 +202,7 @@ describe('Test multiple servers', function () {
199 }, 202 },
200 isLocal, 203 isLocal,
201 commentsEnabled: true, 204 commentsEnabled: true,
205 downloadEnabled: true,
202 duration: 5, 206 duration: 5,
203 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], 207 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
204 privacy: VideoPrivacy.PUBLIC, 208 privacy: VideoPrivacy.PUBLIC,
@@ -307,6 +311,7 @@ describe('Test multiple servers', function () {
307 isLocal, 311 isLocal,
308 duration: 5, 312 duration: 5,
309 commentsEnabled: true, 313 commentsEnabled: true,
314 downloadEnabled: true,
310 tags: [ 'tag1p3' ], 315 tags: [ 'tag1p3' ],
311 privacy: VideoPrivacy.PUBLIC, 316 privacy: VideoPrivacy.PUBLIC,
312 channel: { 317 channel: {
@@ -338,6 +343,7 @@ describe('Test multiple servers', function () {
338 host: 'localhost:9003' 343 host: 'localhost:9003'
339 }, 344 },
340 commentsEnabled: true, 345 commentsEnabled: true,
346 downloadEnabled: true,
341 isLocal, 347 isLocal,
342 duration: 5, 348 duration: 5,
343 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], 349 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
@@ -573,15 +579,15 @@ describe('Test multiple servers', function () {
573 this.timeout(20000) 579 this.timeout(20000)
574 580
575 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') 581 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
576 await wait(200) 582 await wait(500)
577 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike') 583 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')
578 await wait(200) 584 await wait(500)
579 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') 585 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
580 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like') 586 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')
581 await wait(200) 587 await wait(500)
582 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike') 588 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')
583 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike') 589 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')
584 await wait(200) 590 await wait(500)
585 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') 591 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')
586 592
587 await waitJobs(servers) 593 await waitJobs(servers)
@@ -621,6 +627,7 @@ describe('Test multiple servers', function () {
621 support: 'my super support text updated', 627 support: 'my super support text updated',
622 tags: [ 'tag_up_1', 'tag_up_2' ], 628 tags: [ 'tag_up_1', 'tag_up_2' ],
623 thumbnailfile: 'thumbnail.jpg', 629 thumbnailfile: 'thumbnail.jpg',
630 originallyPublishedAt: '2019-02-11T13:38:14.449Z',
624 previewfile: 'preview.jpg' 631 previewfile: 'preview.jpg'
625 } 632 }
626 633
@@ -648,6 +655,7 @@ describe('Test multiple servers', function () {
648 nsfw: true, 655 nsfw: true,
649 description: 'my super description updated', 656 description: 'my super description updated',
650 support: 'my super support text updated', 657 support: 'my super support text updated',
658 originallyPublishedAt: '2019-02-11T13:38:14.449Z',
651 account: { 659 account: {
652 name: 'root', 660 name: 'root',
653 host: 'localhost:9003' 661 host: 'localhost:9003'
@@ -655,6 +663,7 @@ describe('Test multiple servers', function () {
655 isLocal, 663 isLocal,
656 duration: 5, 664 duration: 5,
657 commentsEnabled: true, 665 commentsEnabled: true,
666 downloadEnabled: true,
658 tags: [ 'tag_up_1', 'tag_up_2' ], 667 tags: [ 'tag_up_1', 'tag_up_2' ],
659 privacy: VideoPrivacy.PUBLIC, 668 privacy: VideoPrivacy.PUBLIC,
660 channel: { 669 channel: {
@@ -914,11 +923,12 @@ describe('Test multiple servers', function () {
914 } 923 }
915 }) 924 })
916 925
917 it('Should disable comments', async function () { 926 it('Should disable comments and download', async function () {
918 this.timeout(20000) 927 this.timeout(20000)
919 928
920 const attributes = { 929 const attributes = {
921 commentsEnabled: false 930 commentsEnabled: false,
931 downloadEnabled: false
922 } 932 }
923 933
924 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) 934 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes)
@@ -928,6 +938,7 @@ describe('Test multiple servers', function () {
928 for (const server of servers) { 938 for (const server of servers) {
929 const res = await getVideo(server.url, videoUUID) 939 const res = await getVideo(server.url, videoUUID)
930 expect(res.body.commentsEnabled).to.be.false 940 expect(res.body.commentsEnabled).to.be.false
941 expect(res.body.downloadEnabled).to.be.false
931 942
932 const text = 'my super forbidden comment' 943 const text = 'my super forbidden comment'
933 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409) 944 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409)
@@ -976,6 +987,7 @@ describe('Test multiple servers', function () {
976 isLocal, 987 isLocal,
977 duration: 5, 988 duration: 5,
978 commentsEnabled: false, 989 commentsEnabled: false,
990 downloadEnabled: true,
979 tags: [ ], 991 tags: [ ],
980 privacy: VideoPrivacy.PUBLIC, 992 privacy: VideoPrivacy.PUBLIC,
981 channel: { 993 channel: {
@@ -1018,11 +1030,6 @@ describe('Test multiple servers', function () {
1018 }) 1030 })
1019 1031
1020 after(async function () { 1032 after(async function () {
1021 killallServers(servers) 1033 await cleanupTests(servers)
1022
1023 // Keep the logs if the test failed
1024 if (this['ok']) {
1025 await flushTests()
1026 }
1027 }) 1034 })
1028}) 1035})
diff --git a/server/tests/api/videos/services.ts b/server/tests/api/videos/services.ts
index 2da86964f..e9ad947b2 100644
--- a/server/tests/api/videos/services.ts
+++ b/server/tests/api/videos/services.ts
@@ -2,16 +2,8 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import { getOEmbed, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index'
6 flushTests, 6import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
7 getOEmbed,
8 getVideosList,
9 killallServers,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo
13} from '../../../../shared/utils/index'
14import { runServer } from '../../../../shared/utils/server/servers'
15 7
16const expect = chai.expect 8const expect = chai.expect
17 9
@@ -21,9 +13,7 @@ describe('Test services', function () {
21 before(async function () { 13 before(async function () {
22 this.timeout(30000) 14 this.timeout(30000)
23 15
24 await flushTests() 16 server = await flushAndRunServer(1)
25
26 server = await runServer(1)
27 17
28 await setAccessTokensToServers([ server ]) 18 await setAccessTokensToServers([ server ])
29 19
@@ -77,6 +67,6 @@ describe('Test services', function () {
77 }) 67 })
78 68
79 after(async function () { 69 after(async function () {
80 killallServers([ server ]) 70 await cleanupTests([ server ])
81 }) 71 })
82}) 72})
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index 069dec67c..1f366b642 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -6,8 +6,9 @@ import 'mocha'
6import { VideoPrivacy } from '../../../../shared/models/videos' 6import { VideoPrivacy } from '../../../../shared/models/videos'
7import { 7import {
8 checkVideoFilesWereRemoved, 8 checkVideoFilesWereRemoved,
9 cleanupTests,
9 completeVideoCheck, 10 completeVideoCheck,
10 flushTests, 11 flushAndRunServer,
11 getVideo, 12 getVideo,
12 getVideoCategories, 13 getVideoCategories,
13 getVideoLanguages, 14 getVideoLanguages,
@@ -17,10 +18,8 @@ import {
17 getVideosListPagination, 18 getVideosListPagination,
18 getVideosListSort, 19 getVideosListSort,
19 getVideosWithFilters, 20 getVideosWithFilters,
20 killallServers,
21 rateVideo, 21 rateVideo,
22 removeVideo, 22 removeVideo,
23 runServer,
24 ServerInfo, 23 ServerInfo,
25 setAccessTokensToServers, 24 setAccessTokensToServers,
26 testImage, 25 testImage,
@@ -28,7 +27,7 @@ import {
28 uploadVideo, 27 uploadVideo,
29 viewVideo, 28 viewVideo,
30 wait 29 wait
31} from '../../../../shared/utils' 30} from '../../../../shared/extra-utils'
32 31
33const expect = chai.expect 32const expect = chai.expect
34 33
@@ -55,6 +54,7 @@ describe('Test a single server', function () {
55 tags: [ 'tag1', 'tag2', 'tag3' ], 54 tags: [ 'tag1', 'tag2', 'tag3' ],
56 privacy: VideoPrivacy.PUBLIC, 55 privacy: VideoPrivacy.PUBLIC,
57 commentsEnabled: true, 56 commentsEnabled: true,
57 downloadEnabled: true,
58 channel: { 58 channel: {
59 displayName: 'Main root channel', 59 displayName: 'Main root channel',
60 name: 'root_channel', 60 name: 'root_channel',
@@ -87,6 +87,7 @@ describe('Test a single server', function () {
87 privacy: VideoPrivacy.PUBLIC, 87 privacy: VideoPrivacy.PUBLIC,
88 duration: 5, 88 duration: 5,
89 commentsEnabled: false, 89 commentsEnabled: false,
90 downloadEnabled: false,
90 channel: { 91 channel: {
91 name: 'root_channel', 92 name: 'root_channel',
92 displayName: 'Main root channel', 93 displayName: 'Main root channel',
@@ -105,9 +106,7 @@ describe('Test a single server', function () {
105 before(async function () { 106 before(async function () {
106 this.timeout(30000) 107 this.timeout(30000)
107 108
108 await flushTests() 109 server = await flushAndRunServer(1)
109
110 server = await runServer(1)
111 110
112 await setAccessTokensToServers([ server ]) 111 await setAccessTokensToServers([ server ])
113 }) 112 })
@@ -356,6 +355,7 @@ describe('Test a single server', function () {
356 nsfw: false, 355 nsfw: false,
357 description: 'my super description updated', 356 description: 'my super description updated',
358 commentsEnabled: false, 357 commentsEnabled: false,
358 downloadEnabled: false,
359 tags: [ 'tagup1', 'tagup2' ] 359 tags: [ 'tagup1', 'tagup2' ]
360 } 360 }
361 await updateVideo(server.url, server.accessToken, videoId, attributes) 361 await updateVideo(server.url, server.accessToken, videoId, attributes)
@@ -424,11 +424,6 @@ describe('Test a single server', function () {
424 }) 424 })
425 425
426 after(async function () { 426 after(async function () {
427 killallServers([ server ]) 427 await cleanupTests([ server ])
428
429 // Keep the logs if the test failed
430 if (this['ok']) {
431 await flushTests()
432 }
433 }) 428 })
434}) 429})
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts
index 3a7b623da..7318497d5 100644
--- a/server/tests/api/videos/video-abuse.ts
+++ b/server/tests/api/videos/video-abuse.ts
@@ -4,6 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos' 5import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos'
6import { 6import {
7 cleanupTests,
7 deleteVideoAbuse, 8 deleteVideoAbuse,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
9 getVideoAbusesList, 10 getVideoAbusesList,
@@ -14,9 +15,9 @@ import {
14 setAccessTokensToServers, 15 setAccessTokensToServers,
15 updateVideoAbuse, 16 updateVideoAbuse,
16 uploadVideo 17 uploadVideo
17} from '../../../../shared/utils/index' 18} from '../../../../shared/extra-utils/index'
18import { doubleFollow } from '../../../../shared/utils/server/follows' 19import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
19import { waitJobs } from '../../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20 21
21const expect = chai.expect 22const expect = chai.expect
22 23
@@ -173,6 +174,6 @@ describe('Test video abuses', function () {
173 }) 174 })
174 175
175 after(async function () { 176 after(async function () {
176 killallServers(servers) 177 await cleanupTests(servers)
177 }) 178 })
178}) 179})
diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts
index d39ad63b4..e907bbdc0 100644
--- a/server/tests/api/videos/video-blacklist.ts
+++ b/server/tests/api/videos/video-blacklist.ts
@@ -4,29 +4,32 @@ import * as chai from 'chai'
4import { orderBy } from 'lodash' 4import { orderBy } from 'lodash'
5import 'mocha' 5import 'mocha'
6import { 6import {
7 addVideoToBlacklist, 7 addVideoToBlacklist, cleanupTests,
8 createUser,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
9 getBlacklistedVideosList, 10 getBlacklistedVideosList,
10 getMyVideos, 11 getMyVideos,
11 getSortedBlacklistedVideosList,
12 getVideosList, 12 getVideosList,
13 killallServers, 13 killallServers,
14 removeVideoFromBlacklist, 14 removeVideoFromBlacklist,
15 reRunServer,
15 searchVideo, 16 searchVideo,
16 ServerInfo, 17 ServerInfo,
17 setAccessTokensToServers, 18 setAccessTokensToServers,
18 updateVideo, 19 updateVideo,
19 updateVideoBlacklist, 20 updateVideoBlacklist,
20 uploadVideo, 21 uploadVideo,
21 viewVideo 22 userLogin
22} from '../../../../shared/utils/index' 23} from '../../../../shared/extra-utils/index'
23import { doubleFollow } from '../../../../shared/utils/server/follows' 24import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
24import { waitJobs } from '../../../../shared/utils/server/jobs' 25import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
25import { VideoBlacklist } from '../../../../shared/models/videos' 26import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
27import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
28import { UserRole } from '../../../../shared/models/users'
26 29
27const expect = chai.expect 30const expect = chai.expect
28 31
29describe('Test video blacklist management', function () { 32describe('Test video blacklist', function () {
30 let servers: ServerInfo[] = [] 33 let servers: ServerInfo[] = []
31 let videoId: number 34 let videoId: number
32 35
@@ -101,9 +104,9 @@ describe('Test video blacklist management', function () {
101 }) 104 })
102 }) 105 })
103 106
104 describe('When listing blacklisted videos', function () { 107 describe('When listing manually blacklisted videos', function () {
105 it('Should display all the blacklisted videos', async function () { 108 it('Should display all the blacklisted videos', async function () {
106 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) 109 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken })
107 110
108 expect(res.body.total).to.equal(2) 111 expect(res.body.total).to.equal(2)
109 112
@@ -117,8 +120,36 @@ describe('Test video blacklist management', function () {
117 } 120 }
118 }) 121 })
119 122
123 it('Should display all the blacklisted videos when applying manual type filter', async function () {
124 const res = await getBlacklistedVideosList({
125 url: servers[ 0 ].url,
126 token: servers[ 0 ].accessToken,
127 type: VideoBlacklistType.MANUAL
128 })
129
130 expect(res.body.total).to.equal(2)
131
132 const blacklistedVideos = res.body.data
133 expect(blacklistedVideos).to.be.an('array')
134 expect(blacklistedVideos.length).to.equal(2)
135 })
136
137 it('Should display nothing when applying automatic type filter', async function () {
138 const res = await getBlacklistedVideosList({
139 url: servers[ 0 ].url,
140 token: servers[ 0 ].accessToken,
141 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
142 })
143
144 expect(res.body.total).to.equal(0)
145
146 const blacklistedVideos = res.body.data
147 expect(blacklistedVideos).to.be.an('array')
148 expect(blacklistedVideos.length).to.equal(0)
149 })
150
120 it('Should get the correct sort when sorting by descending id', async function () { 151 it('Should get the correct sort when sorting by descending id', async function () {
121 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') 152 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-id' })
122 expect(res.body.total).to.equal(2) 153 expect(res.body.total).to.equal(2)
123 154
124 const blacklistedVideos = res.body.data 155 const blacklistedVideos = res.body.data
@@ -131,7 +162,7 @@ describe('Test video blacklist management', function () {
131 }) 162 })
132 163
133 it('Should get the correct sort when sorting by descending video name', async function () { 164 it('Should get the correct sort when sorting by descending video name', async function () {
134 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 165 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
135 expect(res.body.total).to.equal(2) 166 expect(res.body.total).to.equal(2)
136 167
137 const blacklistedVideos = res.body.data 168 const blacklistedVideos = res.body.data
@@ -144,7 +175,7 @@ describe('Test video blacklist management', function () {
144 }) 175 })
145 176
146 it('Should get the correct sort when sorting by ascending creation date', async function () { 177 it('Should get the correct sort when sorting by ascending creation date', async function () {
147 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') 178 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' })
148 expect(res.body.total).to.equal(2) 179 expect(res.body.total).to.equal(2)
149 180
150 const blacklistedVideos = res.body.data 181 const blacklistedVideos = res.body.data
@@ -161,7 +192,7 @@ describe('Test video blacklist management', function () {
161 it('Should change the reason', async function () { 192 it('Should change the reason', async function () {
162 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') 193 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
163 194
164 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 195 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
165 const video = res.body.data.find(b => b.video.id === videoId) 196 const video = res.body.data.find(b => b.video.id === videoId)
166 197
167 expect(video.reason).to.equal('my super reason updated') 198 expect(video.reason).to.equal('my super reason updated')
@@ -197,7 +228,7 @@ describe('Test video blacklist management', function () {
197 228
198 it('Should remove a video from the blacklist on server 1', async function () { 229 it('Should remove a video from the blacklist on server 1', async function () {
199 // Get one video in the blacklist 230 // Get one video in the blacklist
200 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 231 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
201 videoToRemove = res.body.data[0] 232 videoToRemove = res.body.data[0]
202 blacklist = res.body.data.slice(1) 233 blacklist = res.body.data.slice(1)
203 234
@@ -218,7 +249,7 @@ describe('Test video blacklist management', function () {
218 }) 249 })
219 250
220 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { 251 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
221 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 252 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
222 expect(res.body.total).to.equal(1) 253 expect(res.body.total).to.equal(1)
223 254
224 const videos = res.body.data 255 const videos = res.body.data
@@ -292,7 +323,7 @@ describe('Test video blacklist management', function () {
292 }) 323 })
293 324
294 it('Should have the correct video blacklist unfederate attribute', async function () { 325 it('Should have the correct video blacklist unfederate attribute', async function () {
295 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') 326 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' })
296 327
297 const blacklistedVideos: VideoBlacklist[] = res.body.data 328 const blacklistedVideos: VideoBlacklist[] = res.body.data
298 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) 329 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
@@ -317,7 +348,84 @@ describe('Test video blacklist management', function () {
317 348
318 }) 349 })
319 350
351 describe('When auto blacklist videos', function () {
352 let userWithoutFlag: string
353 let userWithFlag: string
354
355 before(async function () {
356 this.timeout(20000)
357
358 killallServers([ servers[0] ])
359
360 const config = {
361 'auto_blacklist': {
362 videos: {
363 'of_users': {
364 enabled: true
365 }
366 }
367 }
368 }
369 await reRunServer(servers[0], config)
370
371 {
372 const user = { username: 'user_without_flag', password: 'password' }
373 await createUser({
374 url: servers[ 0 ].url,
375 accessToken: servers[ 0 ].accessToken,
376 username: user.username,
377 adminFlags: UserAdminFlag.NONE,
378 password: user.password,
379 role: UserRole.USER
380 })
381
382 userWithoutFlag = await userLogin(servers[0], user)
383 }
384
385 {
386 const user = { username: 'user_with_flag', password: 'password' }
387 await createUser({
388 url: servers[ 0 ].url,
389 accessToken: servers[ 0 ].accessToken,
390 username: user.username,
391 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST,
392 password: user.password,
393 role: UserRole.USER
394 })
395
396 userWithFlag = await userLogin(servers[0], user)
397 }
398
399 await waitJobs(servers)
400 })
401
402 it('Should auto blacklist a video', async function () {
403 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
404
405 const res = await getBlacklistedVideosList({
406 url: servers[ 0 ].url,
407 token: servers[ 0 ].accessToken,
408 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
409 })
410
411 expect(res.body.total).to.equal(1)
412 expect(res.body.data[0].video.name).to.equal('blacklisted')
413 })
414
415 it('Should not auto blacklist a video', async function () {
416 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
417
418 const res = await getBlacklistedVideosList({
419 url: servers[ 0 ].url,
420 token: servers[ 0 ].accessToken,
421 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
422 })
423
424 expect(res.body.total).to.equal(1)
425 })
426 })
427
320 after(async function () { 428 after(async function () {
321 killallServers(servers) 429 await cleanupTests(servers)
322 }) 430 })
323}) 431})
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index 57bee713f..5e13f5949 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -3,16 +3,21 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 checkVideoFilesWereRemoved, 6 checkVideoFilesWereRemoved, cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 removeVideo, 9 removeVideo,
10 uploadVideo, 10 uploadVideo,
11 wait 11 wait
12} from '../../../../shared/utils' 12} from '../../../../shared/extra-utils'
13import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index' 13import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
14import { waitJobs } from '../../../../shared/utils/server/jobs' 14import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
15import { createVideoCaption, deleteVideoCaption, listVideoCaptions, testCaptionFile } from '../../../../shared/utils/videos/video-captions' 15import {
16 createVideoCaption,
17 deleteVideoCaption,
18 listVideoCaptions,
19 testCaptionFile
20} from '../../../../shared/extra-utils/videos/video-captions'
16import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' 21import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
17 22
18const expect = chai.expect 23const expect = chai.expect
@@ -24,8 +29,6 @@ describe('Test video captions', function () {
24 before(async function () { 29 before(async function () {
25 this.timeout(30000) 30 this.timeout(30000)
26 31
27 await flushTests()
28
29 servers = await flushAndRunMultipleServers(2) 32 servers = await flushAndRunMultipleServers(2)
30 33
31 await setAccessTokensToServers(servers) 34 await setAccessTokensToServers(servers)
@@ -193,6 +196,6 @@ describe('Test video captions', function () {
193 }) 196 })
194 197
195 after(async function () { 198 after(async function () {
196 killallServers(servers) 199 await cleanupTests(servers)
197 }) 200 })
198}) 201})
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index 25675a966..1c0327d40 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -4,22 +4,23 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 acceptChangeOwnership, 6 acceptChangeOwnership,
7 changeVideoOwnership, 7 changeVideoOwnership, cleanupTests,
8 createUser, doubleFollow, flushAndRunMultipleServers, 8 createUser,
9 flushTests, 9 doubleFollow,
10 flushAndRunMultipleServers,
11 flushAndRunServer,
10 getMyUserInformation, 12 getMyUserInformation,
13 getVideo,
11 getVideoChangeOwnershipList, 14 getVideoChangeOwnershipList,
12 getVideosList, 15 getVideosList,
13 killallServers, 16 killallServers,
14 refuseChangeOwnership, 17 refuseChangeOwnership,
15 runServer,
16 ServerInfo, 18 ServerInfo,
17 setAccessTokensToServers, 19 setAccessTokensToServers,
18 uploadVideo, 20 uploadVideo,
19 userLogin, 21 userLogin
20 getVideo 22} from '../../../../shared/extra-utils'
21} from '../../../../shared/utils' 23import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22import { waitJobs } from '../../../../shared/utils/server/jobs'
23import { User } from '../../../../shared/models/users' 24import { User } from '../../../../shared/models/users'
24import { VideoDetails } from '../../../../shared/models/videos' 25import { VideoDetails } from '../../../../shared/models/videos'
25 26
@@ -46,8 +47,20 @@ describe('Test video change ownership - nominal', function () {
46 await setAccessTokensToServers(servers) 47 await setAccessTokensToServers(servers)
47 48
48 const videoQuota = 42000000 49 const videoQuota = 42000000
49 await createUser(servers[0].url, servers[0].accessToken, firstUser.username, firstUser.password, videoQuota) 50 await createUser({
50 await createUser(servers[0].url, servers[0].accessToken, secondUser.username, secondUser.password, videoQuota) 51 url: servers[ 0 ].url,
52 accessToken: servers[ 0 ].accessToken,
53 username: firstUser.username,
54 password: firstUser.password,
55 videoQuota: videoQuota
56 })
57 await createUser({
58 url: servers[ 0 ].url,
59 accessToken: servers[ 0 ].accessToken,
60 username: secondUser.username,
61 password: secondUser.password,
62 videoQuota: videoQuota
63 })
51 64
52 firstUserAccessToken = await userLogin(servers[0], firstUser) 65 firstUserAccessToken = await userLogin(servers[0], firstUser)
53 secondUserAccessToken = await userLogin(servers[0], secondUser) 66 secondUserAccessToken = await userLogin(servers[0], secondUser)
@@ -190,7 +203,7 @@ describe('Test video change ownership - nominal', function () {
190 } 203 }
191 }) 204 })
192 205
193 after(async function () { 206 after(function () {
194 killallServers(servers) 207 killallServers(servers)
195 }) 208 })
196}) 209})
@@ -213,14 +226,25 @@ describe('Test video change ownership - quota too small', function () {
213 this.timeout(50000) 226 this.timeout(50000)
214 227
215 // Run one server 228 // Run one server
216 await flushTests() 229 server = await flushAndRunServer(1)
217 server = await runServer(1)
218 await setAccessTokensToServers([server]) 230 await setAccessTokensToServers([server])
219 231
220 const videoQuota = 42000000 232 const videoQuota = 42000000
221 const limitedVideoQuota = 10 233 const limitedVideoQuota = 10
222 await createUser(server.url, server.accessToken, firstUser.username, firstUser.password, videoQuota) 234 await createUser({
223 await createUser(server.url, server.accessToken, secondUser.username, secondUser.password, limitedVideoQuota) 235 url: server.url,
236 accessToken: server.accessToken,
237 username: firstUser.username,
238 password: firstUser.password,
239 videoQuota: videoQuota
240 })
241 await createUser({
242 url: server.url,
243 accessToken: server.accessToken,
244 username: secondUser.username,
245 password: secondUser.password,
246 videoQuota: limitedVideoQuota
247 })
224 248
225 firstUserAccessToken = await userLogin(server, firstUser) 249 firstUserAccessToken = await userLogin(server, firstUser)
226 secondUserAccessToken = await userLogin(server, secondUser) 250 secondUserAccessToken = await userLogin(server, secondUser)
@@ -274,6 +298,6 @@ describe('Test video change ownership - quota too small', function () {
274 }) 298 })
275 299
276 after(async function () { 300 after(async function () {
277 killallServers([server]) 301 await cleanupTests([ server ])
278 }) 302 })
279}) 303})
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 63514d69c..345e96f43 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -4,6 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { User, Video } from '../../../../shared/index' 5import { User, Video } from '../../../../shared/index'
6import { 6import {
7 cleanupTests,
7 createUser, 8 createUser,
8 doubleFollow, 9 doubleFollow,
9 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -13,7 +14,7 @@ import {
13 updateVideoChannelAvatar, 14 updateVideoChannelAvatar,
14 uploadVideo, 15 uploadVideo,
15 userLogin 16 userLogin
16} from '../../../../shared/utils' 17} from '../../../../shared/extra-utils'
17import { 18import {
18 addVideoChannel, 19 addVideoChannel,
19 deleteVideoChannel, 20 deleteVideoChannel,
@@ -26,8 +27,8 @@ import {
26 ServerInfo, 27 ServerInfo,
27 setAccessTokensToServers, 28 setAccessTokensToServers,
28 updateVideoChannel 29 updateVideoChannel
29} from '../../../../shared/utils/index' 30} from '../../../../shared/extra-utils/index'
30import { waitJobs } from '../../../../shared/utils/server/jobs' 31import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
31 32
32const expect = chai.expect 33const expect = chai.expect
33 34
@@ -42,8 +43,6 @@ describe('Test video channels', function () {
42 before(async function () { 43 before(async function () {
43 this.timeout(30000) 44 this.timeout(30000)
44 45
45 await flushTests()
46
47 servers = await flushAndRunMultipleServers(2) 46 servers = await flushAndRunMultipleServers(2)
48 47
49 await setAccessTokensToServers(servers) 48 await setAccessTokensToServers(servers)
@@ -270,7 +269,7 @@ describe('Test video channels', function () {
270 } 269 }
271 270
272 { 271 {
273 await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, 'toto', 'password') 272 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' })
274 const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' }) 273 const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' })
275 274
276 const res = await getMyUserInformation(servers[ 0 ].url, accessToken) 275 const res = await getMyUserInformation(servers[ 0 ].url, accessToken)
@@ -280,6 +279,6 @@ describe('Test video channels', function () {
280 }) 279 })
281 280
282 after(async function () { 281 after(async function () {
283 killallServers(servers) 282 await cleanupTests(servers)
284 }) 283 })
285}) 284})
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index ce1b17e35..22fd8c058 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -3,24 +3,22 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
6import { testImage } from '../../../../shared/utils' 6import { cleanupTests, testImage } from '../../../../shared/extra-utils'
7import { 7import {
8 dateIsValid, 8 dateIsValid,
9 flushTests, 9 flushAndRunServer,
10 killallServers,
11 runServer,
12 ServerInfo, 10 ServerInfo,
13 setAccessTokensToServers, 11 setAccessTokensToServers,
14 updateMyAvatar, 12 updateMyAvatar,
15 uploadVideo 13 uploadVideo
16} from '../../../../shared/utils/index' 14} from '../../../../shared/extra-utils/index'
17import { 15import {
18 addVideoCommentReply, 16 addVideoCommentReply,
19 addVideoCommentThread, 17 addVideoCommentThread,
20 deleteVideoComment, 18 deleteVideoComment,
21 getVideoCommentThreads, 19 getVideoCommentThreads,
22 getVideoThreadComments 20 getVideoThreadComments
23} from '../../../../shared/utils/videos/video-comments' 21} from '../../../../shared/extra-utils/videos/video-comments'
24 22
25const expect = chai.expect 23const expect = chai.expect
26 24
@@ -34,9 +32,7 @@ describe('Test video comments', function () {
34 before(async function () { 32 before(async function () {
35 this.timeout(30000) 33 this.timeout(30000)
36 34
37 await flushTests() 35 server = await flushAndRunServer(1)
38
39 server = await runServer(1)
40 36
41 await setAccessTokensToServers([ server ]) 37 await setAccessTokensToServers([ server ])
42 38
@@ -202,6 +198,6 @@ describe('Test video comments', function () {
202 }) 198 })
203 199
204 after(async function () { 200 after(async function () {
205 killallServers([ server ]) 201 await cleanupTests([ server ])
206 }) 202 })
207}) 203})
diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts
index cbda0b9a6..db4d278bf 100644
--- a/server/tests/api/videos/video-description.ts
+++ b/server/tests/api/videos/video-description.ts
@@ -3,6 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 cleanupTests,
6 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
7 getVideo, 8 getVideo,
8 getVideoDescription, 9 getVideoDescription,
@@ -12,9 +13,9 @@ import {
12 setAccessTokensToServers, 13 setAccessTokensToServers,
13 updateVideo, 14 updateVideo,
14 uploadVideo 15 uploadVideo
15} from '../../../../shared/utils/index' 16} from '../../../../shared/extra-utils/index'
16import { doubleFollow } from '../../../../shared/utils/server/follows' 17import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
17import { waitJobs } from '../../../../shared/utils/server/jobs' 18import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18 19
19const expect = chai.expect 20const expect = chai.expect
20 21
@@ -100,6 +101,6 @@ describe('Test video description', function () {
100 }) 101 })
101 102
102 after(async function () { 103 after(async function () {
103 killallServers(servers) 104 await cleanupTests(servers)
104 }) 105 })
105}) 106})
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts
new file mode 100644
index 000000000..22031c18b
--- /dev/null
+++ b/server/tests/api/videos/video-hls.ts
@@ -0,0 +1,134 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 checkDirectoryIsEmpty,
7 checkSegmentHash,
8 checkTmpIsEmpty, cleanupTests,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 flushTests,
12 getPlaylist,
13 getVideo,
14 killallServers,
15 removeVideo,
16 ServerInfo,
17 setAccessTokensToServers,
18 updateVideo,
19 uploadVideo,
20 waitJobs
21} from '../../../../shared/extra-utils'
22import { VideoDetails } from '../../../../shared/models/videos'
23import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
24import { join } from 'path'
25
26const expect = chai.expect
27
28async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) {
29 const resolutions = [ 240, 360, 480, 720 ]
30
31 for (const server of servers) {
32 const res = await getVideo(server.url, videoUUID)
33 const videoDetails: VideoDetails = res.body
34
35 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
36
37 const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
38 expect(hlsPlaylist).to.not.be.undefined
39
40 {
41 const res2 = await getPlaylist(hlsPlaylist.playlistUrl)
42
43 const masterPlaylist = res2.text
44
45 expect(masterPlaylist).to.contain('#EXT-X-STREAM-INF:BANDWIDTH=55472,RESOLUTION=640x360,FRAME-RATE=25')
46
47 for (const resolution of resolutions) {
48 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
49 }
50 }
51
52 {
53 for (const resolution of resolutions) {
54 const res2 = await getPlaylist(`http://localhost:9001/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`)
55
56 const subPlaylist = res2.text
57 expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
58 }
59 }
60
61 {
62 const baseUrl = 'http://localhost:9001/static/streaming-playlists/hls'
63
64 for (const resolution of resolutions) {
65 await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist)
66 }
67 }
68 }
69}
70
71describe('Test HLS videos', function () {
72 let servers: ServerInfo[] = []
73 let videoUUID = ''
74
75 before(async function () {
76 this.timeout(120000)
77
78 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: true, hls: { enabled: true } } })
79
80 // Get the access tokens
81 await setAccessTokensToServers(servers)
82
83 // Server 1 and server 2 follow each other
84 await doubleFollow(servers[0], servers[1])
85 })
86
87 it('Should upload a video and transcode it to HLS', async function () {
88 this.timeout(120000)
89
90 {
91 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1', fixture: 'video_short.webm' })
92 videoUUID = res.body.video.uuid
93 }
94
95 await waitJobs(servers)
96
97 await checkHlsPlaylist(servers, videoUUID)
98 })
99
100 it('Should update the video', async function () {
101 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' })
102
103 await waitJobs(servers)
104
105 await checkHlsPlaylist(servers, videoUUID)
106 })
107
108 it('Should delete the video', async function () {
109 await removeVideo(servers[0].url, servers[0].accessToken, videoUUID)
110
111 await waitJobs(servers)
112
113 for (const server of servers) {
114 await getVideo(server.url, videoUUID, 404)
115 }
116 })
117
118 it('Should have the playlists/segment deleted from the disk', async function () {
119 for (const server of servers) {
120 await checkDirectoryIsEmpty(server, 'videos')
121 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'))
122 }
123 })
124
125 it('Should have an empty tmp directory', async function () {
126 for (const server of servers) {
127 await checkTmpIsEmpty(server)
128 }
129 })
130
131 after(async function () {
132 await cleanupTests(servers)
133 })
134})
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index cd4988553..1233ed6eb 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -4,6 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos' 5import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos'
6import { 6import {
7 cleanupTests,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
9 getMyUserInformation, 10 getMyUserInformation,
@@ -14,9 +15,9 @@ import {
14 killallServers, 15 killallServers,
15 ServerInfo, 16 ServerInfo,
16 setAccessTokensToServers 17 setAccessTokensToServers
17} from '../../../../shared/utils' 18} from '../../../../shared/extra-utils'
18import { waitJobs } from '../../../../shared/utils/server/jobs' 19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
19import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../../../shared/utils/videos/video-imports' 20import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../../../shared/extra-utils/videos/video-imports'
20 21
21const expect = chai.expect 22const expect = chai.expect
22 23
@@ -38,6 +39,11 @@ describe('Test video imports', function () {
38 expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ]) 39 expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ])
39 expect(videoHttp.files).to.have.lengthOf(1) 40 expect(videoHttp.files).to.have.lengthOf(1)
40 41
42 const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt)
43 expect(originallyPublishedAt.getDate()).to.equal(14)
44 expect(originallyPublishedAt.getMonth()).to.equal(0)
45 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
46
41 const resMagnet = await getVideo(url, idMagnet) 47 const resMagnet = await getVideo(url, idMagnet)
42 const videoMagnet: VideoDetails = resMagnet.body 48 const videoMagnet: VideoDetails = resMagnet.body
43 const resTorrent = await getVideo(url, idTorrent) 49 const resTorrent = await getVideo(url, idTorrent)
@@ -237,6 +243,6 @@ describe('Test video imports', function () {
237 }) 243 })
238 244
239 after(async function () { 245 after(async function () {
240 killallServers(servers) 246 await cleanupTests(servers)
241 }) 247 })
242}) 248})
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index df1ee2eb9..ad6a4b43f 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -2,30 +2,23 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index'
6import { userLogin } from '../../../../shared/extra-utils/users/login'
7import { createUser } from '../../../../shared/extra-utils/users/users'
8import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
5import { 9import {
6 flushTests, 10 flushAndRunServer,
7 getVideosList,
8 killallServers,
9 ServerInfo,
10 setAccessTokensToServers,
11 uploadVideo
12} from '../../../../shared/utils/index'
13import { userLogin } from '../../../../shared/utils/users/login'
14import { createUser } from '../../../../shared/utils/users/users'
15import { getMyVideos } from '../../../../shared/utils/videos/videos'
16import {
17 getAccountVideos, 11 getAccountVideos,
18 getConfig, 12 getConfig,
19 getCustomConfig, 13 getCustomConfig,
20 getMyUserInformation, 14 getMyUserInformation,
21 getVideoChannelVideos, 15 getVideoChannelVideos,
22 getVideosListWithToken, 16 getVideosListWithToken,
23 runServer,
24 searchVideo, 17 searchVideo,
25 searchVideoWithToken, 18 searchVideoWithToken,
26 updateCustomConfig, 19 updateCustomConfig,
27 updateMyUser 20 updateMyUser
28} from '../../../../shared/utils' 21} from '../../../../shared/extra-utils'
29import { ServerConfig } from '../../../../shared/models' 22import { ServerConfig } from '../../../../shared/models'
30import { CustomConfig } from '../../../../shared/models/server/custom-config.model' 23import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
31import { User } from '../../../../shared/models/users' 24import { User } from '../../../../shared/models/users'
@@ -64,9 +57,7 @@ describe('Test video NSFW policy', function () {
64 57
65 before(async function () { 58 before(async function () {
66 this.timeout(50000) 59 this.timeout(50000)
67 60 server = await flushAndRunServer(1)
68 await flushTests()
69 server = await runServer(1)
70 61
71 // Get the access tokens 62 // Get the access tokens
72 await setAccessTokensToServers([ server ]) 63 await setAccessTokensToServers([ server ])
@@ -144,7 +135,7 @@ describe('Test video NSFW policy', function () {
144 it('Should create a user having the default nsfw policy', async function () { 135 it('Should create a user having the default nsfw policy', async function () {
145 const username = 'user1' 136 const username = 'user1'
146 const password = 'my super password' 137 const password = 'my super password'
147 await createUser(server.url, server.accessToken, username, password) 138 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
148 139
149 userAccessToken = await userLogin(server, { username, password }) 140 userAccessToken = await userLogin(server, { username, password })
150 141
@@ -244,6 +235,6 @@ describe('Test video NSFW policy', function () {
244 }) 235 })
245 236
246 after(async function () { 237 after(async function () {
247 killallServers([ server ]) 238 await cleanupTests([ server ])
248 }) 239 })
249}) 240})
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
new file mode 100644
index 000000000..e4d817ff8
--- /dev/null
+++ b/server/tests/api/videos/video-playlists.ts
@@ -0,0 +1,867 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 addVideoChannel,
7 addVideoInPlaylist,
8 checkPlaylistFilesWereRemoved,
9 cleanupTests,
10 createUser,
11 createVideoPlaylist,
12 deleteVideoChannel,
13 deleteVideoPlaylist,
14 doubleFollow,
15 doVideosExistInMyPlaylist,
16 flushAndRunMultipleServers,
17 getAccountPlaylistsList,
18 getAccountPlaylistsListWithToken,
19 getMyUserInformation,
20 getPlaylistVideos,
21 getVideoChannelPlaylistsList,
22 getVideoPlaylist,
23 getVideoPlaylistPrivacies,
24 getVideoPlaylistsList,
25 getVideoPlaylistWithToken,
26 removeUser,
27 removeVideoFromPlaylist,
28 reorderVideosPlaylist,
29 ServerInfo,
30 setAccessTokensToServers,
31 setDefaultVideoChannel,
32 testImage,
33 unfollow,
34 updateVideoPlaylist,
35 updateVideoPlaylistElement,
36 uploadVideo,
37 uploadVideoAndGetId,
38 userLogin,
39 waitJobs
40} from '../../../../shared/extra-utils'
41import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
42import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model'
43import { Video } from '../../../../shared/models/videos'
44import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
45import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
46import { User } from '../../../../shared/models/users'
47
48const expect = chai.expect
49
50describe('Test video playlists', function () {
51 let servers: ServerInfo[] = []
52
53 let playlistServer2Id1: number
54 let playlistServer2Id2: number
55 let playlistServer2UUID2: number
56
57 let playlistServer1Id: number
58 let playlistServer1UUID: string
59
60 let nsfwVideoServer1: number
61
62 before(async function () {
63 this.timeout(120000)
64
65 servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } })
66
67 // Get the access tokens
68 await setAccessTokensToServers(servers)
69 await setDefaultVideoChannel(servers)
70
71 // Server 1 and server 2 follow each other
72 await doubleFollow(servers[0], servers[1])
73 // Server 1 and server 3 follow each other
74 await doubleFollow(servers[0], servers[2])
75
76 {
77 const serverPromises: Promise<any>[][] = []
78
79 for (const server of servers) {
80 const videoPromises: Promise<any>[] = []
81
82 for (let i = 0; i < 7; i++) {
83 videoPromises.push(
84 uploadVideo(server.url, server.accessToken, { name: `video ${i} server ${server.serverNumber}`, nsfw: false })
85 .then(res => res.body.video)
86 )
87 }
88
89 serverPromises.push(videoPromises)
90 }
91
92 servers[0].videos = await Promise.all(serverPromises[0])
93 servers[1].videos = await Promise.all(serverPromises[1])
94 servers[2].videos = await Promise.all(serverPromises[2])
95 }
96
97 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[ 0 ], videoName: 'NSFW video', nsfw: true })).id
98
99 await waitJobs(servers)
100 })
101
102 it('Should list video playlist privacies', async function () {
103 const res = await getVideoPlaylistPrivacies(servers[0].url)
104
105 const privacies = res.body
106 expect(Object.keys(privacies)).to.have.length.at.least(3)
107
108 expect(privacies[3]).to.equal('Private')
109 })
110
111 it('Should list watch later playlist', async function () {
112 const url = servers[ 0 ].url
113 const accessToken = servers[ 0 ].accessToken
114
115 {
116 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER)
117
118 expect(res.body.total).to.equal(1)
119 expect(res.body.data).to.have.lengthOf(1)
120
121 const playlist: VideoPlaylist = res.body.data[ 0 ]
122 expect(playlist.displayName).to.equal('Watch later')
123 expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER)
124 expect(playlist.type.label).to.equal('Watch later')
125 }
126
127 {
128 const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR)
129
130 expect(res.body.total).to.equal(0)
131 expect(res.body.data).to.have.lengthOf(0)
132 }
133
134 {
135 const res = await getAccountPlaylistsList(url, 'root', 0, 5)
136 expect(res.body.total).to.equal(0)
137 expect(res.body.data).to.have.lengthOf(0)
138 }
139 })
140
141 it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () {
142 this.timeout(30000)
143
144 await createVideoPlaylist({
145 url: servers[0].url,
146 token: servers[0].accessToken,
147 playlistAttrs: {
148 displayName: 'my super playlist',
149 privacy: VideoPlaylistPrivacy.PUBLIC,
150 description: 'my super description',
151 thumbnailfile: 'thumbnail.jpg',
152 videoChannelId: servers[0].videoChannel.id
153 }
154 })
155
156 await waitJobs(servers)
157
158 for (const server of servers) {
159 const res = await getVideoPlaylistsList(server.url, 0, 5)
160 expect(res.body.total).to.equal(1)
161 expect(res.body.data).to.have.lengthOf(1)
162
163 const playlistFromList = res.body.data[0] as VideoPlaylist
164
165 const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid)
166 const playlistFromGet = res2.body
167
168 for (const playlist of [ playlistFromGet, playlistFromList ]) {
169 expect(playlist.id).to.be.a('number')
170 expect(playlist.uuid).to.be.a('string')
171
172 expect(playlist.isLocal).to.equal(server.serverNumber === 1)
173
174 expect(playlist.displayName).to.equal('my super playlist')
175 expect(playlist.description).to.equal('my super description')
176 expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC)
177 expect(playlist.privacy.label).to.equal('Public')
178 expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
179 expect(playlist.type.label).to.equal('Regular')
180
181 expect(playlist.videosLength).to.equal(0)
182
183 expect(playlist.ownerAccount.name).to.equal('root')
184 expect(playlist.ownerAccount.displayName).to.equal('root')
185 expect(playlist.videoChannel.name).to.equal('root_channel')
186 expect(playlist.videoChannel.displayName).to.equal('Main root channel')
187 }
188 }
189 })
190
191 it('Should create a playlist on server 2 and have the playlist on server 1 but not on server 3', async function () {
192 this.timeout(30000)
193
194 {
195 const res = await createVideoPlaylist({
196 url: servers[1].url,
197 token: servers[1].accessToken,
198 playlistAttrs: {
199 displayName: 'playlist 2',
200 privacy: VideoPlaylistPrivacy.PUBLIC,
201 videoChannelId: servers[1].videoChannel.id
202 }
203 })
204 playlistServer2Id1 = res.body.videoPlaylist.id
205 }
206
207 {
208 const res = await createVideoPlaylist({
209 url: servers[ 1 ].url,
210 token: servers[ 1 ].accessToken,
211 playlistAttrs: {
212 displayName: 'playlist 3',
213 privacy: VideoPlaylistPrivacy.PUBLIC,
214 thumbnailfile: 'thumbnail.jpg',
215 videoChannelId: servers[1].videoChannel.id
216 }
217 })
218
219 playlistServer2Id2 = res.body.videoPlaylist.id
220 playlistServer2UUID2 = res.body.videoPlaylist.uuid
221 }
222
223 for (let id of [ playlistServer2Id1, playlistServer2Id2 ]) {
224 await addVideoInPlaylist({
225 url: servers[ 1 ].url,
226 token: servers[ 1 ].accessToken,
227 playlistId: id,
228 elementAttrs: { videoId: servers[ 1 ].videos[ 0 ].id, startTimestamp: 1, stopTimestamp: 2 }
229 })
230 await addVideoInPlaylist({
231 url: servers[ 1 ].url,
232 token: servers[ 1 ].accessToken,
233 playlistId: id,
234 elementAttrs: { videoId: servers[ 1 ].videos[ 1 ].id }
235 })
236 }
237
238 await waitJobs(servers)
239
240 for (const server of [ servers[0], servers[1] ]) {
241 const res = await getVideoPlaylistsList(server.url, 0, 5)
242
243 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
244 expect(playlist2).to.not.be.undefined
245 await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath)
246
247 const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3')
248 expect(playlist3).to.not.be.undefined
249 await testImage(server.url, 'thumbnail', playlist3.thumbnailPath)
250 }
251
252 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
253 expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined
254 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined
255 })
256
257 it('Should have the playlist on server 3 after a new follow', async function () {
258 this.timeout(30000)
259
260 // Server 2 and server 3 follow each other
261 await doubleFollow(servers[1], servers[2])
262
263 const res = await getVideoPlaylistsList(servers[2].url, 0, 5)
264
265 const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2')
266 expect(playlist2).to.not.be.undefined
267 await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath)
268
269 expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined
270 })
271
272 it('Should correctly list the playlists', async function () {
273 this.timeout(30000)
274
275 {
276 const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, 'createdAt')
277
278 expect(res.body.total).to.equal(3)
279
280 const data: VideoPlaylist[] = res.body.data
281 expect(data).to.have.lengthOf(2)
282 expect(data[ 0 ].displayName).to.equal('playlist 2')
283 expect(data[ 1 ].displayName).to.equal('playlist 3')
284 }
285
286 {
287 const res = await getVideoPlaylistsList(servers[ 2 ].url, 1, 2, '-createdAt')
288
289 expect(res.body.total).to.equal(3)
290
291 const data: VideoPlaylist[] = res.body.data
292 expect(data).to.have.lengthOf(2)
293 expect(data[ 0 ].displayName).to.equal('playlist 2')
294 expect(data[ 1 ].displayName).to.equal('my super playlist')
295 }
296 })
297
298 it('Should list video channel playlists', async function () {
299 this.timeout(30000)
300
301 {
302 const res = await getVideoChannelPlaylistsList(servers[ 0 ].url, 'root_channel', 0, 2, '-createdAt')
303
304 expect(res.body.total).to.equal(1)
305
306 const data: VideoPlaylist[] = res.body.data
307 expect(data).to.have.lengthOf(1)
308 expect(data[ 0 ].displayName).to.equal('my super playlist')
309 }
310 })
311
312 it('Should list account playlists', async function () {
313 this.timeout(30000)
314
315 {
316 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, '-createdAt')
317
318 expect(res.body.total).to.equal(2)
319
320 const data: VideoPlaylist[] = res.body.data
321 expect(data).to.have.lengthOf(1)
322 expect(data[ 0 ].displayName).to.equal('playlist 2')
323 }
324
325 {
326 const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 1, 2, 'createdAt')
327
328 expect(res.body.total).to.equal(2)
329
330 const data: VideoPlaylist[] = res.body.data
331 expect(data).to.have.lengthOf(1)
332 expect(data[ 0 ].displayName).to.equal('playlist 3')
333 }
334 })
335
336 it('Should not list unlisted or private playlists', async function () {
337 this.timeout(30000)
338
339 await createVideoPlaylist({
340 url: servers[ 1 ].url,
341 token: servers[ 1 ].accessToken,
342 playlistAttrs: {
343 displayName: 'playlist unlisted',
344 privacy: VideoPlaylistPrivacy.UNLISTED
345 }
346 })
347
348 await createVideoPlaylist({
349 url: servers[ 1 ].url,
350 token: servers[ 1 ].accessToken,
351 playlistAttrs: {
352 displayName: 'playlist private',
353 privacy: VideoPlaylistPrivacy.PRIVATE
354 }
355 })
356
357 await waitJobs(servers)
358
359 for (const server of servers) {
360 const results = [
361 await getAccountPlaylistsList(server.url, 'root@localhost:9002', 0, 5, '-createdAt'),
362 await getVideoPlaylistsList(server.url, 0, 2, '-createdAt')
363 ]
364
365 expect(results[0].body.total).to.equal(2)
366 expect(results[1].body.total).to.equal(3)
367
368 for (const res of results) {
369 const data: VideoPlaylist[] = res.body.data
370 expect(data).to.have.lengthOf(2)
371 expect(data[ 0 ].displayName).to.equal('playlist 3')
372 expect(data[ 1 ].displayName).to.equal('playlist 2')
373 }
374 }
375 })
376
377 it('Should update a playlist', async function () {
378 this.timeout(30000)
379
380 await updateVideoPlaylist({
381 url: servers[1].url,
382 token: servers[1].accessToken,
383 playlistAttrs: {
384 displayName: 'playlist 3 updated',
385 description: 'description updated',
386 privacy: VideoPlaylistPrivacy.UNLISTED,
387 thumbnailfile: 'thumbnail.jpg',
388 videoChannelId: servers[1].videoChannel.id
389 },
390 playlistId: playlistServer2Id2
391 })
392
393 await waitJobs(servers)
394
395 for (const server of servers) {
396 const res = await getVideoPlaylist(server.url, playlistServer2UUID2)
397 const playlist: VideoPlaylist = res.body
398
399 expect(playlist.displayName).to.equal('playlist 3 updated')
400 expect(playlist.description).to.equal('description updated')
401
402 expect(playlist.privacy.id).to.equal(VideoPlaylistPrivacy.UNLISTED)
403 expect(playlist.privacy.label).to.equal('Unlisted')
404
405 expect(playlist.type.id).to.equal(VideoPlaylistType.REGULAR)
406 expect(playlist.type.label).to.equal('Regular')
407
408 expect(playlist.videosLength).to.equal(2)
409
410 expect(playlist.ownerAccount.name).to.equal('root')
411 expect(playlist.ownerAccount.displayName).to.equal('root')
412 expect(playlist.videoChannel.name).to.equal('root_channel')
413 expect(playlist.videoChannel.displayName).to.equal('Main root channel')
414 }
415 })
416
417 it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () {
418 this.timeout(30000)
419
420 const addVideo = (elementAttrs: any) => {
421 return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs })
422 }
423
424 const res = await createVideoPlaylist({
425 url: servers[ 0 ].url,
426 token: servers[ 0 ].accessToken,
427 playlistAttrs: {
428 displayName: 'playlist 4',
429 privacy: VideoPlaylistPrivacy.PUBLIC,
430 videoChannelId: servers[0].videoChannel.id
431 }
432 })
433
434 playlistServer1Id = res.body.videoPlaylist.id
435 playlistServer1UUID = res.body.videoPlaylist.uuid
436
437 await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 })
438 await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 })
439 await addVideo({ videoId: servers[2].videos[2].uuid })
440 await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 })
441 await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 })
442 await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 })
443
444 await waitJobs(servers)
445 })
446
447 it('Should correctly list playlist videos', async function () {
448 this.timeout(30000)
449
450 for (const server of servers) {
451 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
452
453 expect(res.body.total).to.equal(6)
454
455 const videos: Video[] = res.body.data
456 expect(videos).to.have.lengthOf(6)
457
458 expect(videos[0].name).to.equal('video 0 server 1')
459 expect(videos[0].playlistElement.position).to.equal(1)
460 expect(videos[0].playlistElement.startTimestamp).to.equal(15)
461 expect(videos[0].playlistElement.stopTimestamp).to.equal(28)
462
463 expect(videos[1].name).to.equal('video 1 server 3')
464 expect(videos[1].playlistElement.position).to.equal(2)
465 expect(videos[1].playlistElement.startTimestamp).to.equal(35)
466 expect(videos[1].playlistElement.stopTimestamp).to.be.null
467
468 expect(videos[2].name).to.equal('video 2 server 3')
469 expect(videos[2].playlistElement.position).to.equal(3)
470 expect(videos[2].playlistElement.startTimestamp).to.be.null
471 expect(videos[2].playlistElement.stopTimestamp).to.be.null
472
473 expect(videos[3].name).to.equal('video 3 server 1')
474 expect(videos[3].playlistElement.position).to.equal(4)
475 expect(videos[3].playlistElement.startTimestamp).to.be.null
476 expect(videos[3].playlistElement.stopTimestamp).to.equal(35)
477
478 expect(videos[4].name).to.equal('video 4 server 1')
479 expect(videos[4].playlistElement.position).to.equal(5)
480 expect(videos[4].playlistElement.startTimestamp).to.equal(45)
481 expect(videos[4].playlistElement.stopTimestamp).to.equal(60)
482
483 expect(videos[5].name).to.equal('NSFW video')
484 expect(videos[5].playlistElement.position).to.equal(6)
485 expect(videos[5].playlistElement.startTimestamp).to.equal(5)
486 expect(videos[5].playlistElement.stopTimestamp).to.be.null
487
488 const res2 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10, { nsfw: false })
489 expect(res2.body.total).to.equal(5)
490 expect(res2.body.data.find(v => v.name === 'NSFW video')).to.be.undefined
491
492 const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2)
493 expect(res3.body.data).to.have.lengthOf(2)
494 }
495 })
496
497 it('Should reorder the playlist', async function () {
498 this.timeout(30000)
499
500 {
501 await reorderVideosPlaylist({
502 url: servers[ 0 ].url,
503 token: servers[ 0 ].accessToken,
504 playlistId: playlistServer1Id,
505 elementAttrs: {
506 startPosition: 2,
507 insertAfterPosition: 3
508 }
509 })
510
511 await waitJobs(servers)
512
513 for (const server of servers) {
514 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
515 const names = res.body.data.map(v => v.name)
516
517 expect(names).to.deep.equal([
518 'video 0 server 1',
519 'video 2 server 3',
520 'video 1 server 3',
521 'video 3 server 1',
522 'video 4 server 1',
523 'NSFW video'
524 ])
525 }
526 }
527
528 {
529 await reorderVideosPlaylist({
530 url: servers[0].url,
531 token: servers[0].accessToken,
532 playlistId: playlistServer1Id,
533 elementAttrs: {
534 startPosition: 1,
535 reorderLength: 3,
536 insertAfterPosition: 4
537 }
538 })
539
540 await waitJobs(servers)
541
542 for (const server of servers) {
543 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
544 const names = res.body.data.map(v => v.name)
545
546 expect(names).to.deep.equal([
547 'video 3 server 1',
548 'video 0 server 1',
549 'video 2 server 3',
550 'video 1 server 3',
551 'video 4 server 1',
552 'NSFW video'
553 ])
554 }
555 }
556
557 {
558 await reorderVideosPlaylist({
559 url: servers[0].url,
560 token: servers[0].accessToken,
561 playlistId: playlistServer1Id,
562 elementAttrs: {
563 startPosition: 6,
564 insertAfterPosition: 3
565 }
566 })
567
568 await waitJobs(servers)
569
570 for (const server of servers) {
571 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
572 const videos: Video[] = res.body.data
573
574 const names = videos.map(v => v.name)
575
576 expect(names).to.deep.equal([
577 'video 3 server 1',
578 'video 0 server 1',
579 'video 2 server 3',
580 'NSFW video',
581 'video 1 server 3',
582 'video 4 server 1'
583 ])
584
585 for (let i = 1; i <= videos.length; i++) {
586 expect(videos[i - 1].playlistElement.position).to.equal(i)
587 }
588 }
589 }
590 })
591
592 it('Should update startTimestamp/endTimestamp of some elements', async function () {
593 this.timeout(30000)
594
595 await updateVideoPlaylistElement({
596 url: servers[0].url,
597 token: servers[0].accessToken,
598 playlistId: playlistServer1Id,
599 videoId: servers[0].videos[3].uuid,
600 elementAttrs: {
601 startTimestamp: 1
602 }
603 })
604
605 await updateVideoPlaylistElement({
606 url: servers[0].url,
607 token: servers[0].accessToken,
608 playlistId: playlistServer1Id,
609 videoId: servers[0].videos[4].uuid,
610 elementAttrs: {
611 stopTimestamp: null
612 }
613 })
614
615 await waitJobs(servers)
616
617 for (const server of servers) {
618 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
619 const videos: Video[] = res.body.data
620
621 expect(videos[0].name).to.equal('video 3 server 1')
622 expect(videos[0].playlistElement.position).to.equal(1)
623 expect(videos[0].playlistElement.startTimestamp).to.equal(1)
624 expect(videos[0].playlistElement.stopTimestamp).to.equal(35)
625
626 expect(videos[5].name).to.equal('video 4 server 1')
627 expect(videos[5].playlistElement.position).to.equal(6)
628 expect(videos[5].playlistElement.startTimestamp).to.equal(45)
629 expect(videos[5].playlistElement.stopTimestamp).to.be.null
630 }
631 })
632
633 it('Should check videos existence in my playlist', async function () {
634 const videoIds = [
635 servers[0].videos[0].id,
636 42000,
637 servers[0].videos[3].id,
638 43000,
639 servers[0].videos[4].id
640 ]
641 const res = await doVideosExistInMyPlaylist(servers[ 0 ].url, servers[ 0 ].accessToken, videoIds)
642 const obj = res.body as VideoExistInPlaylist
643
644 {
645 const elem = obj[servers[0].videos[0].id]
646 expect(elem).to.have.lengthOf(1)
647 expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
648 expect(elem[ 0 ].startTimestamp).to.equal(15)
649 expect(elem[ 0 ].stopTimestamp).to.equal(28)
650 }
651
652 {
653 const elem = obj[servers[0].videos[3].id]
654 expect(elem).to.have.lengthOf(1)
655 expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
656 expect(elem[ 0 ].startTimestamp).to.equal(1)
657 expect(elem[ 0 ].stopTimestamp).to.equal(35)
658 }
659
660 {
661 const elem = obj[servers[0].videos[4].id]
662 expect(elem).to.have.lengthOf(1)
663 expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id)
664 expect(elem[ 0 ].startTimestamp).to.equal(45)
665 expect(elem[ 0 ].stopTimestamp).to.equal(null)
666 }
667
668 expect(obj[42000]).to.have.lengthOf(0)
669 expect(obj[43000]).to.have.lengthOf(0)
670 })
671
672 it('Should automatically update updatedAt field of playlists', async function () {
673 const server = servers[1]
674 const videoId = servers[1].videos[5].id
675
676 async function getPlaylistNames () {
677 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt')
678
679 return (res.body.data as VideoPlaylist[]).map(p => p.displayName)
680 }
681
682 const elementAttrs = { videoId }
683 await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs })
684 await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs })
685
686 const names1 = await getPlaylistNames()
687 expect(names1[0]).to.equal('playlist 3 updated')
688 expect(names1[1]).to.equal('playlist 2')
689
690 await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, videoId })
691
692 const names2 = await getPlaylistNames()
693 expect(names2[0]).to.equal('playlist 2')
694 expect(names2[1]).to.equal('playlist 3 updated')
695
696 await removeVideoFromPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, videoId })
697
698 const names3 = await getPlaylistNames()
699 expect(names3[0]).to.equal('playlist 3 updated')
700 expect(names3[1]).to.equal('playlist 2')
701 })
702
703 it('Should delete some elements', async function () {
704 this.timeout(30000)
705
706 await removeVideoFromPlaylist({
707 url: servers[0].url,
708 token: servers[0].accessToken,
709 playlistId: playlistServer1Id,
710 videoId: servers[0].videos[3].uuid
711 })
712
713 await removeVideoFromPlaylist({
714 url: servers[0].url,
715 token: servers[0].accessToken,
716 playlistId: playlistServer1Id,
717 videoId: nsfwVideoServer1
718 })
719
720 await waitJobs(servers)
721
722 for (const server of servers) {
723 const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10)
724
725 expect(res.body.total).to.equal(4)
726
727 const videos: Video[] = res.body.data
728 expect(videos).to.have.lengthOf(4)
729
730 expect(videos[ 0 ].name).to.equal('video 0 server 1')
731 expect(videos[ 0 ].playlistElement.position).to.equal(1)
732
733 expect(videos[ 1 ].name).to.equal('video 2 server 3')
734 expect(videos[ 1 ].playlistElement.position).to.equal(2)
735
736 expect(videos[ 2 ].name).to.equal('video 1 server 3')
737 expect(videos[ 2 ].playlistElement.position).to.equal(3)
738
739 expect(videos[ 3 ].name).to.equal('video 4 server 1')
740 expect(videos[ 3 ].playlistElement.position).to.equal(4)
741 }
742 })
743
744 it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () {
745 this.timeout(30000)
746
747 await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id)
748
749 await waitJobs(servers)
750
751 for (const server of servers) {
752 await getVideoPlaylist(server.url, playlistServer1UUID, 404)
753 }
754 })
755
756 it('Should have deleted the thumbnail on server 1, 2 and 3', async function () {
757 this.timeout(30000)
758
759 for (const server of servers) {
760 await checkPlaylistFilesWereRemoved(playlistServer1UUID, server.serverNumber)
761 }
762 })
763
764 it('Should unfollow servers 1 and 2 and hide their playlists', async function () {
765 this.timeout(30000)
766
767 const finder = data => data.find(p => p.displayName === 'my super playlist')
768
769 {
770 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
771 expect(res.body.total).to.equal(2)
772 expect(finder(res.body.data)).to.not.be.undefined
773 }
774
775 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
776
777 {
778 const res = await getVideoPlaylistsList(servers[ 2 ].url, 0, 5)
779 expect(res.body.total).to.equal(1)
780
781 expect(finder(res.body.data)).to.be.undefined
782 }
783 })
784
785 it('Should delete a channel and put the associated playlist in private mode', async function () {
786 this.timeout(30000)
787
788 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' })
789 const videoChannelId = res.body.videoChannel.id
790
791 const res2 = await createVideoPlaylist({
792 url: servers[0].url,
793 token: servers[0].accessToken,
794 playlistAttrs: {
795 displayName: 'channel playlist',
796 privacy: VideoPlaylistPrivacy.PUBLIC,
797 videoChannelId
798 }
799 })
800 const videoPlaylistUUID = res2.body.videoPlaylist.uuid
801
802 await waitJobs(servers)
803
804 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel')
805
806 await waitJobs(servers)
807
808 const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID)
809 expect(res3.body.displayName).to.equal('channel playlist')
810 expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE)
811
812 await getVideoPlaylist(servers[1].url, videoPlaylistUUID, 404)
813 })
814
815 it('Should delete an account and delete its playlists', async function () {
816 this.timeout(30000)
817
818 const user = { username: 'user_1', password: 'password' }
819 const res = await createUser({
820 url: servers[ 0 ].url,
821 accessToken: servers[ 0 ].accessToken,
822 username: user.username,
823 password: user.password
824 })
825
826 const userId = res.body.user.id
827 const userAccessToken = await userLogin(servers[0], user)
828
829 const resChannel = await getMyUserInformation(servers[0].url, userAccessToken)
830 const userChannel = (resChannel.body as User).videoChannels[0]
831
832 await createVideoPlaylist({
833 url: servers[0].url,
834 token: userAccessToken,
835 playlistAttrs: {
836 displayName: 'playlist to be deleted',
837 privacy: VideoPlaylistPrivacy.PUBLIC,
838 videoChannelId: userChannel.id
839 }
840 })
841
842 await waitJobs(servers)
843
844 const finder = data => data.find(p => p.displayName === 'playlist to be deleted')
845
846 {
847 for (const server of [ servers[0], servers[1] ]) {
848 const res = await getVideoPlaylistsList(server.url, 0, 15)
849 expect(finder(res.body.data)).to.not.be.undefined
850 }
851 }
852
853 await removeUser(servers[0].url, userId, servers[0].accessToken)
854 await waitJobs(servers)
855
856 {
857 for (const server of [ servers[0], servers[1] ]) {
858 const res = await getVideoPlaylistsList(server.url, 0, 15)
859 expect(finder(res.body.data)).to.be.undefined
860 }
861 }
862 })
863
864 after(async function () {
865 await cleanupTests(servers)
866 })
867})
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index 0b4e66369..ef1cf0f07 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -4,18 +4,19 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 5import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
6import { 6import {
7 cleanupTests,
7 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
8 getVideosList, 9 getVideosList,
9 killallServers, 10 killallServers,
10 ServerInfo, 11 ServerInfo,
11 setAccessTokensToServers, 12 setAccessTokensToServers,
12 uploadVideo 13 uploadVideo
13} from '../../../../shared/utils/index' 14} from '../../../../shared/extra-utils/index'
14import { doubleFollow } from '../../../../shared/utils/server/follows' 15import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
15import { userLogin } from '../../../../shared/utils/users/login' 16import { userLogin } from '../../../../shared/extra-utils/users/login'
16import { createUser } from '../../../../shared/utils/users/users' 17import { createUser } from '../../../../shared/extra-utils/users/users'
17import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/utils/videos/videos' 18import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
18import { waitJobs } from '../../../../shared/utils/server/jobs' 19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
19 20
20const expect = chai.expect 21const expect = chai.expect
21 22
@@ -78,7 +79,7 @@ describe('Test video privacy', function () {
78 username: 'hello', 79 username: 'hello',
79 password: 'super password' 80 password: 'super password'
80 } 81 }
81 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) 82 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
82 83
83 const token = await userLogin(servers[0], user) 84 const token = await userLogin(servers[0], user)
84 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403) 85 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
@@ -153,6 +154,6 @@ describe('Test video privacy', function () {
153 }) 154 })
154 155
155 after(async function () { 156 after(async function () {
156 killallServers(servers) 157 await cleanupTests(servers)
157 }) 158 })
158}) 159})
diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts
index 632c4244c..64f657780 100644
--- a/server/tests/api/videos/video-schedule-update.ts
+++ b/server/tests/api/videos/video-schedule-update.ts
@@ -4,6 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoPrivacy } from '../../../../shared/models/videos' 5import { VideoPrivacy } from '../../../../shared/models/videos'
6import { 6import {
7 cleanupTests,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
9 getMyVideos, 10 getMyVideos,
@@ -15,8 +16,8 @@ import {
15 updateVideo, 16 updateVideo,
16 uploadVideo, 17 uploadVideo,
17 wait 18 wait
18} from '../../../../shared/utils' 19} from '../../../../shared/extra-utils'
19import { waitJobs } from '../../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20 21
21const expect = chai.expect 22const expect = chai.expect
22 23
@@ -166,6 +167,6 @@ describe('Test video update scheduler', function () {
166 }) 167 })
167 168
168 after(async function () { 169 after(async function () {
169 killallServers(servers) 170 await cleanupTests(servers)
170 }) 171 })
171}) 172})
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index eefd32ef8..3cd43e99b 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -6,7 +6,7 @@ import { omit } from 'lodash'
6import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' 6import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos'
7import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 7import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
8import { 8import {
9 buildAbsoluteFixturePath, 9 buildAbsoluteFixturePath, cleanupTests,
10 doubleFollow, 10 doubleFollow,
11 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
12 generateHighBitrateVideo, 12 generateHighBitrateVideo,
@@ -19,9 +19,9 @@ import {
19 setAccessTokensToServers, 19 setAccessTokensToServers,
20 uploadVideo, 20 uploadVideo,
21 webtorrentAdd 21 webtorrentAdd
22} from '../../../../shared/utils' 22} from '../../../../shared/extra-utils'
23import { extname, join } from 'path' 23import { extname, join } from 'path'
24import { waitJobs } from '../../../../shared/utils/server/jobs' 24import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
25import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' 25import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
26 26
27const expect = chai.expect 27const expect = chai.expect
@@ -350,6 +350,6 @@ describe('Test video transcoding', function () {
350 }) 350 })
351 351
352 after(async function () { 352 after(async function () {
353 killallServers(servers) 353 await cleanupTests(servers)
354 }) 354 })
355}) 355})
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
index 59e37ad86..e1e65260f 100644
--- a/server/tests/api/videos/videos-filter.ts
+++ b/server/tests/api/videos/videos-filter.ts
@@ -3,6 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -13,7 +14,7 @@ import {
13 setAccessTokensToServers, 14 setAccessTokensToServers,
14 uploadVideo, 15 uploadVideo,
15 userLogin 16 userLogin
16} from '../../../../shared/utils' 17} from '../../../../shared/extra-utils'
17import { Video, VideoPrivacy } from '../../../../shared/models/videos' 18import { Video, VideoPrivacy } from '../../../../shared/models/videos'
18import { UserRole } from '../../../../shared/models/users' 19import { UserRole } from '../../../../shared/models/users'
19 20
@@ -55,8 +56,6 @@ describe('Test videos filter validator', function () {
55 before(async function () { 56 before(async function () {
56 this.timeout(120000) 57 this.timeout(120000)
57 58
58 await flushTests()
59
60 servers = await flushAndRunMultipleServers(2) 59 servers = await flushAndRunMultipleServers(2)
61 60
62 await setAccessTokensToServers(servers) 61 await setAccessTokensToServers(servers)
@@ -64,13 +63,15 @@ describe('Test videos filter validator', function () {
64 for (const server of servers) { 63 for (const server of servers) {
65 const moderator = { username: 'moderator', password: 'my super password' } 64 const moderator = { username: 'moderator', password: 'my super password' }
66 await createUser( 65 await createUser(
67 server.url, 66 {
68 server.accessToken, 67 url: server.url,
69 moderator.username, 68 accessToken: server.accessToken,
70 moderator.password, 69 username: moderator.username,
71 undefined, 70 password: moderator.password,
72 undefined, 71 videoQuota: undefined,
73 UserRole.MODERATOR 72 videoQuotaDaily: undefined,
73 role: UserRole.MODERATOR
74 }
74 ) 75 )
75 server['moderatorAccessToken'] = await userLogin(server, moderator) 76 server['moderatorAccessToken'] = await userLogin(server, moderator)
76 77
@@ -120,11 +121,6 @@ describe('Test videos filter validator', function () {
120 }) 121 })
121 122
122 after(async function () { 123 after(async function () {
123 killallServers(servers) 124 await cleanupTests(servers)
124
125 // Keep the logs if the test failed
126 if (this['ok']) {
127 await flushTests()
128 }
129 }) 125 })
130}) 126})
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index f654a422b..c7e55c1ab 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -3,21 +3,23 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 flushTests, 8 flushAndRunServer,
8 getVideosListWithToken, 9 getVideosListWithToken,
9 getVideoWithToken, 10 getVideoWithToken,
10 killallServers, 11 killallServers,
11 runServer, 12 reRunServer,
12 searchVideoWithToken, 13 searchVideoWithToken,
13 ServerInfo, 14 ServerInfo,
14 setAccessTokensToServers, 15 setAccessTokensToServers,
15 updateMyUser, 16 updateMyUser,
16 uploadVideo, 17 uploadVideo,
17 userLogin 18 userLogin,
18} from '../../../../shared/utils' 19 wait
20} from '../../../../shared/extra-utils'
19import { Video, VideoDetails } from '../../../../shared/models/videos' 21import { Video, VideoDetails } from '../../../../shared/models/videos'
20import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/utils/videos/video-history' 22import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history'
21 23
22const expect = chai.expect 24const expect = chai.expect
23 25
@@ -32,9 +34,7 @@ describe('Test videos history', function () {
32 before(async function () { 34 before(async function () {
33 this.timeout(30000) 35 this.timeout(30000)
34 36
35 await flushTests() 37 server = await flushAndRunServer(1)
36
37 server = await runServer(1)
38 38
39 await setAccessTokensToServers([ server ]) 39 await setAccessTokensToServers([ server ])
40 40
@@ -57,7 +57,7 @@ describe('Test videos history', function () {
57 username: 'user_1', 57 username: 'user_1',
58 password: 'super password' 58 password: 'super password'
59 } 59 }
60 await createUser(server.url, server.accessToken, user.username, user.password) 60 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
61 userAccessToken = await userLogin(server, user) 61 userAccessToken = await userLogin(server, user)
62 }) 62 })
63 63
@@ -192,12 +192,36 @@ describe('Test videos history', function () {
192 expect(videos[1].name).to.equal('video 3') 192 expect(videos[1].name).to.equal('video 3')
193 }) 193 })
194 194
195 after(async function () { 195 it('Should not clean old history', async function () {
196 this.timeout(50000)
197
196 killallServers([ server ]) 198 killallServers([ server ])
197 199
198 // Keep the logs if the test failed 200 await reRunServer(server, { history: { videos: { max_age: '10 days' } } })
199 if (this['ok']) { 201
200 await flushTests() 202 await wait(6000)
201 } 203
204 // Should still have history
205
206 const res = await listMyVideosHistory(server.url, server.accessToken)
207
208 expect(res.body.total).to.equal(2)
209 })
210
211 it('Should clean old history', async function () {
212 this.timeout(50000)
213
214 killallServers([ server ])
215
216 await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } })
217
218 await wait(6000)
219
220 const res = await listMyVideosHistory(server.url, server.accessToken)
221 expect(res.body.total).to.equal(0)
222 })
223
224 after(async function () {
225 await cleanupTests([ server ])
202 }) 226 })
203}) 227})
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts
index 7221bcae6..975a5c87a 100644
--- a/server/tests/api/videos/videos-overview.ts
+++ b/server/tests/api/videos/videos-overview.ts
@@ -2,8 +2,8 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/utils' 5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils'
6import { getVideosOverview } from '../../../../shared/utils/overviews/overviews' 6import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews'
7import { VideosOverview } from '../../../../shared/models/overviews' 7import { VideosOverview } from '../../../../shared/models/overviews'
8 8
9const expect = chai.expect 9const expect = chai.expect
@@ -14,9 +14,7 @@ describe('Test a videos overview', function () {
14 before(async function () { 14 before(async function () {
15 this.timeout(30000) 15 this.timeout(30000)
16 16
17 await flushTests() 17 server = await flushAndRunServer(1)
18
19 server = await runServer(1)
20 18
21 await setAccessTokensToServers([ server ]) 19 await setAccessTokensToServers([ server ])
22 }) 20 })
@@ -90,11 +88,6 @@ describe('Test a videos overview', function () {
90 }) 88 })
91 89
92 after(async function () { 90 after(async function () {
93 killallServers([ server ]) 91 await cleanupTests([ server ])
94
95 // Keep the logs if the test failed
96 if (this['ok']) {
97 await flushTests()
98 }
99 }) 92 })
100}) 93})
diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts
new file mode 100644
index 000000000..c21d46d56
--- /dev/null
+++ b/server/tests/api/videos/videos-views-cleaner.ts
@@ -0,0 +1,106 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 flushAndRunMultipleServers,
7 flushTests,
8 killallServers,
9 reRunServer,
10 flushAndRunServer,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo, uploadVideoAndGetId, viewVideo, wait, countVideoViewsOf, doubleFollow, waitJobs, cleanupTests
14} from '../../../../shared/extra-utils'
15import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews'
16import { VideosOverview } from '../../../../shared/models/overviews'
17import { listMyVideosHistory } from '../../../../shared/extra-utils/videos/video-history'
18
19const expect = chai.expect
20
21describe('Test video views cleaner', function () {
22 let servers: ServerInfo[]
23
24 let videoIdServer1: string
25 let videoIdServer2: string
26
27 before(async function () {
28 this.timeout(50000)
29
30 servers = await flushAndRunMultipleServers(2)
31 await setAccessTokensToServers(servers)
32
33 await doubleFollow(servers[0], servers[1])
34
35 videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid
36 videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid
37
38 await waitJobs(servers)
39
40 await viewVideo(servers[0].url, videoIdServer1)
41 await viewVideo(servers[1].url, videoIdServer1)
42 await viewVideo(servers[0].url, videoIdServer2)
43 await viewVideo(servers[1].url, videoIdServer2)
44
45 await waitJobs(servers)
46 })
47
48 it('Should not clean old video views', async function () {
49 this.timeout(50000)
50
51 killallServers([ servers[0] ])
52
53 await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } })
54
55 await wait(6000)
56
57 // Should still have views
58
59 {
60 for (const server of servers) {
61 const total = await countVideoViewsOf(server.serverNumber, videoIdServer1)
62 expect(total).to.equal(2)
63 }
64 }
65
66 {
67 for (const server of servers) {
68 const total = await countVideoViewsOf(server.serverNumber, videoIdServer2)
69 expect(total).to.equal(2)
70 }
71 }
72 })
73
74 it('Should clean old video views', async function () {
75 this.timeout(50000)
76
77 this.timeout(50000)
78
79 killallServers([ servers[0] ])
80
81 await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } })
82
83 await wait(6000)
84
85 // Should still have views
86
87 {
88 for (const server of servers) {
89 const total = await countVideoViewsOf(server.serverNumber, videoIdServer1)
90 expect(total).to.equal(2)
91 }
92 }
93
94 {
95 const totalServer1 = await countVideoViewsOf(servers[0].serverNumber, videoIdServer2)
96 expect(totalServer1).to.equal(0)
97
98 const totalServer2 = await countVideoViewsOf(servers[1].serverNumber, videoIdServer2)
99 expect(totalServer2).to.equal(2)
100 }
101 })
102
103 after(async function () {
104 await cleanupTests(servers)
105 })
106})
diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts
index 4acda47b1..0d378c1aa 100644
--- a/server/tests/cli/create-import-video-file-job.ts
+++ b/server/tests/cli/create-import-video-file-job.ts
@@ -4,6 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails, VideoFile } from '../../../shared/models/videos' 5import { VideoDetails, VideoFile } from '../../../shared/models/videos'
6import { 6import {
7 cleanupTests,
7 doubleFollow, 8 doubleFollow,
8 execCLI, 9 execCLI,
9 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -15,8 +16,8 @@ import {
15 ServerInfo, 16 ServerInfo,
16 setAccessTokensToServers, 17 setAccessTokensToServers,
17 uploadVideo 18 uploadVideo
18} from '../../../shared/utils' 19} from '../../../shared/extra-utils'
19import { waitJobs } from '../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../shared/extra-utils/server/jobs'
20 21
21const expect = chai.expect 22const expect = chai.expect
22 23
@@ -39,7 +40,6 @@ describe('Test create import video jobs', function () {
39 40
40 before(async function () { 41 before(async function () {
41 this.timeout(90000) 42 this.timeout(90000)
42 await flushTests()
43 43
44 // Run server 2 to have transcoding enabled 44 // Run server 2 to have transcoding enabled
45 servers = await flushAndRunMultipleServers(2) 45 servers = await flushAndRunMultipleServers(2)
@@ -132,6 +132,6 @@ describe('Test create import video jobs', function () {
132 }) 132 })
133 133
134 after(async function () { 134 after(async function () {
135 killallServers(servers) 135 await cleanupTests(servers)
136 }) 136 })
137}) 137})
diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts
index 50be5fa19..1c0e10066 100644
--- a/server/tests/cli/create-transcoding-job.ts
+++ b/server/tests/cli/create-transcoding-job.ts
@@ -4,6 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails } from '../../../shared/models/videos' 5import { VideoDetails } from '../../../shared/models/videos'
6import { 6import {
7 cleanupTests,
7 doubleFollow, 8 doubleFollow,
8 execCLI, 9 execCLI,
9 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -15,8 +16,8 @@ import {
15 ServerInfo, 16 ServerInfo,
16 setAccessTokensToServers, 17 setAccessTokensToServers,
17 uploadVideo, wait 18 uploadVideo, wait
18} from '../../../shared/utils' 19} from '../../../shared/extra-utils'
19import { waitJobs } from '../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../shared/extra-utils/server/jobs'
20 21
21const expect = chai.expect 22const expect = chai.expect
22 23
@@ -28,8 +29,6 @@ describe('Test create transcoding jobs', function () {
28 before(async function () { 29 before(async function () {
29 this.timeout(60000) 30 this.timeout(60000)
30 31
31 await flushTests()
32
33 // Run server 2 to have transcoding enabled 32 // Run server 2 to have transcoding enabled
34 servers = await flushAndRunMultipleServers(2) 33 servers = await flushAndRunMultipleServers(2)
35 await setAccessTokensToServers(servers) 34 await setAccessTokensToServers(servers)
@@ -127,6 +126,6 @@ describe('Test create transcoding jobs', function () {
127 }) 126 })
128 127
129 after(async function () { 128 after(async function () {
130 killallServers(servers) 129 await cleanupTests(servers)
131 }) 130 })
132}) 131})
diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts
index 6f6bc25a6..5e12c0089 100644
--- a/server/tests/cli/optimize-old-videos.ts
+++ b/server/tests/cli/optimize-old-videos.ts
@@ -4,6 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos' 5import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos'
6import { 6import {
7 cleanupTests,
7 doubleFollow, 8 doubleFollow,
8 execCLI, 9 execCLI,
9 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -15,10 +16,10 @@ import {
15 ServerInfo, 16 ServerInfo,
16 setAccessTokensToServers, 17 setAccessTokensToServers,
17 uploadVideo, viewVideo, wait 18 uploadVideo, viewVideo, wait
18} from '../../../shared/utils' 19} from '../../../shared/extra-utils'
19import { waitJobs } from '../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../shared/extra-utils/server/jobs'
20import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffmpeg-utils' 21import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffmpeg-utils'
21import { VIDEO_TRANSCODING_FPS } from '../../initializers' 22import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
22import { join } from 'path' 23import { join } from 'path'
23 24
24const expect = chai.expect 25const expect = chai.expect
@@ -31,8 +32,6 @@ describe('Test optimize old videos', function () {
31 before(async function () { 32 before(async function () {
32 this.timeout(200000) 33 this.timeout(200000)
33 34
34 await flushTests()
35
36 // Run server 2 to have transcoding enabled 35 // Run server 2 to have transcoding enabled
37 servers = await flushAndRunMultipleServers(2) 36 servers = await flushAndRunMultipleServers(2)
38 await setAccessTokensToServers(servers) 37 await setAccessTokensToServers(servers)
@@ -115,6 +114,6 @@ describe('Test optimize old videos', function () {
115 }) 114 })
116 115
117 after(async function () { 116 after(async function () {
118 killallServers(servers) 117 await cleanupTests(servers)
119 }) 118 })
120}) 119})
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index e2836d0c3..80bbc98d5 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -8,10 +8,10 @@ import {
8 flushTests, 8 flushTests,
9 getEnvCli, 9 getEnvCli,
10 killallServers, 10 killallServers,
11 runServer, 11 flushAndRunServer,
12 ServerInfo, 12 ServerInfo,
13 setAccessTokensToServers 13 setAccessTokensToServers, cleanupTests
14} from '../../../shared/utils' 14} from '../../../shared/extra-utils'
15 15
16describe('Test CLI wrapper', function () { 16describe('Test CLI wrapper', function () {
17 let server: ServerInfo 17 let server: ServerInfo
@@ -19,12 +19,10 @@ describe('Test CLI wrapper', function () {
19 19
20 before(async function () { 20 before(async function () {
21 this.timeout(30000) 21 this.timeout(30000)
22 22 server = await flushAndRunServer(1)
23 await flushTests()
24 server = await runServer(1)
25 await setAccessTokensToServers([ server ]) 23 await setAccessTokensToServers([ server ])
26 24
27 await createUser(server.url, server.accessToken, 'user_1', 'super password') 25 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' })
28 }) 26 })
29 27
30 it('Should display no selected instance', async function () { 28 it('Should display no selected instance', async function () {
@@ -48,6 +46,6 @@ describe('Test CLI wrapper', function () {
48 46
49 await execCLI(cmd + ` auth del ${server.url}`) 47 await execCLI(cmd + ` auth del ${server.url}`)
50 48
51 killallServers([ server ]) 49 await cleanupTests([ server ])
52 }) 50 })
53}) 51})
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts
index 1b65f7e39..6abb6738f 100644
--- a/server/tests/cli/reset-password.ts
+++ b/server/tests/cli/reset-password.ts
@@ -1,28 +1,25 @@
1import 'mocha' 1import 'mocha'
2 2
3import { 3import {
4 cleanupTests,
4 createUser, 5 createUser,
5 execCLI, 6 execCLI,
6 flushTests, 7 flushAndRunServer,
7 getEnvCli, 8 getEnvCli,
8 killallServers,
9 login, 9 login,
10 runServer,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers 11 setAccessTokensToServers
13} from '../../../shared/utils' 12} from '../../../shared/extra-utils'
14 13
15describe('Test reset password scripts', function () { 14describe('Test reset password scripts', function () {
16 let server: ServerInfo 15 let server: ServerInfo
17 16
18 before(async function () { 17 before(async function () {
19 this.timeout(30000) 18 this.timeout(30000)
20 19 server = await flushAndRunServer(1)
21 await flushTests()
22 server = await runServer(1)
23 await setAccessTokensToServers([ server ]) 20 await setAccessTokensToServers([ server ])
24 21
25 await createUser(server.url, server.accessToken, 'user_1', 'super password') 22 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' })
26 }) 23 })
27 24
28 it('Should change the user password from CLI', async function () { 25 it('Should change the user password from CLI', async function () {
@@ -35,6 +32,6 @@ describe('Test reset password scripts', function () {
35 }) 32 })
36 33
37 after(async function () { 34 after(async function () {
38 killallServers([ server ]) 35 await cleanupTests([ server ])
39 }) 36 })
40}) 37})
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts
index 811ea6a9f..55c43b32f 100644
--- a/server/tests/cli/update-host.ts
+++ b/server/tests/cli/update-host.ts
@@ -3,26 +3,26 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails } from '../../../shared/models/videos' 5import { VideoDetails } from '../../../shared/models/videos'
6import { waitJobs } from '../../../shared/utils/server/jobs' 6import { waitJobs } from '../../../shared/extra-utils/server/jobs'
7import { addVideoCommentThread } from '../../../shared/utils/videos/video-comments' 7import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
8import { 8import {
9 addVideoChannel, 9 addVideoChannel,
10 cleanupTests,
10 createUser, 11 createUser,
11 execCLI, 12 execCLI,
12 flushTests, 13 flushAndRunServer,
13 getEnvCli, 14 getEnvCli,
14 getVideo, 15 getVideo,
15 getVideoChannelsList, 16 getVideoChannelsList,
16 getVideosList, 17 getVideosList,
17 killallServers, 18 killallServers,
18 makeActivityPubGetRequest, 19 makeActivityPubGetRequest,
19 parseTorrentVideo, 20 parseTorrentVideo, reRunServer,
20 runServer,
21 ServerInfo, 21 ServerInfo,
22 setAccessTokensToServers, 22 setAccessTokensToServers,
23 uploadVideo 23 uploadVideo
24} from '../../../shared/utils' 24} from '../../../shared/extra-utils'
25import { getAccountsList } from '../../../shared/utils/users/accounts' 25import { getAccountsList } from '../../../shared/extra-utils/users/accounts'
26 26
27const expect = chai.expect 27const expect = chai.expect
28 28
@@ -32,15 +32,13 @@ describe('Test update host scripts', function () {
32 before(async function () { 32 before(async function () {
33 this.timeout(60000) 33 this.timeout(60000)
34 34
35 await flushTests()
36
37 const overrideConfig = { 35 const overrideConfig = {
38 webserver: { 36 webserver: {
39 port: 9256 37 port: 9256
40 } 38 }
41 } 39 }
42 // Run server 2 to have transcoding enabled 40 // Run server 2 to have transcoding enabled
43 server = await runServer(2, overrideConfig) 41 server = await flushAndRunServer(2, overrideConfig)
44 await setAccessTokensToServers([ server ]) 42 await setAccessTokensToServers([ server ])
45 43
46 // Upload two videos for our needs 44 // Upload two videos for our needs
@@ -50,7 +48,7 @@ describe('Test update host scripts', function () {
50 await uploadVideo(server.url, server.accessToken, videoAttributes) 48 await uploadVideo(server.url, server.accessToken, videoAttributes)
51 49
52 // Create a user 50 // Create a user
53 await createUser(server.url, server.accessToken, 'toto', 'coucou') 51 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
54 52
55 // Create channel 53 // Create channel
56 const videoChannel = { 54 const videoChannel = {
@@ -72,7 +70,7 @@ describe('Test update host scripts', function () {
72 70
73 killallServers([ server ]) 71 killallServers([ server ])
74 // Run server with standard configuration 72 // Run server with standard configuration
75 server = await runServer(2) 73 await reRunServer(server)
76 74
77 const env = getEnvCli(server) 75 const env = getEnvCli(server)
78 await execCLI(`${env} npm run update-host`) 76 await execCLI(`${env} npm run update-host`)
@@ -86,6 +84,13 @@ describe('Test update host scripts', function () {
86 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) 84 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
87 85
88 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid) 86 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
87
88 const res = await getVideo(server.url, video.uuid)
89 const videoDetails: VideoDetails = res.body
90
91 expect(videoDetails.trackerUrls[0]).to.include(server.host)
92 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
93 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
89 } 94 }
90 }) 95 })
91 96
@@ -100,7 +105,7 @@ describe('Test update host scripts', function () {
100 } 105 }
101 }) 106 })
102 107
103 it('Should have update accounts url', async function () { 108 it('Should have updated accounts url', async function () {
104 const res = await getAccountsList(server.url) 109 const res = await getAccountsList(server.url)
105 expect(res.body.total).to.equal(3) 110 expect(res.body.total).to.equal(3)
106 111
@@ -112,7 +117,7 @@ describe('Test update host scripts', function () {
112 } 117 }
113 }) 118 })
114 119
115 it('Should update torrent hosts', async function () { 120 it('Should have updated torrent hosts', async function () {
116 this.timeout(30000) 121 this.timeout(30000)
117 122
118 const res = await getVideosList(server.url) 123 const res = await getVideosList(server.url)
@@ -142,6 +147,6 @@ describe('Test update host scripts', function () {
142 }) 147 })
143 148
144 after(async function () { 149 after(async function () {
145 killallServers([ server ]) 150 await cleanupTests([ server ])
146 }) 151 })
147}) 152})
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 06b4a9c5a..778dcd08e 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -4,18 +4,17 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import * as request from 'supertest' 5import * as request from 'supertest'
6import { 6import {
7 flushTests, 7 cleanupTests,
8 flushAndRunServer,
8 getCustomConfig, 9 getCustomConfig,
9 getVideosList, 10 getVideosList,
10 killallServers,
11 makeHTMLRequest, 11 makeHTMLRequest,
12 runServer,
13 ServerInfo, 12 ServerInfo,
14 serverLogin, 13 serverLogin,
15 updateCustomConfig, 14 updateCustomConfig,
16 updateCustomSubConfig, 15 updateCustomSubConfig,
17 uploadVideo 16 uploadVideo
18} from '../../shared/utils' 17} from '../../shared/extra-utils'
19 18
20const expect = chai.expect 19const expect = chai.expect
21 20
@@ -31,9 +30,7 @@ describe('Test a client controllers', function () {
31 before(async function () { 30 before(async function () {
32 this.timeout(120000) 31 this.timeout(120000)
33 32
34 await flushTests() 33 server = await flushAndRunServer(1)
35
36 server = await runServer(1)
37 server.accessToken = await serverLogin(server) 34 server.accessToken = await serverLogin(server)
38 35
39 const videoAttributes = { 36 const videoAttributes = {
@@ -148,6 +145,6 @@ describe('Test a client controllers', function () {
148 }) 145 })
149 146
150 after(async function () { 147 after(async function () {
151 killallServers([ server ]) 148 await cleanupTests([ server ])
152 }) 149 })
153}) 150})
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index a771474bc..0dcdf09cf 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -3,6 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 cleanupTests,
6 createUser, 7 createUser,
7 doubleFollow, 8 doubleFollow,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
@@ -13,10 +14,10 @@ import {
13 ServerInfo, 14 ServerInfo,
14 setAccessTokensToServers, 15 setAccessTokensToServers,
15 uploadVideo, userLogin 16 uploadVideo, userLogin
16} from '../../../shared/utils' 17} from '../../../shared/extra-utils'
17import * as libxmljs from 'libxmljs' 18import * as libxmljs from 'libxmljs'
18import { addVideoCommentThread } from '../../../shared/utils/videos/video-comments' 19import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
19import { waitJobs } from '../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../shared/extra-utils/server/jobs'
20import { User } from '../../../shared/models/users' 21import { User } from '../../../shared/models/users'
21 22
22chai.use(require('chai-xml')) 23chai.use(require('chai-xml'))
@@ -50,7 +51,7 @@ describe('Test syndication feeds', () => {
50 51
51 { 52 {
52 const attr = { username: 'john', password: 'password' } 53 const attr = { username: 'john', password: 'password' }
53 await createUser(servers[0].url, servers[0].accessToken, attr.username, attr.password) 54 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: attr.username, password: attr.password })
54 userAccessToken = await userLogin(servers[0], attr) 55 userAccessToken = await userLogin(servers[0], attr)
55 56
56 const res = await getMyUserInformation(servers[0].url, userAccessToken) 57 const res = await getMyUserInformation(servers[0].url, userAccessToken)
@@ -208,11 +209,6 @@ describe('Test syndication feeds', () => {
208 }) 209 })
209 210
210 after(async function () { 211 after(async function () {
211 killallServers(servers) 212 await cleanupTests(servers)
212
213 // Keep the logs if the test failed
214 if (this['ok']) {
215 await flushTests()
216 }
217 }) 213 })
218}) 214})
diff --git a/server/tests/fixtures/thumbnail-playlist.jpg b/server/tests/fixtures/thumbnail-playlist.jpg
new file mode 100644
index 000000000..19db4f18c
--- /dev/null
+++ b/server/tests/fixtures/thumbnail-playlist.jpg
Binary files differ
diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts
index 551208245..03b971770 100644
--- a/server/tests/helpers/index.ts
+++ b/server/tests/helpers/index.ts
@@ -1,2 +1,3 @@
1import './core-utils' 1import './core-utils'
2import './comment-model' 2import './comment-model'
3import './request'
diff --git a/server/tests/helpers/request.ts b/server/tests/helpers/request.ts
new file mode 100644
index 000000000..a754bc6e2
--- /dev/null
+++ b/server/tests/helpers/request.ts
@@ -0,0 +1,48 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
5import { get4KFileUrl, root, wait } from '../../../shared/extra-utils'
6import { join } from 'path'
7import { pathExists, remove } from 'fs-extra'
8import { expect } from 'chai'
9
10describe('Request helpers', function () {
11 const destPath1 = join(root(), 'test-output-1.txt')
12 const destPath2 = join(root(), 'test-output-2.txt')
13
14 it('Should throw an error when the bytes limit is exceeded for request', async function () {
15 try {
16 await doRequest({ uri: get4KFileUrl() }, 3)
17 } catch {
18 return
19 }
20
21 throw new Error('No error thrown by do request')
22 })
23
24 it('Should throw an error when the bytes limit is exceeded for request and save file', async function () {
25 try {
26 await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath1, 3)
27 } catch {
28
29 await wait(500)
30 expect(await pathExists(destPath1)).to.be.false
31 return
32 }
33
34 throw new Error('No error thrown by do request and save to file')
35 })
36
37 it('Should succeed if the file is below the limit', async function () {
38 await doRequest({ uri: get4KFileUrl() }, 5)
39 await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath2, 5)
40
41 expect(await pathExists(destPath2)).to.be.true
42 })
43
44 after(async function () {
45 await remove(destPath1)
46 await remove(destPath2)
47 })
48})
diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts
index 5f82719da..ed406e1bc 100644
--- a/server/tests/misc-endpoints.ts
+++ b/server/tests/misc-endpoints.ts
@@ -4,15 +4,14 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addVideoChannel, 6 addVideoChannel,
7 cleanupTests,
7 createUser, 8 createUser,
8 flushTests, 9 flushAndRunServer,
9 killallServers,
10 makeGetRequest, 10 makeGetRequest,
11 runServer,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 uploadVideo 13 uploadVideo
15} from '../../shared/utils' 14} from '../../shared/extra-utils'
16import { VideoPrivacy } from '../../shared/models/videos' 15import { VideoPrivacy } from '../../shared/models/videos'
17 16
18const expect = chai.expect 17const expect = chai.expect
@@ -23,9 +22,7 @@ describe('Test misc endpoints', function () {
23 before(async function () { 22 before(async function () {
24 this.timeout(120000) 23 this.timeout(120000)
25 24
26 await flushTests() 25 server = await flushAndRunServer(1)
27
28 server = await runServer(1)
29 await setAccessTokensToServers([ server ]) 26 await setAccessTokensToServers([ server ])
30 }) 27 })
31 28
@@ -149,8 +146,8 @@ describe('Test misc endpoints', function () {
149 await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' }) 146 await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' })
150 await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' }) 147 await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' })
151 148
152 await createUser(server.url, server.accessToken, 'user1', 'password') 149 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
153 await createUser(server.url, server.accessToken, 'user2', 'password') 150 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
154 151
155 const res = await makeGetRequest({ 152 const res = await makeGetRequest({
156 url: server.url, 153 url: server.url,
@@ -174,6 +171,6 @@ describe('Test misc endpoints', function () {
174 }) 171 })
175 172
176 after(async function () { 173 after(async function () {
177 killallServers([ server ]) 174 await cleanupTests([ server ])
178 }) 175 })
179}) 176})
diff --git a/server/tests/real-world/populate-database.ts b/server/tests/real-world/populate-database.ts
index 016503498..b1c1688e7 100644
--- a/server/tests/real-world/populate-database.ts
+++ b/server/tests/real-world/populate-database.ts
@@ -6,11 +6,11 @@ import {
6 getVideosList, 6 getVideosList,
7 killallServers, 7 killallServers,
8 rateVideo, 8 rateVideo,
9 runServer, 9 flushAndRunServer,
10 ServerInfo, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 uploadVideo 12 uploadVideo
13} from '../../../shared/utils' 13} from '../../../shared/extra-utils'
14import * as Bluebird from 'bluebird' 14import * as Bluebird from 'bluebird'
15 15
16start() 16start()
@@ -19,11 +19,10 @@ start()
19// ---------------------------------------------------------------------------- 19// ----------------------------------------------------------------------------
20 20
21async function start () { 21async function start () {
22 await flushTests()
23 22
24 console.log('Flushed tests.') 23 console.log('Flushed tests.')
25 24
26 const server = await runServer(6) 25 const server = await flushAndRunServer(6)
27 26
28 process.on('exit', async () => { 27 process.on('exit', async () => {
29 killallServers([ server ]) 28 killallServers([ server ])
@@ -78,7 +77,7 @@ function createUserCustom (server: ServerInfo) {
78 const username = Date.now().toString() + getRandomInt(0, 100000) 77 const username = Date.now().toString() + getRandomInt(0, 100000)
79 console.log('Creating user %s.', username) 78 console.log('Creating user %s.', username)
80 79
81 return createUser(server.url, server.accessToken, username, 'coucou') 80 return createUser({ url: server.url, accessToken: server.accessToken, username: username, password: 'coucou' })
82} 81}
83 82
84function uploadCustom (server: ServerInfo) { 83function uploadCustom (server: ServerInfo) {
diff --git a/server/tests/real-world/real-world.ts b/server/tests/real-world/real-world.ts
index ac3baaf9a..8b070004d 100644
--- a/server/tests/real-world/real-world.ts
+++ b/server/tests/real-world/real-world.ts
@@ -16,8 +16,8 @@ import {
16 updateVideo, 16 updateVideo,
17 uploadVideo, viewVideo, 17 uploadVideo, viewVideo,
18 wait 18 wait
19} from '../../../shared/utils' 19} from '../../../shared/extra-utils'
20import { getJobsListPaginationAndSort } from '../../../shared/utils/server/jobs' 20import { getJobsListPaginationAndSort } from '../../../shared/extra-utils/server/jobs'
21 21
22interface ServerInfo extends DefaultServerInfo { 22interface ServerInfo extends DefaultServerInfo {
23 requestsNumber: number 23 requestsNumber: number