X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fvideos.ts;h=572ca8997507791bdfd6dfb60dd3b9f8b942c41f;hb=d102de1b38f2877463529c3b27bd35ffef4fd8bf;hp=e11ca0c828ef9960ec541cc5c9825a071bc5f445;hpb=a24bd1ed41b43790bab6ba789580bb4e85f07d85;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index e11ca0c82..572ca8997 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -1,15 +1,11 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import * as chai from 'chai' -import { omit } from 'lodash' +import { expect } from 'chai' import { join } from 'path' -import { randomInt } from '@shared/core-utils' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, checkUploadVideoParam } from '@server/tests/shared' +import { omit, randomInt, root } from '@shared/core-utils' +import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, - checkUploadVideoParam, cleanupTests, createSingleServer, makeDeleteRequest, @@ -17,12 +13,8 @@ import { makePutBodyRequest, makeUploadRequest, PeerTubeServer, - root, setAccessTokensToServers -} from '@shared/extra-utils' -import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' - -const expect = chai.expect +} from '@shared/server-commands' describe('Test videos API validator', function () { const path = '/api/v1/videos/' @@ -32,6 +24,7 @@ describe('Test videos API validator', function () { let channelId: number let channelName: string let video: VideoCreateResult + let privateVideo: VideoCreateResult // --------------------------------------------------------------- @@ -42,10 +35,7 @@ describe('Test videos API validator', function () { await setAccessTokensToServers([ server ]) - const username = 'user1' - const password = 'my super password' - await server.users.create({ username: username, password: password }) - userAccessToken = await server.login.getAccessToken({ username, password }) + userAccessToken = await server.users.generateUserAndToken('user1') { const body = await server.users.getMyInfo() @@ -53,6 +43,10 @@ describe('Test videos API validator', function () { channelName = body.videoChannels[0].name accountName = body.account.name + '@' + body.account.host } + + { + privateVideo = await server.videos.quickUpload({ name: 'private video', privacy: VideoPrivacy.PRIVATE }) + } }) describe('When listing videos', function () { @@ -119,6 +113,20 @@ describe('Test videos API validator', function () { await checkBadSortPagination(server.url, path, server.accessToken) }) + it('Should fail with an invalid channel', async function () { + await makeGetRequest({ url: server.url, token: server.accessToken, path, query: { channelId: 'toto' } }) + }) + + it('Should fail with an unknown channel', async function () { + await makeGetRequest({ + url: server.url, + token: server.accessToken, + path, + query: { channelId: 89898 }, + expectedStatus: HttpStatusCode.NOT_FOUND_404 + }) + }) + it('Should success with the correct parameters', async function () { await makeGetRequest({ url: server.url, token: server.accessToken, path, expectedStatus: HttpStatusCode.OK_200 }) }) @@ -193,7 +201,7 @@ describe('Test videos API validator', function () { support: 'my super support text', tags: [ 'tag1', 'tag2' ], privacy: VideoPrivacy.PUBLIC, - channelId: channelId, + channelId, originallyPublishedAt: new Date().toISOString() } }) @@ -207,7 +215,7 @@ describe('Test videos API validator', function () { }) it('Should fail without name', async function () { - const fields = omit(baseCorrectParams, 'name') + const fields = omit(baseCorrectParams, [ 'name' ]) const attaches = baseCorrectAttaches await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) @@ -256,7 +264,7 @@ describe('Test videos API validator', function () { }) it('Should fail without a channel', async function () { - const fields = omit(baseCorrectParams, 'channelId') + const fields = omit(baseCorrectParams, [ 'channelId' ]) const attaches = baseCorrectAttaches await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) @@ -773,6 +781,19 @@ describe('Test videos API validator', function () { await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields }) }) + it('Should fail with a private video of another user', async function () { + const fields = { + rating: 'like' + } + await makePutBodyRequest({ + url: server.url, + path: path + privateVideo.uuid + '/rate', + token: userAccessToken, + fields, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) + }) + it('Should succeed with the correct parameters', async function () { const fields = { rating: 'like'