1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
12 flushAndRunMultipleServers, makeDeleteRequest,
13 makeGetRequest, makePostBodyRequest,
16 setAccessTokensToServers, uploadVideoAndGetId,
18 } from '../../../../shared/extra-utils'
20 describe('Test server redundancy API validators', function () {
21 let servers: ServerInfo[]
22 let userAccessToken = null
23 let videoIdLocal: number
24 let videoIdRemote: number
26 // ---------------------------------------------------------------
28 before(async function () {
31 servers = await flushAndRunMultipleServers(2)
33 await setAccessTokensToServers(servers)
34 await doubleFollow(servers[0], servers[1])
41 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
42 userAccessToken = await userLogin(servers[0], user)
44 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
45 videoIdRemote = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).id
47 await waitJobs(servers)
50 describe('When listing redundancies', function () {
51 const path = '/api/v1/server/redundancy/videos'
58 token = servers[0].accessToken
61 it('Should fail with an invalid token', async function () {
62 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 })
65 it('Should fail if the user is not an administrator', async function () {
66 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 })
69 it('Should fail with a bad start pagination', async function () {
70 await checkBadStartPagination(url, path, servers[0].accessToken)
73 it('Should fail with a bad count pagination', async function () {
74 await checkBadCountPagination(url, path, servers[0].accessToken)
77 it('Should fail with an incorrect sort', async function () {
78 await checkBadSortPagination(url, path, servers[0].accessToken)
81 it('Should fail with a bad target', async function () {
82 await makeGetRequest({ url, path, token, query: { target: 'bad target' } })
85 it('Should fail without target', async function () {
86 await makeGetRequest({ url, path, token })
89 it('Should succeed with the correct params', async function () {
90 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: 200 })
94 describe('When manually adding a redundancy', function () {
95 const path = '/api/v1/server/redundancy/videos'
102 token = servers[0].accessToken
105 it('Should fail with an invalid token', async function () {
106 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 })
109 it('Should fail if the user is not an administrator', async function () {
110 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 })
113 it('Should fail without a video id', async function () {
114 await makePostBodyRequest({ url, path, token })
117 it('Should fail with an incorrect video id', async function () {
118 await makePostBodyRequest({ url, path, token, fields: { videoId: 'peertube' } })
121 it('Should fail with a not found video id', async function () {
122 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: 404 })
125 it('Should fail with a local a video id', async function () {
126 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdLocal } })
129 it('Should succeed with the correct params', async function () {
130 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 204 })
133 it('Should fail if the video is already duplicated', async function () {
136 await waitJobs(servers)
138 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 409 })
142 describe('When manually removing a redundancy', function () {
143 const path = '/api/v1/server/redundancy/videos/'
150 token = servers[0].accessToken
153 it('Should fail with an invalid token', async function () {
154 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: 401 })
157 it('Should fail if the user is not an administrator', async function () {
158 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: 403 })
161 it('Should fail with an incorrect video id', async function () {
162 await makeDeleteRequest({ url, path: path + 'toto', token })
165 it('Should fail with a not found video redundancy', async function () {
166 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: 404 })
170 describe('When updating server redundancy', function () {
171 const path = '/api/v1/server/redundancy'
173 it('Should fail with an invalid token', async function () {
174 await makePutBodyRequest({
176 path: path + '/localhost:' + servers[1].port,
177 fields: { redundancyAllowed: true },
179 statusCodeExpected: 401
183 it('Should fail if the user is not an administrator', async function () {
184 await makePutBodyRequest({
186 path: path + '/localhost:' + servers[1].port,
187 fields: { redundancyAllowed: true },
188 token: userAccessToken,
189 statusCodeExpected: 403
193 it('Should fail if we do not follow this server', async function () {
194 await makePutBodyRequest({
196 path: path + '/example.com',
197 fields: { redundancyAllowed: true },
198 token: servers[0].accessToken,
199 statusCodeExpected: 404
203 it('Should fail without de redundancyAllowed param', async function () {
204 await makePutBodyRequest({
206 path: path + '/localhost:' + servers[1].port,
207 fields: { blabla: true },
208 token: servers[0].accessToken,
209 statusCodeExpected: 400
213 it('Should succeed with the correct parameters', async function () {
214 await makePutBodyRequest({
216 path: path + '/localhost:' + servers[1].port,
217 fields: { redundancyAllowed: true },
218 token: servers[0].accessToken,
219 statusCodeExpected: 204
224 after(async function () {
225 await cleanupTests(servers)