+ await servers[0].users.create({ username: user.username, password: user.password })
+ userAccessToken = await servers[0].login.getAccessToken(user)
+
+ videoIdLocal = (await servers[0].videos.quickUpload({ name: 'video' })).id
+
+ const remoteUUID = (await servers[1].videos.quickUpload({ name: 'video' })).uuid
+
+ await waitJobs(servers)
+
+ videoRemote = await servers[0].videos.get({ id: remoteUUID })
+ })
+
+ describe('When listing redundancies', function () {
+ const path = '/api/v1/server/redundancy/videos'
+
+ let url: string
+ let token: string
+
+ before(function () {
+ url = servers[0].url
+ token = servers[0].accessToken
+ })
+
+ it('Should fail with an invalid token', async function () {
+ await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ })
+
+ it('Should fail if the user is not an administrator', async function () {
+ await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ })
+
+ it('Should fail with a bad start pagination', async function () {
+ await checkBadStartPagination(url, path, servers[0].accessToken)
+ })
+
+ it('Should fail with a bad count pagination', async function () {
+ await checkBadCountPagination(url, path, servers[0].accessToken)
+ })
+
+ it('Should fail with an incorrect sort', async function () {
+ await checkBadSortPagination(url, path, servers[0].accessToken)
+ })
+
+ it('Should fail with a bad target', async function () {
+ await makeGetRequest({ url, path, token, query: { target: 'bad target' } })
+ })
+
+ it('Should fail without target', async function () {
+ await makeGetRequest({ url, path, token })
+ })
+
+ it('Should succeed with the correct params', async function () {
+ await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 })
+ })
+ })
+
+ describe('When manually adding a redundancy', function () {
+ const path = '/api/v1/server/redundancy/videos'
+
+ let url: string
+ let token: string
+
+ before(function () {
+ url = servers[0].url
+ token = servers[0].accessToken
+ })
+
+ it('Should fail with an invalid token', async function () {
+ await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ })
+
+ it('Should fail if the user is not an administrator', async function () {
+ await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ })
+
+ it('Should fail without a video id', async function () {
+ await makePostBodyRequest({ url, path, token })
+ })
+
+ it('Should fail with an incorrect video id', async function () {
+ await makePostBodyRequest({ url, path, token, fields: { videoId: 'peertube' } })
+ })
+
+ it('Should fail with a not found video id', async function () {
+ await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
+ })
+
+ it('Should fail with a local a video id', async function () {
+ await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdLocal } })
+ })
+
+ it('Should succeed with the correct params', async function () {
+ await makePostBodyRequest({
+ url,
+ path,
+ token,
+ fields: { videoId: videoRemote.shortUUID },
+ expectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ })
+
+ it('Should fail if the video is already duplicated', async function () {
+ this.timeout(30000)
+
+ await waitJobs(servers)
+
+ await makePostBodyRequest({
+ url,
+ path,
+ token,
+ fields: { videoId: videoRemote.uuid },
+ expectedStatus: HttpStatusCode.CONFLICT_409
+ })
+ })
+ })
+
+ describe('When manually removing a redundancy', function () {
+ const path = '/api/v1/server/redundancy/videos/'
+
+ let url: string
+ let token: string
+
+ before(function () {
+ url = servers[0].url
+ token = servers[0].accessToken
+ })
+
+ it('Should fail with an invalid token', async function () {
+ await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
+ })
+
+ it('Should fail if the user is not an administrator', async function () {
+ await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+ })
+
+ it('Should fail with an incorrect video id', async function () {
+ await makeDeleteRequest({ url, path: path + 'toto', token })
+ })
+
+ it('Should fail with a not found video redundancy', async function () {
+ await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
+ })