X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fvideos.ts;h=188d1835c17446ce4e83c3bd2767b0da818c2d34;hb=e62f03ae0412f4efa62917d8741bc1a39e8ed7fc;hp=699f135c79410c1c010be94c0f4aaed83da0375b;hpb=be0f59b4eec3c2c4dcd151e2b174be39dff1568e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 699f135c7..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' @@ -6,11 +6,29 @@ import 'mocha' import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { - createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, - makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin -} from '../../utils' -import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' -import { getAccountsList } from '../../utils/users/accounts' + cleanupTests, + createUser, + flushAndRunServer, + getMyUserInformation, + getVideo, + getVideosList, + immutableAssign, + makeDeleteRequest, + makeGetRequest, + makePutBodyRequest, + makeUploadRequest, + removeVideo, + ServerInfo, + setAccessTokensToServers, + userLogin, + root +} from '../../../../shared/extra-utils' +import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination +} from '../../../../shared/extra-utils/requests/check-api-params' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -28,26 +46,24 @@ describe('Test videos API validator', function () { before(async function () { this.timeout(30000) - await flushTests() - - server = await runServer(1) + server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) const username = 'user1' const password = 'my super password' - await createUser(server.url, server.accessToken, username, password) + await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) userAccessToken = await userLogin(server, { username, password }) { 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 } }) - describe('When listing a video', function () { + describe('When listing videos', function () { it('Should fail with a bad start pagination', async function () { await checkBadStartPagination(server.url, path) }) @@ -60,8 +76,12 @@ describe('Test videos API validator', function () { await checkBadSortPagination(server.url, path) }) + it('Should fail with a bad skipVideos query', async function () { + 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 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } }) }) }) @@ -71,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 }) }) @@ -88,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 }) }) }) @@ -108,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 }) }) }) @@ -132,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 }) }) }) @@ -156,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(__dirname, '..', '..', 'fixtures', 'video_short.webm') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm') } before(function () { @@ -175,12 +195,14 @@ describe('Test videos API validator', function () { language: 'pt', nsfw: false, commentsEnabled: true, + downloadEnabled: true, waitTranscoding: true, description: 'my super description', support: 'my super support text', tags: [ 'tag1', 'tag2' ], privacy: VideoPrivacy.PUBLIC, - channelId: channelId + channelId: channelId, + originallyPublishedAt: new Date().toISOString() } }) @@ -258,7 +280,7 @@ describe('Test videos API validator', function () { username: 'fake', password: 'fake_password' } - await createUser(server.url, server.accessToken, user.username, user.password) + await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) const accessTokenUser = await userLogin(server, user) const res = await getMyUserInformation(server.url, accessTokenUser) @@ -308,25 +330,51 @@ describe('Test videos API validator', function () { await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) + it('Should fail with a bad originally published at attribute', async function () { + const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) + const attaches = baseCorrectAttaches + + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + it('Should fail without an input file', async function () { const fields = baseCorrectParams const attaches = {} await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) - it('Should fail without an incorrect input file', async function () { + it('Should fail with an incorrect input file', async function () { const fields = baseCorrectParams - const attaches = { - 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') + let attaches = { + 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') + } + 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(__dirname, '..', '..', 'fixtures', 'avatar.png'), - 'videofile': join(__dirname, '..', '..', '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 }) @@ -335,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(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), - 'videofile': join(__dirname, '..', '..', '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 }) @@ -345,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(__dirname, '..', '..', 'fixtures', 'avatar.png'), - 'videofile': join(__dirname, '..', '..', '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 }) @@ -355,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(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), - 'videofile': join(__dirname, '..', '..', '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 }) @@ -375,13 +423,13 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } { const attaches = immutableAssign(baseCorrectAttaches, { - videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') }) await makeUploadRequest({ @@ -390,13 +438,13 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } { const attaches = immutableAssign(baseCorrectAttaches, { - videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv') + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') }) await makeUploadRequest({ @@ -405,7 +453,7 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } }) @@ -419,6 +467,7 @@ describe('Test videos API validator', function () { language: 'pt', nsfw: false, commentsEnabled: false, + downloadEnabled: false, description: 'my super description', privacy: VideoPrivacy.PUBLIC, tags: [ 'tag1', 'tag2' ] @@ -447,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 }) }) @@ -523,10 +572,16 @@ describe('Test videos API validator', function () { await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) + it('Should fail with a bad originally published at param', async function () { + const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) + + await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) + }) + it('Should fail with an incorrect thumbnail file', async function () { const fields = baseCorrectParams const attaches = { - 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ @@ -542,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(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png') } await makeUploadRequest({ @@ -558,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(__dirname, '..', '..', 'fixtures', 'avatar.png') + previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } await makeUploadRequest({ @@ -574,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(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png') } await makeUploadRequest({ @@ -590,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') @@ -598,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 + }) }) }) @@ -607,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') @@ -615,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 () { @@ -651,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 }) }) @@ -671,7 +738,7 @@ describe('Test videos API validator', function () { path: path + videoId + '/rate', token: server.accessToken, fields, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -681,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') @@ -705,11 +772,6 @@ describe('Test videos API validator', function () { }) after(async function () { - killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + await cleanupTests([ server ]) }) })