aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/redundancy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/redundancy.ts')
-rw-r--r--server/tests/api/check-params/redundancy.ts60
1 files changed, 27 insertions, 33 deletions
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index dac6938de..d9f905549 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -1,30 +1,25 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { VideoCreateResult } from '@shared/models'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 4import {
7 checkBadCountPagination, 5 checkBadCountPagination,
8 checkBadSortPagination, 6 checkBadSortPagination,
9 checkBadStartPagination, 7 checkBadStartPagination,
10 cleanupTests, 8 cleanupTests,
11 createUser, 9 createMultipleServers,
12 doubleFollow, 10 doubleFollow,
13 flushAndRunMultipleServers,
14 getVideo,
15 makeDeleteRequest, 11 makeDeleteRequest,
16 makeGetRequest, 12 makeGetRequest,
17 makePostBodyRequest, 13 makePostBodyRequest,
18 makePutBodyRequest, 14 makePutBodyRequest,
19 ServerInfo, 15 PeerTubeServer,
20 setAccessTokensToServers, 16 setAccessTokensToServers,
21 uploadVideoAndGetId,
22 userLogin,
23 waitJobs 17 waitJobs
24} from '../../../../shared/extra-utils' 18} from '@shared/extra-utils'
19import { HttpStatusCode, VideoCreateResult } from '@shared/models'
25 20
26describe('Test server redundancy API validators', function () { 21describe('Test server redundancy API validators', function () {
27 let servers: ServerInfo[] 22 let servers: PeerTubeServer[]
28 let userAccessToken = null 23 let userAccessToken = null
29 let videoIdLocal: number 24 let videoIdLocal: number
30 let videoRemote: VideoCreateResult 25 let videoRemote: VideoCreateResult
@@ -34,7 +29,7 @@ describe('Test server redundancy API validators', function () {
34 before(async function () { 29 before(async function () {
35 this.timeout(80000) 30 this.timeout(80000)
36 31
37 servers = await flushAndRunMultipleServers(2) 32 servers = await createMultipleServers(2)
38 33
39 await setAccessTokensToServers(servers) 34 await setAccessTokensToServers(servers)
40 await doubleFollow(servers[0], servers[1]) 35 await doubleFollow(servers[0], servers[1])
@@ -44,17 +39,16 @@ describe('Test server redundancy API validators', function () {
44 password: 'password' 39 password: 'password'
45 } 40 }
46 41
47 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 42 await servers[0].users.create({ username: user.username, password: user.password })
48 userAccessToken = await userLogin(servers[0], user) 43 userAccessToken = await servers[0].login.getAccessToken(user)
49 44
50 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id 45 videoIdLocal = (await servers[0].videos.quickUpload({ name: 'video' })).id
51 46
52 const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid 47 const remoteUUID = (await servers[1].videos.quickUpload({ name: 'video' })).uuid
53 48
54 await waitJobs(servers) 49 await waitJobs(servers)
55 50
56 const resVideo = await getVideo(servers[0].url, remoteUUID) 51 videoRemote = await servers[0].videos.get({ id: remoteUUID })
57 videoRemote = resVideo.body
58 }) 52 })
59 53
60 describe('When listing redundancies', function () { 54 describe('When listing redundancies', function () {
@@ -69,11 +63,11 @@ describe('Test server redundancy API validators', function () {
69 }) 63 })
70 64
71 it('Should fail with an invalid token', async function () { 65 it('Should fail with an invalid token', async function () {
72 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 66 await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
73 }) 67 })
74 68
75 it('Should fail if the user is not an administrator', async function () { 69 it('Should fail if the user is not an administrator', async function () {
76 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 70 await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
77 }) 71 })
78 72
79 it('Should fail with a bad start pagination', async function () { 73 it('Should fail with a bad start pagination', async function () {
@@ -97,7 +91,7 @@ describe('Test server redundancy API validators', function () {
97 }) 91 })
98 92
99 it('Should succeed with the correct params', async function () { 93 it('Should succeed with the correct params', async function () {
100 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: HttpStatusCode.OK_200 }) 94 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 })
101 }) 95 })
102 }) 96 })
103 97
@@ -113,11 +107,11 @@ describe('Test server redundancy API validators', function () {
113 }) 107 })
114 108
115 it('Should fail with an invalid token', async function () { 109 it('Should fail with an invalid token', async function () {
116 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 110 await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
117 }) 111 })
118 112
119 it('Should fail if the user is not an administrator', async function () { 113 it('Should fail if the user is not an administrator', async function () {
120 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 114 await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
121 }) 115 })
122 116
123 it('Should fail without a video id', async function () { 117 it('Should fail without a video id', async function () {
@@ -129,7 +123,7 @@ describe('Test server redundancy API validators', function () {
129 }) 123 })
130 124
131 it('Should fail with a not found video id', async function () { 125 it('Should fail with a not found video id', async function () {
132 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 126 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
133 }) 127 })
134 128
135 it('Should fail with a local a video id', async function () { 129 it('Should fail with a local a video id', async function () {
@@ -142,7 +136,7 @@ describe('Test server redundancy API validators', function () {
142 path, 136 path,
143 token, 137 token,
144 fields: { videoId: videoRemote.shortUUID }, 138 fields: { videoId: videoRemote.shortUUID },
145 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 139 expectedStatus: HttpStatusCode.NO_CONTENT_204
146 }) 140 })
147 }) 141 })
148 142
@@ -156,7 +150,7 @@ describe('Test server redundancy API validators', function () {
156 path, 150 path,
157 token, 151 token,
158 fields: { videoId: videoRemote.uuid }, 152 fields: { videoId: videoRemote.uuid },
159 statusCodeExpected: HttpStatusCode.CONFLICT_409 153 expectedStatus: HttpStatusCode.CONFLICT_409
160 }) 154 })
161 }) 155 })
162 }) 156 })
@@ -173,11 +167,11 @@ describe('Test server redundancy API validators', function () {
173 }) 167 })
174 168
175 it('Should fail with an invalid token', async function () { 169 it('Should fail with an invalid token', async function () {
176 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 170 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
177 }) 171 })
178 172
179 it('Should fail if the user is not an administrator', async function () { 173 it('Should fail if the user is not an administrator', async function () {
180 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 174 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
181 }) 175 })
182 176
183 it('Should fail with an incorrect video id', async function () { 177 it('Should fail with an incorrect video id', async function () {
@@ -185,7 +179,7 @@ describe('Test server redundancy API validators', function () {
185 }) 179 })
186 180
187 it('Should fail with a not found video redundancy', async function () { 181 it('Should fail with a not found video redundancy', async function () {
188 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 182 await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
189 }) 183 })
190 }) 184 })
191 185
@@ -198,7 +192,7 @@ describe('Test server redundancy API validators', function () {
198 path: path + '/localhost:' + servers[1].port, 192 path: path + '/localhost:' + servers[1].port,
199 fields: { redundancyAllowed: true }, 193 fields: { redundancyAllowed: true },
200 token: 'fake_token', 194 token: 'fake_token',
201 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 195 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
202 }) 196 })
203 }) 197 })
204 198
@@ -208,7 +202,7 @@ describe('Test server redundancy API validators', function () {
208 path: path + '/localhost:' + servers[1].port, 202 path: path + '/localhost:' + servers[1].port,
209 fields: { redundancyAllowed: true }, 203 fields: { redundancyAllowed: true },
210 token: userAccessToken, 204 token: userAccessToken,
211 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 205 expectedStatus: HttpStatusCode.FORBIDDEN_403
212 }) 206 })
213 }) 207 })
214 208
@@ -218,7 +212,7 @@ describe('Test server redundancy API validators', function () {
218 path: path + '/example.com', 212 path: path + '/example.com',
219 fields: { redundancyAllowed: true }, 213 fields: { redundancyAllowed: true },
220 token: servers[0].accessToken, 214 token: servers[0].accessToken,
221 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 215 expectedStatus: HttpStatusCode.NOT_FOUND_404
222 }) 216 })
223 }) 217 })
224 218
@@ -228,7 +222,7 @@ describe('Test server redundancy API validators', function () {
228 path: path + '/localhost:' + servers[1].port, 222 path: path + '/localhost:' + servers[1].port,
229 fields: { blabla: true }, 223 fields: { blabla: true },
230 token: servers[0].accessToken, 224 token: servers[0].accessToken,
231 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 225 expectedStatus: HttpStatusCode.BAD_REQUEST_400
232 }) 226 })
233 }) 227 })
234 228
@@ -238,7 +232,7 @@ describe('Test server redundancy API validators', function () {
238 path: path + '/localhost:' + servers[1].port, 232 path: path + '/localhost:' + servers[1].port,
239 fields: { redundancyAllowed: true }, 233 fields: { redundancyAllowed: true },
240 token: servers[0].accessToken, 234 token: servers[0].accessToken,
241 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 235 expectedStatus: HttpStatusCode.NO_CONTENT_204
242 }) 236 })
243 }) 237 })
244 }) 238 })