Verified Commit 12edc149 authored by Chocobozzz's avatar Chocobozzz
Browse files

Introduce comments command

parent a5461888
import { registerTSPaths } from '../server/helpers/register-ts-paths'
registerTSPaths()
import * as autocannon from 'autocannon'
import {
addVideoCommentReply,
addVideoCommentThread,
flushAndRunServer,
getVideosList,
killallServers,
ServerInfo,
setAccessTokensToServers,
uploadVideo
} from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models'
import { writeJson } from 'fs-extra'
import { flushAndRunServer, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils'
import { Video, VideoPrivacy } from '@shared/models'
import { registerTSPaths } from '../server/helpers/register-ts-paths'
registerTSPaths()
let server: ServerInfo
let video: Video
......@@ -228,18 +219,17 @@ async function prepare () {
for (let i = 0; i < 10; i++) {
const text = 'my super first comment'
const res = await addVideoCommentThread(server.url, server.accessToken, video.id, text)
threadId = res.body.comment.id
const created = await server.commentsCommand.createThread({ videoId: video.id, text })
threadId = created.id
const text1 = 'my super answer to thread 1'
const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, video.id, threadId, text1)
const childCommentId = childCommentRes.body.comment.id
const child = await server.commentsCommand.addReply({ videoId: video.id, toCommentId: threadId, text: text1 })
const text2 = 'my super answer to answer of thread 1'
await addVideoCommentReply(server.url, server.accessToken, video.id, childCommentId, text2)
await server.commentsCommand.addReply({ videoId: video.id, toCommentId: child.id, text: text2 })
const text3 = 'my second answer to thread 1'
await addVideoCommentReply(server.url, server.accessToken, video.id, threadId, text3)
await server.commentsCommand.addReply({ videoId: video.id, toCommentId: threadId, text: text3 })
}
for (const caption of [ 'ar', 'fr', 'en', 'zh' ]) {
......
import * as express from 'express'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { ResultList, ThreadsResultList, UserRight } from '../../../../shared/models'
import { VideoCommentCreate } from '../../../../shared/models/videos/comment/video-comment.model'
import { ResultList, ThreadsResultList, UserRight, VideoCommentCreate } from '../../../../shared/models'
import { VideoCommentThreads } from '../../../../shared/models/videos/comment/video-comment.model'
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
import { getFormattedObjects } from '../../../helpers/utils'
import { sequelizeTypescript } from '../../../initializers/database'
......@@ -136,7 +136,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) {
return res.json({
...getFormattedObjects(resultList.data, resultList.total),
totalNotDeletedComments: resultList.totalNotDeletedComments
})
} as VideoCommentThreads)
}
async function listVideoThreadComments (req: express.Request, res: express.Response) {
......
......@@ -23,7 +23,7 @@ import { ActivityCreate } from '../../shared/models/activitypub'
import { VideoObject } from '../../shared/models/activitypub/objects'
import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object'
import { LiveVideoCreate, VideoCreate, VideoImportCreate } from '../../shared/models/videos'
import { VideoCommentCreate } from '../../shared/models/videos/comment/video-comment.model'
import { VideoCommentCreate } from '../../shared/models/videos/comment'
import { ActorModel } from '../models/actor/actor'
import { UserModel } from '../models/user/user'
import { VideoModel } from '../models/video/video'
......
......@@ -7,16 +7,19 @@ import {
closeAllSequelize,
deleteAll,
doubleFollow,
flushAndRunMultipleServers,
getCount,
getVideo,
rateVideo,
selectQuery,
ServerInfo,
setAccessTokensToServers,
setVideoField,
updateQuery,
wait
} from '../../../../shared/extra-utils'
import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { addVideoCommentThread, getVideoCommentThreads } from '../../../../shared/extra-utils/videos/video-comments'
import { getVideo, rateVideo, uploadVideoAndGetId } from '../../../../shared/extra-utils/videos/videos'
uploadVideoAndGetId,
wait,
waitJobs
} from '@shared/extra-utils'
const expect = chai.expect
......@@ -63,7 +66,7 @@ describe('Test AP cleaner', function () {
for (const server of servers) {
for (const uuid of videoUUIDs) {
await rateVideo(server.url, server.accessToken, uuid, 'like')
await addVideoCommentThread(server.url, server.accessToken, uuid, 'comment')
await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' })
}
}
......@@ -172,8 +175,8 @@ describe('Test AP cleaner', function () {
this.timeout(20000)
{
const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5)
expect(res.body.total).to.equal(3)
const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 })
expect(total).to.equal(3)
}
await deleteAll(servers[2].internalServerNumber, 'videoComment')
......@@ -182,8 +185,8 @@ describe('Test AP cleaner', function () {
await waitJobs(servers)
{
const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5)
expect(res.body.total).to.equal(2)
const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 })
expect(total).to.equal(2)
}
})
......
......@@ -2,9 +2,11 @@
import 'mocha'
import * as chai from 'chai'
import { VideoCreateResult } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { HttpStatusCode } from '@shared/core-utils'
import {
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
createUser,
flushAndRunServer,
......@@ -15,13 +17,8 @@ import {
setAccessTokensToServers,
uploadVideo,
userLogin
} from '../../../../shared/extra-utils'
import {
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination
} from '../../../../shared/extra-utils/requests/check-api-params'
import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
} from '@shared/extra-utils'
import { VideoCreateResult } from '@shared/models'
const expect = chai.expect
......@@ -50,8 +47,8 @@ describe('Test video comments API validator', function () {
}
{
const res = await addVideoCommentThread(server.url, server.accessToken, video.uuid, 'coucou')
commentId = res.body.comment.id
const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'coucou' })
commentId = created.id
pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId
}
......@@ -281,8 +278,8 @@ describe('Test video comments API validator', function () {
let commentToDelete: number
{
const res = await addVideoCommentThread(server.url, userAccessToken, video.uuid, 'hello')
commentToDelete = res.body.comment.id
const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'hello' })
commentToDelete = created.id
}
const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete
......@@ -301,8 +298,8 @@ describe('Test video comments API validator', function () {
}
{
const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello')
commentToDelete = res.body.comment.id
const created = await server.commentsCommand.createThread({ videoId: anotherVideoUUID, text: 'hello' })
commentToDelete = created.id
}
const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
......
......@@ -4,14 +4,11 @@ import 'mocha'
import * as chai from 'chai'
import {
AbusesCommand,
addVideoCommentThread,
cleanupTests,
createUser,
deleteVideoComment,
doubleFollow,
flushAndRunMultipleServers,
generateUserAccessToken,
getVideoCommentThreads,
getVideoIdFromUUID,
getVideosList,
removeUser,
......@@ -23,7 +20,7 @@ import {
userLogin,
waitJobs
} from '@shared/extra-utils'
import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'
import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
const expect = chai.expect
......@@ -399,14 +396,14 @@ describe('Test abuses', function () {
describe('Comment abuses', function () {
async function getComment (url: string, videoIdArg: number | string) {
async function getComment (server: ServerInfo, videoIdArg: number | string) {
const videoId = typeof videoIdArg === 'string'
? await getVideoIdFromUUID(url, videoIdArg)
? await getVideoIdFromUUID(server.url, videoIdArg)
: videoIdArg
const res = await getVideoCommentThreads(url, videoId, 0, 5)
const { data } = await server.commentsCommand.listThreads({ videoId })
return res.body.data[0] as VideoComment
return data[0]
}
before(async function () {
......@@ -415,8 +412,8 @@ describe('Test abuses', function () {
servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1')
await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2')
await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
await waitJobs(servers)
})
......@@ -424,7 +421,7 @@ describe('Test abuses', function () {
it('Should report abuse on a comment', async function () {
this.timeout(15000)
const comment = await getComment(servers[0].url, servers[0].video.id)
const comment = await getComment(servers[0], servers[0].video.id)
const reason = 'it is a bad comment'
await commands[0].report({ commentId: comment.id, reason })
......@@ -434,7 +431,7 @@ describe('Test abuses', function () {
it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
{
const comment = await getComment(servers[0].url, servers[0].video.id)
const comment = await getComment(servers[0], servers[0].video.id)
const body = await commands[0].getAdminList({ filter: 'comment' })
expect(body.total).to.equal(1)
......@@ -469,7 +466,7 @@ describe('Test abuses', function () {
it('Should report abuse on a remote comment', async function () {
this.timeout(10000)
const comment = await getComment(servers[0].url, servers[1].video.uuid)
const comment = await getComment(servers[0], servers[1].video.uuid)
const reason = 'it is a really bad comment'
await commands[0].report({ commentId: comment.id, reason })
......@@ -478,7 +475,7 @@ describe('Test abuses', function () {
})
it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
const commentServer2 = await getComment(servers[0], servers[1].video.id)
{
const body = await commands[0].getAdminList({ filter: 'comment' })
......@@ -537,9 +534,9 @@ describe('Test abuses', function () {
it('Should keep the comment abuse when deleting the comment', async function () {
this.timeout(10000)
const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
const commentServer2 = await getComment(servers[0], servers[1].video.id)
await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id)
await servers[0].commentsCommand.delete({ videoId: servers[1].video.uuid, commentId: commentServer2.id })
await waitJobs(servers)
......
......@@ -3,7 +3,6 @@
import 'mocha'
import * as chai from 'chai'
import {
addVideoCommentThread,
cleanupTests,
createUser,
doubleFollow,
......@@ -59,7 +58,11 @@ describe('Test blocklist', function () {
}
{
await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello')
await servers[1].commentsCommand.createThread({
token: remoteUserToken,
videoId: videoUUID,
text: '@user2@' + servers[0].host + ' hello'
})
}
{
......
This diff is collapsed.
......@@ -3,14 +3,10 @@
import 'mocha'
import * as chai from 'chai'
import {
addVideoCommentReply,
addVideoCommentThread,
checkCommentMention,
CheckerBaseParams,
checkNewCommentOnMyVideo,
cleanupTests,
getVideoCommentThreads,
getVideoThreadComments,
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
......@@ -18,13 +14,13 @@ import {
uploadVideo,
waitJobs
} from '@shared/extra-utils'
import { UserNotification, VideoCommentThreadTree } from '@shared/models'
import { UserNotification } from '@shared/models'
const expect = chai.expect
describe('Test comments notifications', function () {
let servers: ServerInfo[] = []
let userAccessToken: string
let userToken: string
let userNotifications: UserNotification[] = []
let emails: object[] = []
......@@ -38,7 +34,7 @@ describe('Test comments notifications', function () {
const res = await prepareNotificationsTest(2)
emails = res.emails
userAccessToken = res.userAccessToken
userToken = res.userAccessToken
servers = res.servers
userNotifications = res.userNotifications
})
......@@ -51,7 +47,7 @@ describe('Test comments notifications', function () {
server: servers[0],
emails,
socketNotifications: userNotifications,
token: userAccessToken
token: userToken
}
})
......@@ -61,8 +57,8 @@ describe('Test comments notifications', function () {
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
const commentId = resComment.body.comment.id
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
......@@ -71,11 +67,11 @@ describe('Test comments notifications', function () {
it('Should not send a new comment notification if I comment my own video', async function () {
this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
const commentId = resComment.body.comment.id
const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
const commentId = created.id
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
......@@ -84,28 +80,28 @@ describe('Test comments notifications', function () {
it('Should not send a new comment notification if the account is muted', async function () {
this.timeout(20000)
await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
const commentId = resComment.body.comment.id
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })
await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
})
it('Should send a new comment notification after a local comment on my video', async function () {
this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
const commentId = resComment.body.comment.id
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
......@@ -114,33 +110,31 @@ describe('Test comments notifications', function () {
it('Should send a new comment notification after a remote comment on my video', async function () {
this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
await waitJobs(servers)
await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
await waitJobs(servers)
const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
expect(resComment.body.data).to.have.lengthOf(1)
const commentId = resComment.body.data[0].id
const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
expect(data).to.have.lengthOf(1)
const commentId = data[0].id
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
})
it('Should send a new comment notification after a local reply on my video', async function () {
this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
const threadId = resThread.body.comment.id
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
const commentId = resComment.body.comment.id
const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
......@@ -149,24 +143,23 @@ describe('Test comments notifications', function () {
it('Should send a new comment notification after a remote reply on my video', async function () {
this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
await waitJobs(servers)
{
const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
const threadId = resThread.body.comment.id
await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
const created = await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
const threadId = created.id
await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
}
await waitJobs(servers)
const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
expect(resThread.body.data).to.have.lengthOf(1)
const threadId = resThread.body.data[0].id
const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
expect(data).to.have.lengthOf(1)
const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
const tree = resComments.body as VideoCommentThreadTree
const threadId = data[0].id
const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId })
expect(tree.children).to.have.lengthOf(1)
const commentId = tree.children[0].comment.id
......@@ -177,10 +170,10 @@ describe('Test comments notifications', function () {
it('Should convert markdown in comment to html', async function () {
this.timeout(20000)
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'cool video' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' })
const uuid = resVideo.body.video.uuid
await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, commentText)
await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText })
await waitJobs(servers)
......@@ -197,7 +190,7 @@ describe('Test comments notifications', function () {
server: servers[0],
emails,
socketNotifications: userNotifications,
token: userAccessToken
token: userToken
}
await updateMyUser({
......@@ -216,11 +209,10 @@ describe('Test comments notifications', function () {
it('Should not send a new mention comment notification if I mention the video owner', async function () {
this.timeout(10000)
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
const commentId = resComment.body.comment.id
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
......@@ -232,8 +224,7 @@ describe('Test comments notifications', function () {
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
const commentId = resComment.body.comment.id
const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
......@@ -242,18 +233,17 @@ describe('Test comments notifications', function () {
it('Should not send a new mention notification if the account is muted', async function () {
this.timeout(10000)
await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
const uuid = resVideo