X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fvideos.ts;h=188d1835c17446ce4e83c3bd2767b0da818c2d34;hb=a786d8a08bf99f339bf16808f46e160404497ae2;hp=16ef1c50521761dc71fca2d86a4c73dc087201a1;hpb=fe98765624cdd6695739bda719fcb726b71c2b2a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 16ef1c505..188d1835c 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -1,4 +1,4 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import * as chai from 'chai' import { omit } from 'lodash' @@ -28,6 +28,7 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -56,8 +57,8 @@ describe('Test videos API validator', function () { { const res = await getMyUserInformation(server.url, server.accessToken) - channelId = res.body.videoChannels[ 0 ].id - channelName = res.body.videoChannels[ 0 ].name + channelId = res.body.videoChannels[0].id + channelName = res.body.videoChannels[0].name accountName = res.body.account.name + '@' + res.body.account.host } }) @@ -76,11 +77,11 @@ describe('Test videos API validator', function () { }) it('Should fail with a bad skipVideos query', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: 'toto' } }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } }) }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: false } }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } }) }) }) @@ -90,7 +91,7 @@ describe('Test videos API validator', function () { await makeGetRequest({ url: server.url, path: join(path, 'search'), - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -107,7 +108,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -127,7 +128,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -151,7 +152,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -175,14 +176,14 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) describe('When adding a video', function () { let baseCorrectParams const baseCorrectAttaches = { - 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.webm') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm') } before(function () { @@ -330,7 +331,7 @@ describe('Test videos API validator', function () { }) it('Should fail with a bad originally published at attribute', async function () { - const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' }) + const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) const attaches = baseCorrectAttaches await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -345,21 +346,35 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect input file', async function () { const fields = baseCorrectParams let attaches = { - 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } - await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ + url: server.url, + path: path + '/upload', + token: server.accessToken, + fields, + attaches, + statusCodeExpected: HttpStatusCode.UNPROCESSABLE_ENTITY_422 + }) attaches = { - 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } - await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ + url: server.url, + path: path + '/upload', + token: server.accessToken, + fields, + attaches, + statusCodeExpected: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 + }) }) it('Should fail with an incorrect thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'), - 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') + thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'), + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -368,8 +383,8 @@ describe('Test videos API validator', function () { it('Should fail with a big thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'), - 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') + thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'), + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -378,8 +393,8 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'), - 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') + previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'), + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -388,8 +403,8 @@ describe('Test videos API validator', function () { it('Should fail with a big preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'), - 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') + previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'), + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) @@ -408,7 +423,7 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -423,7 +438,7 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -438,7 +453,7 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } }) @@ -481,7 +496,7 @@ describe('Test videos API validator', function () { path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', token: server.accessToken, fields, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -566,7 +581,7 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png') + thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ @@ -582,7 +597,7 @@ describe('Test videos API validator', function () { it('Should fail with a big thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png') + thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png') } await makeUploadRequest({ @@ -598,7 +613,7 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png') + previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ @@ -614,7 +629,7 @@ describe('Test videos API validator', function () { it('Should fail with a big preview file', async function () { const fields = baseCorrectParams const attaches = { - 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png') + previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png') } await makeUploadRequest({ @@ -630,7 +645,13 @@ describe('Test videos API validator', function () { it('Should fail with a video of another user without the appropriate right', async function () { const fields = baseCorrectParams - await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 }) + await makePutBodyRequest({ + url: server.url, + path: path + videoId, + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should fail with a video of another server') @@ -638,7 +659,13 @@ describe('Test videos API validator', function () { it('Should succeed with the correct parameters', async function () { const fields = baseCorrectParams - await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) + await makePutBodyRequest({ + url: server.url, + path: path + videoId, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) @@ -647,7 +674,7 @@ describe('Test videos API validator', function () { const res = await makeGetRequest({ url: server.url, path, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) expect(res.body.data).to.be.an('array') @@ -655,11 +682,11 @@ describe('Test videos API validator', function () { }) it('Should fail without a correct uuid', async function () { - await getVideo(server.url, 'coucou', 400) + await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400) }) it('Should return 404 with an incorrect video', async function () { - await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) + await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) }) it('Should succeed with the correct parameters', async function () { @@ -691,7 +718,7 @@ describe('Test videos API validator', function () { path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', token: server.accessToken, fields, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -711,7 +738,7 @@ describe('Test videos API validator', function () { path: path + videoId + '/rate', token: server.accessToken, fields, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -721,20 +748,20 @@ describe('Test videos API validator', function () { await makeDeleteRequest({ url: server.url, path, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail without a correct uuid', async function () { - await removeVideo(server.url, server.accessToken, 'hello', 400) + await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with a video which does not exist', async function () { - await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) + await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a video of another user without the appropriate right', async function () { - await removeVideo(server.url, userAccessToken, videoId, 403) + await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with a video of another server')