From 47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Jan 2018 10:12:36 +0100 Subject: Add ability to disable video comments --- server/tests/api/check-params/users.ts | 16 +++++++---- server/tests/api/check-params/video-comments.ts | 35 ++++++++++++++++++++++--- server/tests/api/check-params/videos.ts | 22 ++++++++++++++++ server/tests/api/server/follows.ts | 1 + server/tests/api/videos/multiple-servers.ts | 27 +++++++++++++++++++ server/tests/api/videos/single-server.ts | 5 +++- 6 files changed, 97 insertions(+), 9 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 44412ad82..33d92ac24 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -2,14 +2,13 @@ import { omit } from 'lodash' import 'mocha' -import { join } from "path" +import { join } from 'path' import { UserRole } from '../../../../shared' import { createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, makePostBodyRequest, makePostUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, - updateUser, - uploadVideo, userLogin + updateUser, uploadVideo, userLogin } from '../../utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' @@ -25,7 +24,7 @@ describe('Test users API validators', function () { // --------------------------------------------------------------- before(async function () { - this.timeout(120000) + this.timeout(20000) await flushTests() @@ -282,7 +281,14 @@ describe('Test users API validators', function () { const attaches = { 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar.png') } - await makePostUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) + await makePostUploadRequest({ + url: server.url, + path: path + '/me/avatar/pick', + token: server.accessToken, + fields, + attaches, + statusCodeExpected: 200 + }) }) }) diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index cdb48a276..c11660d07 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -1,5 +1,6 @@ /* tslint:disable:no-unused-expression */ +import * as chai from 'chai' import 'mocha' import { flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, @@ -8,6 +9,8 @@ import { import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' import { addVideoCommentThread } from '../../utils/videos/video-comments' +const expect = chai.expect + describe('Test video comments API validator', function () { let pathThread: string let pathComment: string @@ -42,17 +45,14 @@ describe('Test video comments API validator', function () { describe('When listing video comment threads', function () { it('Should fail with a bad start pagination', async function () { await checkBadStartPagination(server.url, pathThread, server.accessToken) - }) it('Should fail with a bad count pagination', async function () { await checkBadCountPagination(server.url, pathThread, server.accessToken) - }) it('Should fail with an incorrect sort', async function () { await checkBadSortPagination(server.url, pathThread, server.accessToken) - }) it('Should fail with an incorrect video', async function () { @@ -185,6 +185,35 @@ describe('Test video comments API validator', function () { }) }) + describe('When a video has comments disabled', function () { + before(async function () { + const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) + videoUUID = res.body.video.uuid + pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads' + }) + + it('Should return an empty thread list', async function () { + const res = await makeGetRequest({ + url: server.url, + path: pathThread, + statusCodeExpected: 200 + }) + expect(res.body.total).to.equal(0) + expect(res.body.data).to.have.lengthOf(0) + }) + + it('Should return an thread comments list') + + it('Should return conflict on thread add', async function () { + const fields = { + text: 'super comment' + } + await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 }) + }) + + it('Should return conflict on comment thread add') + }) + after(async function () { killallServers([ server ]) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index b9484afc4..5c067dc96 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -100,6 +100,7 @@ describe('Test videos API validator', function () { licence: 1, language: 6, nsfw: false, + commentsEnabled: true, description: 'my super description', tags: [ 'tag1', 'tag2' ], privacy: VideoPrivacy.PUBLIC, @@ -162,6 +163,20 @@ describe('Test videos API validator', function () { await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) + it('Should fail without commentsEnabled attribute', async function () { + const fields = omit(baseCorrectParams, 'commentsEnabled') + const attaches = baseCorrectAttaches + + await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + + it('Should fail with a bad commentsEnabled attribute', async function () { + const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 }) + const attaches = baseCorrectAttaches + + await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + it('Should fail with a long description', async function () { const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) const attaches = baseCorrectAttaches @@ -291,6 +306,7 @@ describe('Test videos API validator', function () { licence: 2, language: 6, nsfw: false, + commentsEnabled: false, description: 'my super description', privacy: VideoPrivacy.PUBLIC, tags: [ 'tag1', 'tag2' ] @@ -354,6 +370,12 @@ describe('Test videos API validator', function () { await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) + it('Should fail with a bad commentsEnabled attribute', async function () { + const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 }) + + await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) + }) + it('Should fail with a long description', async function () { const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index fc9c5c3b6..e6dfd5f62 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -246,6 +246,7 @@ describe('Test follows', function () { host: 'localhost:9003', account: 'root', isLocal, + commentsEnabled: true, duration: 5, tags: [ 'tag1', 'tag2', 'tag3' ], privacy: VideoPrivacy.PUBLIC, diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index abd051a30..b6dfe0d1b 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -93,6 +93,7 @@ describe('Test multiple servers', function () { duration: 10, tags: [ 'tag1p1', 'tag2p1' ], privacy: VideoPrivacy.PUBLIC, + commentsEnabled: true, channel: { name: 'my channel', description: 'super channel', @@ -155,6 +156,7 @@ describe('Test multiple servers', function () { host: 'localhost:9002', account: 'user1', isLocal, + commentsEnabled: true, duration: 5, tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], privacy: VideoPrivacy.PUBLIC, @@ -254,6 +256,7 @@ describe('Test multiple servers', function () { account: 'root', isLocal, duration: 5, + commentsEnabled: true, tags: [ 'tag1p3' ], privacy: VideoPrivacy.PUBLIC, channel: { @@ -280,6 +283,7 @@ describe('Test multiple servers', function () { description: 'my super description for server 3-2', host: 'localhost:9003', account: 'root', + commentsEnabled: true, isLocal, duration: 5, tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], @@ -545,6 +549,7 @@ describe('Test multiple servers', function () { account: 'root', isLocal, duration: 5, + commentsEnabled: true, tags: [ 'tag_up_1', 'tag_up_2' ], privacy: VideoPrivacy.PUBLIC, channel: { @@ -732,6 +737,26 @@ describe('Test multiple servers', function () { expect(secondChild.children).to.have.lengthOf(0) } }) + + it('Should disable comments', async function () { + this.timeout(20000) + + const attributes = { + commentsEnabled: false + } + + await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) + + await wait(5000) + + for (const server of servers) { + const res = await getVideo(server.url, videoUUID) + expect(res.body.commentsEnabled).to.be.false + + const text = 'my super forbidden comment' + await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409) + } + }) }) describe('With minimum parameters', function () { @@ -748,6 +773,7 @@ describe('Test multiple servers', function () { .field('privacy', '1') .field('nsfw', 'false') .field('channelId', '1') + .field('commentsEnabled', 'true') const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm') @@ -772,6 +798,7 @@ describe('Test multiple servers', function () { account: 'root', isLocal, duration: 5, + commentsEnabled: true, tags: [ ], privacy: VideoPrivacy.PUBLIC, channel: { diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 2a3126f32..0a0c95750 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -32,6 +32,7 @@ describe('Test a single server', function () { duration: 5, tags: [ 'tag1', 'tag2', 'tag3' ], privacy: VideoPrivacy.PUBLIC, + commentsEnabled: true, channel: { name: 'Default root channel', description: '', @@ -51,7 +52,7 @@ describe('Test a single server', function () { category: 4, licence: 2, language: 5, - nsfw: true, + nsfw: false, description: 'my super description updated', host: 'localhost:9001', account: 'root', @@ -59,6 +60,7 @@ describe('Test a single server', function () { tags: [ 'tagup1', 'tagup2' ], privacy: VideoPrivacy.PUBLIC, duration: 5, + commentsEnabled: false, channel: { name: 'Default root channel', description: '', @@ -475,6 +477,7 @@ describe('Test a single server', function () { language: 5, nsfw: false, description: 'my super description updated', + commentsEnabled: false, tags: [ 'tagup1', 'tagup2' ] } await updateVideo(server.url, server.accessToken, videoId, attributes) -- cgit v1.2.3