Introduce comments command
This commit is contained in:
parent
a54618880c
commit
12edc1495a
|
@ -1,19 +1,10 @@
|
||||||
import { registerTSPaths } from '../server/helpers/register-ts-paths'
|
|
||||||
registerTSPaths()
|
|
||||||
|
|
||||||
import * as autocannon from 'autocannon'
|
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 { 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 server: ServerInfo
|
||||||
let video: Video
|
let video: Video
|
||||||
|
@ -228,18 +219,17 @@ async function prepare () {
|
||||||
|
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
const text = 'my super first comment'
|
const text = 'my super first comment'
|
||||||
const res = await addVideoCommentThread(server.url, server.accessToken, video.id, text)
|
const created = await server.commentsCommand.createThread({ videoId: video.id, text })
|
||||||
threadId = res.body.comment.id
|
threadId = created.id
|
||||||
|
|
||||||
const text1 = 'my super answer to thread 1'
|
const text1 = 'my super answer to thread 1'
|
||||||
const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, video.id, threadId, text1)
|
const child = await server.commentsCommand.addReply({ videoId: video.id, toCommentId: threadId, text: text1 })
|
||||||
const childCommentId = childCommentRes.body.comment.id
|
|
||||||
|
|
||||||
const text2 = 'my super answer to answer of thread 1'
|
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'
|
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' ]) {
|
for (const caption of [ 'ar', 'fr', 'en', 'zh' ]) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
import { ResultList, ThreadsResultList, UserRight } from '../../../../shared/models'
|
import { ResultList, ThreadsResultList, UserRight, VideoCommentCreate } from '../../../../shared/models'
|
||||||
import { VideoCommentCreate } from '../../../../shared/models/videos/comment/video-comment.model'
|
import { VideoCommentThreads } from '../../../../shared/models/videos/comment/video-comment.model'
|
||||||
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
|
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
|
||||||
import { getFormattedObjects } from '../../../helpers/utils'
|
import { getFormattedObjects } from '../../../helpers/utils'
|
||||||
import { sequelizeTypescript } from '../../../initializers/database'
|
import { sequelizeTypescript } from '../../../initializers/database'
|
||||||
|
@ -136,7 +136,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) {
|
||||||
return res.json({
|
return res.json({
|
||||||
...getFormattedObjects(resultList.data, resultList.total),
|
...getFormattedObjects(resultList.data, resultList.total),
|
||||||
totalNotDeletedComments: resultList.totalNotDeletedComments
|
totalNotDeletedComments: resultList.totalNotDeletedComments
|
||||||
})
|
} as VideoCommentThreads)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listVideoThreadComments (req: express.Request, res: express.Response) {
|
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 { VideoObject } from '../../shared/models/activitypub/objects'
|
||||||
import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object'
|
import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object'
|
||||||
import { LiveVideoCreate, VideoCreate, VideoImportCreate } from '../../shared/models/videos'
|
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 { ActorModel } from '../models/actor/actor'
|
||||||
import { UserModel } from '../models/user/user'
|
import { UserModel } from '../models/user/user'
|
||||||
import { VideoModel } from '../models/video/video'
|
import { VideoModel } from '../models/video/video'
|
||||||
|
|
|
@ -7,16 +7,19 @@ import {
|
||||||
closeAllSequelize,
|
closeAllSequelize,
|
||||||
deleteAll,
|
deleteAll,
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
|
flushAndRunMultipleServers,
|
||||||
getCount,
|
getCount,
|
||||||
|
getVideo,
|
||||||
|
rateVideo,
|
||||||
selectQuery,
|
selectQuery,
|
||||||
|
ServerInfo,
|
||||||
|
setAccessTokensToServers,
|
||||||
setVideoField,
|
setVideoField,
|
||||||
updateQuery,
|
updateQuery,
|
||||||
wait
|
uploadVideoAndGetId,
|
||||||
} from '../../../../shared/extra-utils'
|
wait,
|
||||||
import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
|
waitJobs
|
||||||
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
} from '@shared/extra-utils'
|
||||||
import { addVideoCommentThread, getVideoCommentThreads } from '../../../../shared/extra-utils/videos/video-comments'
|
|
||||||
import { getVideo, rateVideo, uploadVideoAndGetId } from '../../../../shared/extra-utils/videos/videos'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
|
@ -63,7 +66,7 @@ describe('Test AP cleaner', function () {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
for (const uuid of videoUUIDs) {
|
for (const uuid of videoUUIDs) {
|
||||||
await rateVideo(server.url, server.accessToken, uuid, 'like')
|
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)
|
this.timeout(20000)
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5)
|
const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 })
|
||||||
expect(res.body.total).to.equal(3)
|
expect(total).to.equal(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
await deleteAll(servers[2].internalServerNumber, 'videoComment')
|
await deleteAll(servers[2].internalServerNumber, 'videoComment')
|
||||||
|
@ -182,8 +185,8 @@ describe('Test AP cleaner', function () {
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5)
|
const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 })
|
||||||
expect(res.body.total).to.equal(2)
|
expect(total).to.equal(2)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import { VideoCreateResult } from '@shared/models'
|
import { HttpStatusCode } from '@shared/core-utils'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
|
||||||
import {
|
import {
|
||||||
|
checkBadCountPagination,
|
||||||
|
checkBadSortPagination,
|
||||||
|
checkBadStartPagination,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
|
@ -15,13 +17,8 @@ import {
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
userLogin
|
userLogin
|
||||||
} from '../../../../shared/extra-utils'
|
} from '@shared/extra-utils'
|
||||||
import {
|
import { VideoCreateResult } from '@shared/models'
|
||||||
checkBadCountPagination,
|
|
||||||
checkBadSortPagination,
|
|
||||||
checkBadStartPagination
|
|
||||||
} from '../../../../shared/extra-utils/requests/check-api-params'
|
|
||||||
import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
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')
|
const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'coucou' })
|
||||||
commentId = res.body.comment.id
|
commentId = created.id
|
||||||
pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId
|
pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,8 +278,8 @@ describe('Test video comments API validator', function () {
|
||||||
let commentToDelete: number
|
let commentToDelete: number
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await addVideoCommentThread(server.url, userAccessToken, video.uuid, 'hello')
|
const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'hello' })
|
||||||
commentToDelete = res.body.comment.id
|
commentToDelete = created.id
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete
|
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')
|
const created = await server.commentsCommand.createThread({ videoId: anotherVideoUUID, text: 'hello' })
|
||||||
commentToDelete = res.body.comment.id
|
commentToDelete = created.id
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
|
const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
|
||||||
|
|
|
@ -4,14 +4,11 @@ import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import {
|
import {
|
||||||
AbusesCommand,
|
AbusesCommand,
|
||||||
addVideoCommentThread,
|
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
deleteVideoComment,
|
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
generateUserAccessToken,
|
generateUserAccessToken,
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideoIdFromUUID,
|
getVideoIdFromUUID,
|
||||||
getVideosList,
|
getVideosList,
|
||||||
removeUser,
|
removeUser,
|
||||||
|
@ -23,7 +20,7 @@ import {
|
||||||
userLogin,
|
userLogin,
|
||||||
waitJobs
|
waitJobs
|
||||||
} from '@shared/extra-utils'
|
} 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
|
const expect = chai.expect
|
||||||
|
|
||||||
|
@ -399,14 +396,14 @@ describe('Test abuses', function () {
|
||||||
|
|
||||||
describe('Comment 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'
|
const videoId = typeof videoIdArg === 'string'
|
||||||
? await getVideoIdFromUUID(url, videoIdArg)
|
? await getVideoIdFromUUID(server.url, videoIdArg)
|
||||||
: 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 () {
|
before(async function () {
|
||||||
|
@ -415,8 +412,8 @@ describe('Test abuses', function () {
|
||||||
servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
|
servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
|
||||||
servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
|
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 servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
|
||||||
await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2')
|
await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
})
|
})
|
||||||
|
@ -424,7 +421,7 @@ describe('Test abuses', function () {
|
||||||
it('Should report abuse on a comment', async function () {
|
it('Should report abuse on a comment', async function () {
|
||||||
this.timeout(15000)
|
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'
|
const reason = 'it is a bad comment'
|
||||||
await commands[0].report({ commentId: comment.id, reason })
|
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 () {
|
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' })
|
const body = await commands[0].getAdminList({ filter: 'comment' })
|
||||||
|
|
||||||
expect(body.total).to.equal(1)
|
expect(body.total).to.equal(1)
|
||||||
|
@ -469,7 +466,7 @@ describe('Test abuses', function () {
|
||||||
it('Should report abuse on a remote comment', async function () {
|
it('Should report abuse on a remote comment', async function () {
|
||||||
this.timeout(10000)
|
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'
|
const reason = 'it is a really bad comment'
|
||||||
await commands[0].report({ commentId: comment.id, reason })
|
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 () {
|
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' })
|
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 () {
|
it('Should keep the comment abuse when deleting the comment', async function () {
|
||||||
this.timeout(10000)
|
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)
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import {
|
import {
|
||||||
addVideoCommentThread,
|
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
doubleFollow,
|
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'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,55 +3,47 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import {
|
import {
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
BlocklistCommand,
|
BlocklistCommand,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
|
CommentsCommand,
|
||||||
createUser,
|
createUser,
|
||||||
deleteVideoComment,
|
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
findCommentId,
|
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
getUserNotifications,
|
getUserNotifications,
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideosList,
|
getVideosList,
|
||||||
getVideosListWithToken,
|
getVideosListWithToken,
|
||||||
getVideoThreadComments,
|
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
userLogin,
|
userLogin,
|
||||||
waitJobs
|
waitJobs
|
||||||
} from '@shared/extra-utils'
|
} from '@shared/extra-utils'
|
||||||
import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models'
|
import { UserNotification, UserNotificationType, Video } from '@shared/models'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
async function checkAllVideos (url: string, token: string) {
|
async function checkAllVideos (server: ServerInfo, token: string) {
|
||||||
{
|
{
|
||||||
const res = await getVideosListWithToken(url, token)
|
const res = await getVideosListWithToken(server.url, token)
|
||||||
|
|
||||||
expect(res.body.data).to.have.lengthOf(5)
|
expect(res.body.data).to.have.lengthOf(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideosList(url)
|
const res = await getVideosList(server.url)
|
||||||
|
|
||||||
expect(res.body.data).to.have.lengthOf(5)
|
expect(res.body.data).to.have.lengthOf(5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkAllComments (url: string, token: string, videoUUID: string) {
|
async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) {
|
||||||
const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token)
|
const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
|
||||||
|
|
||||||
const allThreads: VideoComment[] = resThreads.body.data
|
const threads = data.filter(t => t.isDeleted === false)
|
||||||
const threads = allThreads.filter(t => t.isDeleted === false)
|
|
||||||
expect(threads).to.have.lengthOf(2)
|
expect(threads).to.have.lengthOf(2)
|
||||||
|
|
||||||
for (const thread of threads) {
|
for (const thread of threads) {
|
||||||
const res = await getVideoThreadComments(url, videoUUID, thread.id, token)
|
const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = res.body
|
|
||||||
expect(tree.children).to.have.lengthOf(1)
|
expect(tree.children).to.have.lengthOf(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,10 +53,9 @@ async function checkCommentNotification (
|
||||||
comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
|
comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
|
||||||
check: 'presence' | 'absence'
|
check: 'presence' | 'absence'
|
||||||
) {
|
) {
|
||||||
const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text)
|
const command = comment.server.commentsCommand
|
||||||
const created = resComment.body.comment as VideoComment
|
|
||||||
const threadId = created.id
|
const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
|
||||||
const createdAt = created.createdAt
|
|
||||||
|
|
||||||
await waitJobs([ mainServer, comment.server ])
|
await waitJobs([ mainServer, comment.server ])
|
||||||
|
|
||||||
|
@ -75,7 +66,7 @@ async function checkCommentNotification (
|
||||||
if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
|
if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
|
||||||
else expect(commentNotifications).to.have.lengthOf(0)
|
else expect(commentNotifications).to.have.lengthOf(0)
|
||||||
|
|
||||||
await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId)
|
await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
|
||||||
|
|
||||||
await waitJobs([ mainServer, comment.server ])
|
await waitJobs([ mainServer, comment.server ])
|
||||||
}
|
}
|
||||||
|
@ -90,6 +81,7 @@ describe('Test blocklist', function () {
|
||||||
let userToken2: string
|
let userToken2: string
|
||||||
|
|
||||||
let command: BlocklistCommand
|
let command: BlocklistCommand
|
||||||
|
let commentsCommand: CommentsCommand[]
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(120000)
|
this.timeout(120000)
|
||||||
|
@ -97,6 +89,9 @@ describe('Test blocklist', function () {
|
||||||
servers = await flushAndRunMultipleServers(3)
|
servers = await flushAndRunMultipleServers(3)
|
||||||
await setAccessTokensToServers(servers)
|
await setAccessTokensToServers(servers)
|
||||||
|
|
||||||
|
command = servers[0].blocklistCommand
|
||||||
|
commentsCommand = servers.map(s => s.commentsCommand)
|
||||||
|
|
||||||
{
|
{
|
||||||
const user = { username: 'user1', password: 'password' }
|
const user = { username: 'user1', password: 'password' }
|
||||||
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
||||||
|
@ -139,30 +134,33 @@ describe('Test blocklist', function () {
|
||||||
await doubleFollow(servers[0], servers[2])
|
await doubleFollow(servers[0], servers[2])
|
||||||
|
|
||||||
{
|
{
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1')
|
const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
|
||||||
const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1')
|
const reply = await commentsCommand[0].addReply({
|
||||||
await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1')
|
token: userToken1,
|
||||||
|
videoId: videoUUID1,
|
||||||
|
toCommentId: created.id,
|
||||||
|
text: 'comment user 1'
|
||||||
|
})
|
||||||
|
await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1')
|
const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
|
||||||
await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1')
|
await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' })
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
command = servers[0].blocklistCommand
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('User blocklist', function () {
|
describe('User blocklist', function () {
|
||||||
|
|
||||||
describe('When managing account blocklist', function () {
|
describe('When managing account blocklist', function () {
|
||||||
it('Should list all videos', function () {
|
it('Should list all videos', function () {
|
||||||
return checkAllVideos(servers[0].url, servers[0].accessToken)
|
return checkAllVideos(servers[0], servers[0].accessToken)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list the comments', function () {
|
it('Should list the comments', function () {
|
||||||
return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should block a remote account', async function () {
|
it('Should block a remote account', async function () {
|
||||||
|
@ -194,19 +192,26 @@ describe('Test blocklist', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should hide its comments', async function () {
|
it('Should hide its comments', async function () {
|
||||||
const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken)
|
const { data } = await commentsCommand[0].listThreads({
|
||||||
|
token: servers[0].accessToken,
|
||||||
|
videoId: videoUUID1,
|
||||||
|
start: 0,
|
||||||
|
count: 25,
|
||||||
|
sort: '-createdAt'
|
||||||
|
})
|
||||||
|
|
||||||
const threads: VideoComment[] = resThreads.body.data
|
expect(data).to.have.lengthOf(1)
|
||||||
expect(threads).to.have.lengthOf(1)
|
expect(data[0].totalReplies).to.equal(1)
|
||||||
expect(threads[0].totalReplies).to.equal(1)
|
|
||||||
|
|
||||||
const t = threads.find(t => t.text === 'comment user 1')
|
const t = data.find(t => t.text === 'comment user 1')
|
||||||
expect(t).to.be.undefined
|
expect(t).to.be.undefined
|
||||||
|
|
||||||
for (const thread of threads) {
|
for (const thread of data) {
|
||||||
const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken)
|
const tree = await commentsCommand[0].getThread({
|
||||||
|
videoId: videoUUID1,
|
||||||
const tree: VideoCommentThreadTree = res.body
|
threadId: thread.id,
|
||||||
|
token: servers[0].accessToken
|
||||||
|
})
|
||||||
expect(tree.children).to.have.lengthOf(0)
|
expect(tree.children).to.have.lengthOf(0)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -231,7 +236,7 @@ describe('Test blocklist', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list all the videos with another user', async function () {
|
it('Should list all the videos with another user', async function () {
|
||||||
return checkAllVideos(servers[0].url, userToken1)
|
return checkAllVideos(servers[0], userToken1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list blocked accounts', async function () {
|
it('Should list blocked accounts', async function () {
|
||||||
|
@ -264,32 +269,29 @@ describe('Test blocklist', function () {
|
||||||
this.timeout(60000)
|
this.timeout(60000)
|
||||||
|
|
||||||
{
|
{
|
||||||
await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2')
|
await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader')
|
await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader')
|
const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
|
||||||
const message = 'reply by user 2'
|
const message = 'reply by user 2'
|
||||||
const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message)
|
const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
|
||||||
await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply')
|
await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server 2 has all the comments
|
// Server 2 has all the comments
|
||||||
{
|
{
|
||||||
const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt')
|
const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
||||||
const threads: VideoComment[] = resThreads.body.data
|
|
||||||
|
|
||||||
expect(threads).to.have.lengthOf(2)
|
expect(data).to.have.lengthOf(2)
|
||||||
expect(threads[0].text).to.equal('uploader')
|
expect(data[0].text).to.equal('uploader')
|
||||||
expect(threads[1].text).to.equal('comment user 2')
|
expect(data[1].text).to.equal('comment user 2')
|
||||||
|
|
||||||
const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id)
|
const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = resReplies.body
|
|
||||||
expect(tree.children).to.have.lengthOf(1)
|
expect(tree.children).to.have.lengthOf(1)
|
||||||
expect(tree.children[0].comment.text).to.equal('reply by user 2')
|
expect(tree.children[0].comment.text).to.equal('reply by user 2')
|
||||||
expect(tree.children[0].children).to.have.lengthOf(1)
|
expect(tree.children[0].children).to.have.lengthOf(1)
|
||||||
|
@ -298,20 +300,15 @@ describe('Test blocklist', function () {
|
||||||
|
|
||||||
// Server 1 and 3 should only have uploader comments
|
// Server 1 and 3 should only have uploader comments
|
||||||
for (const server of [ servers[0], servers[2] ]) {
|
for (const server of [ servers[0], servers[2] ]) {
|
||||||
const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt')
|
const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
||||||
const threads: VideoComment[] = resThreads.body.data
|
|
||||||
|
|
||||||
expect(threads).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
expect(threads[0].text).to.equal('uploader')
|
expect(data[0].text).to.equal('uploader')
|
||||||
|
|
||||||
const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id)
|
const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = resReplies.body
|
if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
|
||||||
if (server.serverNumber === 1) {
|
else expect(tree.children).to.have.lengthOf(1)
|
||||||
expect(tree.children).to.have.lengthOf(0)
|
|
||||||
} else {
|
|
||||||
expect(tree.children).to.have.lengthOf(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -331,22 +328,19 @@ describe('Test blocklist', function () {
|
||||||
|
|
||||||
it('Should display its comments on my video', async function () {
|
it('Should display its comments on my video', async function () {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt')
|
const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
||||||
const threads: VideoComment[] = resThreads.body.data
|
|
||||||
|
|
||||||
// Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
|
// Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
|
||||||
if (server.serverNumber === 3) {
|
if (server.serverNumber === 3) {
|
||||||
expect(threads).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(threads).to.have.lengthOf(2)
|
expect(data).to.have.lengthOf(2)
|
||||||
expect(threads[0].text).to.equal('uploader')
|
expect(data[0].text).to.equal('uploader')
|
||||||
expect(threads[1].text).to.equal('comment user 2')
|
expect(data[1].text).to.equal('comment user 2')
|
||||||
|
|
||||||
const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id)
|
const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = resReplies.body
|
|
||||||
expect(tree.children).to.have.lengthOf(1)
|
expect(tree.children).to.have.lengthOf(1)
|
||||||
expect(tree.children[0].comment.text).to.equal('reply by user 2')
|
expect(tree.children[0].comment.text).to.equal('reply by user 2')
|
||||||
expect(tree.children[0].children).to.have.lengthOf(1)
|
expect(tree.children[0].children).to.have.lengthOf(1)
|
||||||
|
@ -359,7 +353,7 @@ describe('Test blocklist', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should display its comments', function () {
|
it('Should display its comments', function () {
|
||||||
return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have a notification from a non blocked account', async function () {
|
it('Should have a notification from a non blocked account', async function () {
|
||||||
|
@ -385,11 +379,11 @@ describe('Test blocklist', function () {
|
||||||
describe('When managing server blocklist', function () {
|
describe('When managing server blocklist', function () {
|
||||||
|
|
||||||
it('Should list all videos', function () {
|
it('Should list all videos', function () {
|
||||||
return checkAllVideos(servers[0].url, servers[0].accessToken)
|
return checkAllVideos(servers[0], servers[0].accessToken)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list the comments', function () {
|
it('Should list the comments', function () {
|
||||||
return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should block a remote server', async function () {
|
it('Should block a remote server', async function () {
|
||||||
|
@ -410,20 +404,19 @@ describe('Test blocklist', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list all the videos with another user', async function () {
|
it('Should list all the videos with another user', async function () {
|
||||||
return checkAllVideos(servers[0].url, userToken1)
|
return checkAllVideos(servers[0], userToken1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should hide its comments', async function () {
|
it('Should hide its comments', async function () {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
|
|
||||||
const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
|
const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
|
||||||
const threadId = resThreads.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||||
|
|
||||||
await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
|
await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have notifications from blocked server', async function () {
|
it('Should not have notifications from blocked server', async function () {
|
||||||
|
@ -460,11 +453,11 @@ describe('Test blocklist', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should display its videos', function () {
|
it('Should display its videos', function () {
|
||||||
return checkAllVideos(servers[0].url, servers[0].accessToken)
|
return checkAllVideos(servers[0], servers[0].accessToken)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should display its comments', function () {
|
it('Should display its comments', function () {
|
||||||
return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have notification from unblocked server', async function () {
|
it('Should have notification from unblocked server', async function () {
|
||||||
|
@ -493,13 +486,13 @@ describe('Test blocklist', function () {
|
||||||
describe('When managing account blocklist', function () {
|
describe('When managing account blocklist', function () {
|
||||||
it('Should list all videos', async function () {
|
it('Should list all videos', async function () {
|
||||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||||
await checkAllVideos(servers[0].url, token)
|
await checkAllVideos(servers[0], token)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list the comments', async function () {
|
it('Should list the comments', async function () {
|
||||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||||
await checkAllComments(servers[0].url, token, videoUUID1)
|
await checkAllComments(servers[0], token, videoUUID1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -537,10 +530,8 @@ describe('Test blocklist', function () {
|
||||||
|
|
||||||
it('Should hide its comments', async function () {
|
it('Should hide its comments', async function () {
|
||||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||||
const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token)
|
const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
|
||||||
|
const threads = data.filter(t => t.isDeleted === false)
|
||||||
let threads: VideoComment[] = resThreads.body.data
|
|
||||||
threads = threads.filter(t => t.isDeleted === false)
|
|
||||||
|
|
||||||
expect(threads).to.have.lengthOf(1)
|
expect(threads).to.have.lengthOf(1)
|
||||||
expect(threads[0].totalReplies).to.equal(1)
|
expect(threads[0].totalReplies).to.equal(1)
|
||||||
|
@ -549,9 +540,7 @@ describe('Test blocklist', function () {
|
||||||
expect(t).to.be.undefined
|
expect(t).to.be.undefined
|
||||||
|
|
||||||
for (const thread of threads) {
|
for (const thread of threads) {
|
||||||
const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token)
|
const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = res.body
|
|
||||||
expect(tree.children).to.have.lengthOf(0)
|
expect(tree.children).to.have.lengthOf(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -624,7 +613,7 @@ describe('Test blocklist', function () {
|
||||||
|
|
||||||
it('Should display its comments', async function () {
|
it('Should display its comments', async function () {
|
||||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||||
await checkAllComments(servers[0].url, token, videoUUID1)
|
await checkAllComments(servers[0], token, videoUUID1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -651,13 +640,13 @@ describe('Test blocklist', function () {
|
||||||
describe('When managing server blocklist', function () {
|
describe('When managing server blocklist', function () {
|
||||||
it('Should list all videos', async function () {
|
it('Should list all videos', async function () {
|
||||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||||
await checkAllVideos(servers[0].url, token)
|
await checkAllVideos(servers[0], token)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list the comments', async function () {
|
it('Should list the comments', async function () {
|
||||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||||
await checkAllComments(servers[0].url, token, videoUUID1)
|
await checkAllComments(servers[0], token, videoUUID1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -686,14 +675,13 @@ describe('Test blocklist', function () {
|
||||||
it('Should hide its comments', async function () {
|
it('Should hide its comments', async function () {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
|
|
||||||
const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
|
const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
|
||||||
const threadId = resThreads.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||||
|
|
||||||
await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
|
await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have notification from blocked instances by instance', async function () {
|
it('Should not have notification from blocked instances by instance', async function () {
|
||||||
|
@ -749,13 +737,13 @@ describe('Test blocklist', function () {
|
||||||
|
|
||||||
it('Should list all videos', async function () {
|
it('Should list all videos', async function () {
|
||||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||||
await checkAllVideos(servers[0].url, token)
|
await checkAllVideos(servers[0], token)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list the comments', async function () {
|
it('Should list the comments', async function () {
|
||||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||||
await checkAllComments(servers[0].url, token, videoUUID1)
|
await checkAllComments(servers[0], token, videoUUID1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,10 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import {
|
import {
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
checkCommentMention,
|
checkCommentMention,
|
||||||
CheckerBaseParams,
|
CheckerBaseParams,
|
||||||
checkNewCommentOnMyVideo,
|
checkNewCommentOnMyVideo,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideoThreadComments,
|
|
||||||
MockSmtpServer,
|
MockSmtpServer,
|
||||||
prepareNotificationsTest,
|
prepareNotificationsTest,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
|
@ -18,13 +14,13 @@ import {
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
waitJobs
|
waitJobs
|
||||||
} from '@shared/extra-utils'
|
} from '@shared/extra-utils'
|
||||||
import { UserNotification, VideoCommentThreadTree } from '@shared/models'
|
import { UserNotification } from '@shared/models'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Test comments notifications', function () {
|
describe('Test comments notifications', function () {
|
||||||
let servers: ServerInfo[] = []
|
let servers: ServerInfo[] = []
|
||||||
let userAccessToken: string
|
let userToken: string
|
||||||
let userNotifications: UserNotification[] = []
|
let userNotifications: UserNotification[] = []
|
||||||
let emails: object[] = []
|
let emails: object[] = []
|
||||||
|
|
||||||
|
@ -38,7 +34,7 @@ describe('Test comments notifications', function () {
|
||||||
|
|
||||||
const res = await prepareNotificationsTest(2)
|
const res = await prepareNotificationsTest(2)
|
||||||
emails = res.emails
|
emails = res.emails
|
||||||
userAccessToken = res.userAccessToken
|
userToken = res.userAccessToken
|
||||||
servers = res.servers
|
servers = res.servers
|
||||||
userNotifications = res.userNotifications
|
userNotifications = res.userNotifications
|
||||||
})
|
})
|
||||||
|
@ -51,7 +47,7 @@ describe('Test comments notifications', function () {
|
||||||
server: servers[0],
|
server: servers[0],
|
||||||
emails,
|
emails,
|
||||||
socketNotifications: userNotifications,
|
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 resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
||||||
const uuid = resVideo.body.video.uuid
|
const uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
|
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
||||||
const commentId = resComment.body.comment.id
|
const commentId = created.id
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
|
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 () {
|
it('Should not send a new comment notification if I comment my own video', async function () {
|
||||||
this.timeout(20000)
|
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 uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
|
const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
|
||||||
const commentId = resComment.body.comment.id
|
const commentId = created.id
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
|
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 () {
|
it('Should not send a new comment notification if the account is muted', async function () {
|
||||||
this.timeout(20000)
|
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 uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
|
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
||||||
const commentId = resComment.body.comment.id
|
const commentId = created.id
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
|
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 () {
|
it('Should send a new comment notification after a local comment on my video', async function () {
|
||||||
this.timeout(20000)
|
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 uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
|
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
||||||
const commentId = resComment.body.comment.id
|
const commentId = created.id
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
|
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 () {
|
it('Should send a new comment notification after a remote comment on my video', async function () {
|
||||||
this.timeout(20000)
|
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 uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
await waitJobs(servers)
|
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)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
|
||||||
expect(resComment.body.data).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
const commentId = resComment.body.data[0].id
|
|
||||||
|
|
||||||
|
const commentId = data[0].id
|
||||||
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
|
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should send a new comment notification after a local reply on my video', async function () {
|
it('Should send a new comment notification after a local reply on my video', async function () {
|
||||||
this.timeout(20000)
|
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 uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
|
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
||||||
const threadId = resThread.body.comment.id
|
|
||||||
|
|
||||||
const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
|
const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
|
||||||
const commentId = resComment.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
|
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 () {
|
it('Should send a new comment notification after a remote reply on my video', async function () {
|
||||||
this.timeout(20000)
|
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 uuid = resVideo.body.video.uuid
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
{
|
{
|
||||||
const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
|
const created = await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
||||||
const threadId = resThread.body.comment.id
|
const threadId = created.id
|
||||||
await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
|
await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
|
||||||
expect(resThread.body.data).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
const threadId = resThread.body.data[0].id
|
|
||||||
|
|
||||||
const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
|
const threadId = data[0].id
|
||||||
const tree = resComments.body as VideoCommentThreadTree
|
const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId })
|
||||||
|
|
||||||
expect(tree.children).to.have.lengthOf(1)
|
expect(tree.children).to.have.lengthOf(1)
|
||||||
const commentId = tree.children[0].comment.id
|
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 () {
|
it('Should convert markdown in comment to html', async function () {
|
||||||
this.timeout(20000)
|
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
|
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)
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
@ -197,7 +190,7 @@ describe('Test comments notifications', function () {
|
||||||
server: servers[0],
|
server: servers[0],
|
||||||
emails,
|
emails,
|
||||||
socketNotifications: userNotifications,
|
socketNotifications: userNotifications,
|
||||||
token: userAccessToken
|
token: userToken
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateMyUser({
|
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 () {
|
it('Should not send a new mention comment notification if I mention the video owner', async function () {
|
||||||
this.timeout(10000)
|
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 uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
|
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
|
||||||
const commentId = resComment.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
|
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 resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
||||||
const uuid = resVideo.body.video.uuid
|
const uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
|
const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
|
||||||
const commentId = resComment.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
|
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 () {
|
it('Should not send a new mention notification if the account is muted', async function () {
|
||||||
this.timeout(10000)
|
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 resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
||||||
const uuid = resVideo.body.video.uuid
|
const uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
|
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
|
||||||
const commentId = resComment.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
|
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
|
||||||
|
|
||||||
await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })
|
await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not send a new mention notification if the remote account mention a local account', async function () {
|
it('Should not send a new mention notification if the remote account mention a local account', async function () {
|
||||||
|
@ -263,8 +253,7 @@ describe('Test comments notifications', function () {
|
||||||
const uuid = resVideo.body.video.uuid
|
const uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
|
const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
|
||||||
const threadId = resThread.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
|
await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
|
||||||
|
@ -276,14 +265,12 @@ describe('Test comments notifications', function () {
|
||||||
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
||||||
const uuid = resVideo.body.video.uuid
|
const uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
|
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
|
||||||
const threadId = resThread.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
|
await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
|
||||||
|
|
||||||
const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
|
const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
|
||||||
const commentId = resComment.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
|
await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
|
||||||
|
@ -298,23 +285,22 @@ describe('Test comments notifications', function () {
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const text1 = `hello @user_1@localhost:${servers[0].port} 1`
|
const text1 = `hello @user_1@localhost:${servers[0].port} 1`
|
||||||
const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1)
|
const { id: server2ThreadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: text1 })
|
||||||
const server2ThreadId = resThread.body.comment.id
|
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
|
||||||
expect(resThread2.body.data).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
const server1ThreadId = resThread2.body.data[0].id
|
|
||||||
|
const server1ThreadId = data[0].id
|
||||||
await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
|
await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
|
||||||
|
|
||||||
const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
|
const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
|
||||||
await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2)
|
await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
|
const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId: server1ThreadId })
|
||||||
const tree = resComments.body as VideoCommentThreadTree
|
|
||||||
|
|
||||||
expect(tree.children).to.have.lengthOf(1)
|
expect(tree.children).to.have.lengthOf(1)
|
||||||
const commentId = tree.children[0].comment.id
|
const commentId = tree.children[0].comment.id
|
||||||
|
@ -328,10 +314,9 @@ describe('Test comments notifications', function () {
|
||||||
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
||||||
const uuid = resVideo.body.video.uuid
|
const uuid = resVideo.body.video.uuid
|
||||||
|
|
||||||
const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
|
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' })
|
||||||
const threadId = resThread.body.comment.id
|
|
||||||
|
|
||||||
await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, '@user_1 ' + commentText)
|
await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { buildUUID } from '@server/helpers/uuid'
|
import { buildUUID } from '@server/helpers/uuid'
|
||||||
import {
|
import {
|
||||||
addVideoCommentThread,
|
|
||||||
checkAbuseStateChange,
|
checkAbuseStateChange,
|
||||||
checkAutoInstanceFollowing,
|
checkAutoInstanceFollowing,
|
||||||
CheckerBaseParams,
|
CheckerBaseParams,
|
||||||
|
@ -20,7 +19,6 @@ import {
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
generateUserAccessToken,
|
generateUserAccessToken,
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideoIdFromUUID,
|
getVideoIdFromUUID,
|
||||||
immutableAssign,
|
immutableAssign,
|
||||||
MockInstancesIndex,
|
MockInstancesIndex,
|
||||||
|
@ -101,8 +99,11 @@ describe('Test moderation notifications', function () {
|
||||||
const name = 'video for abuse ' + buildUUID()
|
const name = 'video for abuse ' + buildUUID()
|
||||||
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
|
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
|
||||||
const video = resVideo.body.video
|
const video = resVideo.body.video
|
||||||
const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID())
|
const comment = await servers[0].commentsCommand.createThread({
|
||||||
const comment = resComment.body.comment
|
token: userAccessToken,
|
||||||
|
videoId: video.id,
|
||||||
|
text: 'comment abuse ' + buildUUID()
|
||||||
|
})
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
@ -118,12 +119,17 @@ describe('Test moderation notifications', function () {
|
||||||
const name = 'video for abuse ' + buildUUID()
|
const name = 'video for abuse ' + buildUUID()
|
||||||
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
|
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
|
||||||
const video = resVideo.body.video
|
const video = resVideo.body.video
|
||||||
await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID())
|
|
||||||
|
await servers[0].commentsCommand.createThread({
|
||||||
|
token: userAccessToken,
|
||||||
|
videoId: video.id,
|
||||||
|
text: 'comment abuse ' + buildUUID()
|
||||||
|
})
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5)
|
const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.uuid })
|
||||||
const commentId = resComments.body.data[0].id
|
const commentId = data[0].id
|
||||||
await servers[1].abusesCommand.report({ commentId, reason: 'super reason' })
|
await servers[1].abusesCommand.report({ commentId, reason: 'super reason' })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
|
@ -2,16 +2,13 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import { Video, VideoComment } from '@shared/models'
|
import { Video } from '@shared/models'
|
||||||
import {
|
import {
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
BulkCommand,
|
BulkCommand,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideosList,
|
getVideosList,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
|
@ -26,9 +23,9 @@ describe('Test bulk actions', function () {
|
||||||
const commentsUser3: { videoId: number, commentId: number }[] = []
|
const commentsUser3: { videoId: number, commentId: number }[] = []
|
||||||
|
|
||||||
let servers: ServerInfo[] = []
|
let servers: ServerInfo[] = []
|
||||||
let user1AccessToken: string
|
let user1Token: string
|
||||||
let user2AccessToken: string
|
let user2Token: string
|
||||||
let user3AccessToken: string
|
let user3Token: string
|
||||||
|
|
||||||
let bulkCommand: BulkCommand
|
let bulkCommand: BulkCommand
|
||||||
|
|
||||||
|
@ -44,21 +41,21 @@ describe('Test bulk actions', function () {
|
||||||
const user = { username: 'user1', password: 'password' }
|
const user = { username: 'user1', password: 'password' }
|
||||||
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
||||||
|
|
||||||
user1AccessToken = await userLogin(servers[0], user)
|
user1Token = await userLogin(servers[0], user)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const user = { username: 'user2', password: 'password' }
|
const user = { username: 'user2', password: 'password' }
|
||||||
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
||||||
|
|
||||||
user2AccessToken = await userLogin(servers[0], user)
|
user2Token = await userLogin(servers[0], user)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const user = { username: 'user3', password: 'password' }
|
const user = { username: 'user3', password: 'password' }
|
||||||
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
|
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
|
||||||
|
|
||||||
user3AccessToken = await userLogin(servers[1], user)
|
user3Token = await userLogin(servers[1], user)
|
||||||
}
|
}
|
||||||
|
|
||||||
await doubleFollow(servers[0], servers[1])
|
await doubleFollow(servers[0], servers[1])
|
||||||
|
@ -74,9 +71,8 @@ describe('Test bulk actions', function () {
|
||||||
|
|
||||||
// Server 1 should not have these comments anymore
|
// Server 1 should not have these comments anymore
|
||||||
for (const video of videos) {
|
for (const video of videos) {
|
||||||
const resThreads = await getVideoCommentThreads(servers[0].url, video.id, 0, 10)
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id })
|
||||||
const comments = resThreads.body.data as VideoComment[]
|
const comment = data.find(c => c.text === 'comment by user 3')
|
||||||
const comment = comments.find(c => c.text === 'comment by user 3')
|
|
||||||
|
|
||||||
expect(comment).to.not.exist
|
expect(comment).to.not.exist
|
||||||
}
|
}
|
||||||
|
@ -88,9 +84,8 @@ describe('Test bulk actions', function () {
|
||||||
|
|
||||||
// Server 1 should not have these comments on videos of server 1
|
// Server 1 should not have these comments on videos of server 1
|
||||||
for (const video of videos) {
|
for (const video of videos) {
|
||||||
const resThreads = await getVideoCommentThreads(servers[1].url, video.id, 0, 10)
|
const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id })
|
||||||
const comments = resThreads.body.data as VideoComment[]
|
const comment = data.find(c => c.text === 'comment by user 3')
|
||||||
const comment = comments.find(c => c.text === 'comment by user 3')
|
|
||||||
|
|
||||||
if (video.account.host === 'localhost:' + servers[0].port) {
|
if (video.account.host === 'localhost:' + servers[0].port) {
|
||||||
expect(comment).to.not.exist
|
expect(comment).to.not.exist
|
||||||
|
@ -106,7 +101,7 @@ describe('Test bulk actions', function () {
|
||||||
|
|
||||||
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' })
|
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' })
|
||||||
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
|
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
|
||||||
await uploadVideo(servers[0].url, user1AccessToken, { name: 'video 3 server 1' })
|
await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' })
|
||||||
|
|
||||||
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
|
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
|
||||||
|
|
||||||
|
@ -115,19 +110,20 @@ describe('Test bulk actions', function () {
|
||||||
{
|
{
|
||||||
const res = await getVideosList(servers[0].url)
|
const res = await getVideosList(servers[0].url)
|
||||||
for (const video of res.body.data) {
|
for (const video of res.body.data) {
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, video.id, 'comment by root server 1')
|
await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' })
|
||||||
await addVideoCommentThread(servers[0].url, user1AccessToken, video.id, 'comment by user 1')
|
await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' })
|
||||||
await addVideoCommentThread(servers[0].url, user2AccessToken, video.id, 'comment by user 2')
|
await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideosList(servers[1].url)
|
const res = await getVideosList(servers[1].url)
|
||||||
for (const video of res.body.data) {
|
|
||||||
await addVideoCommentThread(servers[1].url, servers[1].accessToken, video.id, 'comment by root server 2')
|
|
||||||
|
|
||||||
const res = await addVideoCommentThread(servers[1].url, user3AccessToken, video.id, 'comment by user 3')
|
for (const video of res.body.data) {
|
||||||
commentsUser3.push({ videoId: video.id, commentId: res.body.comment.id })
|
await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' })
|
||||||
|
|
||||||
|
const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' })
|
||||||
|
commentsUser3.push({ videoId: video.id, commentId: comment.id })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +134,7 @@ describe('Test bulk actions', function () {
|
||||||
this.timeout(60000)
|
this.timeout(60000)
|
||||||
|
|
||||||
await bulkCommand.removeCommentsOf({
|
await bulkCommand.removeCommentsOf({
|
||||||
token: user1AccessToken,
|
token: user1Token,
|
||||||
attributes: {
|
attributes: {
|
||||||
accountName: 'user2',
|
accountName: 'user2',
|
||||||
scope: 'my-videos'
|
scope: 'my-videos'
|
||||||
|
@ -151,15 +147,11 @@ describe('Test bulk actions', function () {
|
||||||
const res = await getVideosList(server.url)
|
const res = await getVideosList(server.url)
|
||||||
|
|
||||||
for (const video of res.body.data) {
|
for (const video of res.body.data) {
|
||||||
const resThreads = await getVideoCommentThreads(server.url, video.id, 0, 10)
|
const { data } = await server.commentsCommand.listThreads({ videoId: video.id })
|
||||||
const comments = resThreads.body.data as VideoComment[]
|
const comment = data.find(c => c.text === 'comment by user 2')
|
||||||
const comment = comments.find(c => c.text === 'comment by user 2')
|
|
||||||
|
|
||||||
if (video.name === 'video 3 server 1') {
|
if (video.name === 'video 3 server 1') expect(comment).to.not.exist
|
||||||
expect(comment).to.not.exist
|
else expect(comment).to.exist
|
||||||
} else {
|
|
||||||
expect(comment).to.exist
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -183,7 +175,12 @@ describe('Test bulk actions', function () {
|
||||||
this.timeout(60000)
|
this.timeout(60000)
|
||||||
|
|
||||||
for (const obj of commentsUser3) {
|
for (const obj of commentsUser3) {
|
||||||
await addVideoCommentReply(servers[1].url, user3AccessToken, obj.videoId, obj.commentId, 'comment by user 3 bis')
|
await servers[1].commentsCommand.addReply({
|
||||||
|
token: user3Token,
|
||||||
|
videoId: obj.videoId,
|
||||||
|
toCommentId: obj.commentId,
|
||||||
|
text: 'comment by user 3 bis'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
|
@ -3,19 +3,14 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import {
|
import {
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
completeVideoCheck,
|
completeVideoCheck,
|
||||||
createUser,
|
createUser,
|
||||||
dateIsValid,
|
dateIsValid,
|
||||||
deleteVideoComment,
|
|
||||||
expectAccountFollows,
|
expectAccountFollows,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
FollowsCommand,
|
FollowsCommand,
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideosList,
|
getVideosList,
|
||||||
getVideoThreadComments,
|
|
||||||
rateVideo,
|
rateVideo,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
|
@ -24,7 +19,7 @@ import {
|
||||||
userLogin,
|
userLogin,
|
||||||
waitJobs
|
waitJobs
|
||||||
} from '@shared/extra-utils'
|
} from '@shared/extra-utils'
|
||||||
import { Video, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
|
import { Video, VideoPrivacy } from '@shared/models'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
|
@ -348,37 +343,35 @@ describe('Test follows', function () {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
const text = 'my super first comment'
|
const text = 'my super first comment'
|
||||||
const res = await addVideoCommentThread(servers[2].url, servers[2].accessToken, video4.id, text)
|
const created = await servers[2].commentsCommand.createThread({ videoId: video4.id, text })
|
||||||
const threadId = res.body.comment.id
|
const threadId = created.id
|
||||||
|
|
||||||
const text1 = 'my super answer to thread 1'
|
const text1 = 'my super answer to thread 1'
|
||||||
const childCommentRes = await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text1)
|
const childComment = await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 })
|
||||||
const childCommentId = childCommentRes.body.comment.id
|
|
||||||
|
|
||||||
const text2 = 'my super answer to answer of thread 1'
|
const text2 = 'my super answer to answer of thread 1'
|
||||||
await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, childCommentId, text2)
|
await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text2 })
|
||||||
|
|
||||||
const text3 = 'my second answer to thread 1'
|
const text3 = 'my second answer to thread 1'
|
||||||
await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text3)
|
await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text3 })
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const text = 'will be deleted'
|
const text = 'will be deleted'
|
||||||
const res = await addVideoCommentThread(servers[2].url, servers[2].accessToken, video4.id, text)
|
const created = await servers[2].commentsCommand.createThread({ videoId: video4.id, text })
|
||||||
const threadId = res.body.comment.id
|
const threadId = created.id
|
||||||
|
|
||||||
const text1 = 'answer to deleted'
|
const text1 = 'answer to deleted'
|
||||||
await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text1)
|
await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 })
|
||||||
|
|
||||||
const text2 = 'will also be deleted'
|
const text2 = 'will also be deleted'
|
||||||
const childCommentRes = await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text2)
|
const childComment = await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text2 })
|
||||||
const childCommentId = childCommentRes.body.comment.id
|
|
||||||
|
|
||||||
const text3 = 'my second answer to deleted'
|
const text3 = 'my second answer to deleted'
|
||||||
await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, childCommentId, text3)
|
await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text3 })
|
||||||
|
|
||||||
await deleteVideoComment(servers[2].url, servers[2].accessToken, video4.id, threadId)
|
await servers[2].commentsCommand.delete({ videoId: video4.id, commentId: threadId })
|
||||||
await deleteVideoComment(servers[2].url, servers[2].accessToken, video4.id, childCommentId)
|
await servers[2].commentsCommand.delete({ videoId: video4.id, commentId: childComment.id })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,14 +455,14 @@ describe('Test follows', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have propagated comments', async function () {
|
it('Should have propagated comments', async function () {
|
||||||
const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5, 'createdAt')
|
const { total, data } = await servers[0].commentsCommand.listThreads({ videoId: video4.id, sort: 'createdAt' })
|
||||||
|
|
||||||
expect(res1.body.total).to.equal(2)
|
expect(total).to.equal(2)
|
||||||
expect(res1.body.data).to.be.an('array')
|
expect(data).to.be.an('array')
|
||||||
expect(res1.body.data).to.have.lengthOf(2)
|
expect(data).to.have.lengthOf(2)
|
||||||
|
|
||||||
{
|
{
|
||||||
const comment: VideoComment = res1.body.data[0]
|
const comment = data[0]
|
||||||
expect(comment.inReplyToCommentId).to.be.null
|
expect(comment.inReplyToCommentId).to.be.null
|
||||||
expect(comment.text).equal('my super first comment')
|
expect(comment.text).equal('my super first comment')
|
||||||
expect(comment.videoId).to.equal(video4.id)
|
expect(comment.videoId).to.equal(video4.id)
|
||||||
|
@ -482,9 +475,7 @@ describe('Test follows', function () {
|
||||||
|
|
||||||
const threadId = comment.threadId
|
const threadId = comment.threadId
|
||||||
|
|
||||||
const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId)
|
const tree = await servers[0].commentsCommand.getThread({ videoId: video4.id, threadId })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = res2.body
|
|
||||||
expect(tree.comment.text).equal('my super first comment')
|
expect(tree.comment.text).equal('my super first comment')
|
||||||
expect(tree.children).to.have.lengthOf(2)
|
expect(tree.children).to.have.lengthOf(2)
|
||||||
|
|
||||||
|
@ -502,7 +493,7 @@ describe('Test follows', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const deletedComment: VideoComment = res1.body.data[1]
|
const deletedComment = data[1]
|
||||||
expect(deletedComment).to.not.be.undefined
|
expect(deletedComment).to.not.be.undefined
|
||||||
expect(deletedComment.isDeleted).to.be.true
|
expect(deletedComment.isDeleted).to.be.true
|
||||||
expect(deletedComment.deletedAt).to.not.be.null
|
expect(deletedComment.deletedAt).to.not.be.null
|
||||||
|
@ -512,9 +503,7 @@ describe('Test follows', function () {
|
||||||
expect(deletedComment.totalReplies).to.equal(2)
|
expect(deletedComment.totalReplies).to.equal(2)
|
||||||
expect(dateIsValid(deletedComment.deletedAt as string)).to.be.true
|
expect(dateIsValid(deletedComment.deletedAt as string)).to.be.true
|
||||||
|
|
||||||
const res2 = await getVideoThreadComments(servers[0].url, video4.id, deletedComment.threadId)
|
const tree = await servers[0].commentsCommand.getThread({ videoId: video4.id, threadId: deletedComment.threadId })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = res2.body
|
|
||||||
const [ commentRoot, deletedChildRoot ] = tree.children
|
const [ commentRoot, deletedChildRoot ] = tree.children
|
||||||
|
|
||||||
expect(deletedChildRoot).to.not.be.undefined
|
expect(deletedChildRoot).to.not.be.undefined
|
||||||
|
|
|
@ -4,16 +4,13 @@ import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import { HttpStatusCode } from '@shared/core-utils'
|
import { HttpStatusCode } from '@shared/core-utils'
|
||||||
import {
|
import {
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
closeAllSequelize,
|
closeAllSequelize,
|
||||||
|
CommentsCommand,
|
||||||
completeVideoCheck,
|
completeVideoCheck,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
getVideo,
|
getVideo,
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideosList,
|
getVideosList,
|
||||||
getVideoThreadComments,
|
|
||||||
immutableAssign,
|
immutableAssign,
|
||||||
killallServers,
|
killallServers,
|
||||||
reRunServer,
|
reRunServer,
|
||||||
|
@ -26,7 +23,7 @@ import {
|
||||||
wait,
|
wait,
|
||||||
waitJobs
|
waitJobs
|
||||||
} from '@shared/extra-utils'
|
} from '@shared/extra-utils'
|
||||||
import { JobState, Video, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
|
import { JobState, Video, VideoPrivacy } from '@shared/models'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
|
@ -62,10 +59,13 @@ describe('Test handle downs', function () {
|
||||||
let checkAttributes: any
|
let checkAttributes: any
|
||||||
let unlistedCheckAttributes: any
|
let unlistedCheckAttributes: any
|
||||||
|
|
||||||
|
let commentCommands: CommentsCommand[]
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(30000)
|
this.timeout(30000)
|
||||||
|
|
||||||
servers = await flushAndRunMultipleServers(3)
|
servers = await flushAndRunMultipleServers(3)
|
||||||
|
commentCommands = servers.map(s => s.commentsCommand)
|
||||||
|
|
||||||
checkAttributes = {
|
checkAttributes = {
|
||||||
name: 'my super name for server 1',
|
name: 'my super name for server 1',
|
||||||
|
@ -154,15 +154,13 @@ describe('Test handle downs', function () {
|
||||||
// Add comments to video 2
|
// Add comments to video 2
|
||||||
{
|
{
|
||||||
const text = 'thread 1'
|
const text = 'thread 1'
|
||||||
let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text)
|
let comment = await commentCommands[0].createThread({ videoId: missedVideo2.uuid, text })
|
||||||
let comment = resComment.body.comment
|
|
||||||
threadIdServer1 = comment.id
|
threadIdServer1 = comment.id
|
||||||
|
|
||||||
resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1')
|
comment = await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: comment.id, text: 'comment 1-1' })
|
||||||
comment = resComment.body.comment
|
|
||||||
|
|
||||||
resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2')
|
const created = await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: comment.id, text: 'comment 1-2' })
|
||||||
commentIdServer1 = resComment.body.comment.id
|
commentIdServer1 = created.id
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitJobs(servers[0])
|
await waitJobs(servers[0])
|
||||||
|
@ -235,7 +233,7 @@ describe('Test handle downs', function () {
|
||||||
it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
|
it('Should send comments on a video to server 3, and automatically fetch the video', async function () {
|
||||||
this.timeout(25000)
|
this.timeout(25000)
|
||||||
|
|
||||||
await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3')
|
await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer1, text: 'comment 1-3' })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
@ -243,15 +241,13 @@ describe('Test handle downs', function () {
|
||||||
expect(resVideo.body).not.to.be.undefined
|
expect(resVideo.body).not.to.be.undefined
|
||||||
|
|
||||||
{
|
{
|
||||||
let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5)
|
const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid })
|
||||||
expect(resComment.body.data).to.be.an('array')
|
expect(data).to.be.an('array')
|
||||||
expect(resComment.body.data).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
|
|
||||||
threadIdServer2 = resComment.body.data[0].id
|
threadIdServer2 = data[0].id
|
||||||
|
|
||||||
resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2)
|
const tree = await servers[2].commentsCommand.getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer2 })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = resComment.body
|
|
||||||
expect(tree.comment.text).equal('thread 1')
|
expect(tree.comment.text).equal('thread 1')
|
||||||
expect(tree.children).to.have.lengthOf(1)
|
expect(tree.children).to.have.lengthOf(1)
|
||||||
|
|
||||||
|
@ -274,33 +270,30 @@ describe('Test handle downs', function () {
|
||||||
it('Should correctly reply to the comment', async function () {
|
it('Should correctly reply to the comment', async function () {
|
||||||
this.timeout(15000)
|
this.timeout(15000)
|
||||||
|
|
||||||
await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4')
|
await servers[2].commentsCommand.addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer2, text: 'comment 1-4' })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
{
|
const tree = await commentCommands[0].getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer1 })
|
||||||
const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1)
|
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = resComment.body
|
expect(tree.comment.text).equal('thread 1')
|
||||||
expect(tree.comment.text).equal('thread 1')
|
expect(tree.children).to.have.lengthOf(1)
|
||||||
expect(tree.children).to.have.lengthOf(1)
|
|
||||||
|
|
||||||
const firstChild = tree.children[0]
|
const firstChild = tree.children[0]
|
||||||
expect(firstChild.comment.text).to.equal('comment 1-1')
|
expect(firstChild.comment.text).to.equal('comment 1-1')
|
||||||
expect(firstChild.children).to.have.lengthOf(1)
|
expect(firstChild.children).to.have.lengthOf(1)
|
||||||
|
|
||||||
const childOfFirstChild = firstChild.children[0]
|
const childOfFirstChild = firstChild.children[0]
|
||||||
expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
|
expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
|
||||||
expect(childOfFirstChild.children).to.have.lengthOf(1)
|
expect(childOfFirstChild.children).to.have.lengthOf(1)
|
||||||
|
|
||||||
const childOfChildFirstChild = childOfFirstChild.children[0]
|
const childOfChildFirstChild = childOfFirstChild.children[0]
|
||||||
expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
|
expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
|
||||||
expect(childOfChildFirstChild.children).to.have.lengthOf(1)
|
expect(childOfChildFirstChild.children).to.have.lengthOf(1)
|
||||||
|
|
||||||
const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
|
const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
|
||||||
expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
|
expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
|
||||||
expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
|
expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should upload many videos on server 1', async function () {
|
it('Should upload many videos on server 1', async function () {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import {
|
import {
|
||||||
addVideoCommentThread,
|
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
|
@ -42,7 +41,7 @@ describe('Test stats (excluding redundancy)', function () {
|
||||||
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
|
||||||
const videoUUID = resVideo.body.video.uuid
|
const videoUUID = resVideo.body.video.uuid
|
||||||
|
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
|
await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'comment' })
|
||||||
|
|
||||||
await viewVideo(servers[0].url, videoUUID)
|
await viewVideo(servers[0].url, videoUUID)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import { HttpStatusCode } from '@shared/core-utils'
|
import { HttpStatusCode } from '@shared/core-utils'
|
||||||
import {
|
import {
|
||||||
addVideoCommentThread,
|
|
||||||
blockUser,
|
blockUser,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
closeAllSequelize,
|
closeAllSequelize,
|
||||||
|
@ -983,7 +982,7 @@ describe('Test users', function () {
|
||||||
|
|
||||||
it('Should report correct video comments for user', async function () {
|
it('Should report correct video comments for user', async function () {
|
||||||
const text = 'super comment'
|
const text = 'super comment'
|
||||||
await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
|
await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text })
|
||||||
|
|
||||||
const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
|
const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
|
||||||
const user: User = res.body
|
const user: User = res.body
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import * as request from 'supertest'
|
import * as request from 'supertest'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '@shared/core-utils'
|
||||||
import {
|
import {
|
||||||
buildAbsoluteFixturePath,
|
buildAbsoluteFixturePath,
|
||||||
checkTmpIsEmpty,
|
checkTmpIsEmpty,
|
||||||
|
@ -27,18 +27,10 @@ import {
|
||||||
userLogin,
|
userLogin,
|
||||||
viewVideo,
|
viewVideo,
|
||||||
wait,
|
wait,
|
||||||
|
waitJobs,
|
||||||
webtorrentAdd
|
webtorrentAdd
|
||||||
} from '../../../../shared/extra-utils'
|
} from '@shared/extra-utils'
|
||||||
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
|
||||||
import {
|
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
deleteVideoComment,
|
|
||||||
findCommentId,
|
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideoThreadComments
|
|
||||||
} from '../../../../shared/extra-utils/videos/video-comments'
|
|
||||||
import { VideoComment, VideoCommentThreadTree, VideoPrivacy } from '../../../../shared/models/videos'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
|
@ -762,36 +754,36 @@ describe('Test multiple servers', function () {
|
||||||
|
|
||||||
{
|
{
|
||||||
const text = 'my super first comment'
|
const text = 'my super first comment'
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, text)
|
await servers[0].commentsCommand.createThread({ videoId: videoUUID, text })
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const text = 'my super second comment'
|
const text = 'my super second comment'
|
||||||
await addVideoCommentThread(servers[2].url, servers[2].accessToken, videoUUID, text)
|
await servers[2].commentsCommand.createThread({ videoId: videoUUID, text })
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
{
|
{
|
||||||
const threadId = await findCommentId(servers[1].url, videoUUID, 'my super first comment')
|
const threadId = await servers[1].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
|
||||||
|
|
||||||
const text = 'my super answer to thread 1'
|
const text = 'my super answer to thread 1'
|
||||||
await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID, threadId, text)
|
await servers[1].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text })
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
{
|
{
|
||||||
const threadId = await findCommentId(servers[2].url, videoUUID, 'my super first comment')
|
const threadId = await servers[2].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
|
||||||
|
|
||||||
const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId)
|
const body = await servers[2].commentsCommand.getThread({ videoId: videoUUID, threadId })
|
||||||
const childCommentId = res2.body.children[0].comment.id
|
const childCommentId = body.children[0].comment.id
|
||||||
|
|
||||||
const text3 = 'my second answer to thread 1'
|
const text3 = 'my second answer to thread 1'
|
||||||
await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, threadId, text3)
|
await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 })
|
||||||
|
|
||||||
const text2 = 'my super answer to answer of thread 1'
|
const text2 = 'my super answer to answer of thread 1'
|
||||||
await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, childCommentId, text2)
|
await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 })
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
@ -799,14 +791,14 @@ describe('Test multiple servers', function () {
|
||||||
|
|
||||||
it('Should have these threads', async function () {
|
it('Should have these threads', async function () {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
|
const body = await server.commentsCommand.listThreads({ videoId: videoUUID })
|
||||||
|
|
||||||
expect(res.body.total).to.equal(2)
|
expect(body.total).to.equal(2)
|
||||||
expect(res.body.data).to.be.an('array')
|
expect(body.data).to.be.an('array')
|
||||||
expect(res.body.data).to.have.lengthOf(2)
|
expect(body.data).to.have.lengthOf(2)
|
||||||
|
|
||||||
{
|
{
|
||||||
const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment')
|
const comment = body.data.find(c => c.text === 'my super first comment')
|
||||||
expect(comment).to.not.be.undefined
|
expect(comment).to.not.be.undefined
|
||||||
expect(comment.inReplyToCommentId).to.be.null
|
expect(comment.inReplyToCommentId).to.be.null
|
||||||
expect(comment.account.name).to.equal('root')
|
expect(comment.account.name).to.equal('root')
|
||||||
|
@ -817,7 +809,7 @@ describe('Test multiple servers', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment')
|
const comment = body.data.find(c => c.text === 'my super second comment')
|
||||||
expect(comment).to.not.be.undefined
|
expect(comment).to.not.be.undefined
|
||||||
expect(comment.inReplyToCommentId).to.be.null
|
expect(comment.inReplyToCommentId).to.be.null
|
||||||
expect(comment.account.name).to.equal('root')
|
expect(comment.account.name).to.equal('root')
|
||||||
|
@ -831,12 +823,11 @@ describe('Test multiple servers', function () {
|
||||||
|
|
||||||
it('Should have these comments', async function () {
|
it('Should have these comments', async function () {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
|
const body = await server.commentsCommand.listThreads({ videoId: videoUUID })
|
||||||
const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
|
const threadId = body.data.find(c => c.text === 'my super first comment').id
|
||||||
|
|
||||||
const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
|
const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = res2.body
|
|
||||||
expect(tree.comment.text).equal('my super first comment')
|
expect(tree.comment.text).equal('my super first comment')
|
||||||
expect(tree.comment.account.name).equal('root')
|
expect(tree.comment.account.name).equal('root')
|
||||||
expect(tree.comment.account.host).equal('localhost:' + servers[0].port)
|
expect(tree.comment.account.host).equal('localhost:' + servers[0].port)
|
||||||
|
@ -865,19 +856,17 @@ describe('Test multiple servers', function () {
|
||||||
it('Should delete a reply', async function () {
|
it('Should delete a reply', async function () {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
|
|
||||||
await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id)
|
await servers[2].commentsCommand.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have this comment marked as deleted', async function () {
|
it('Should have this comment marked as deleted', async function () {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
|
const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID })
|
||||||
const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
|
const threadId = data.find(c => c.text === 'my super first comment').id
|
||||||
|
|
||||||
const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
|
const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = res2.body
|
|
||||||
expect(tree.comment.text).equal('my super first comment')
|
expect(tree.comment.text).equal('my super first comment')
|
||||||
|
|
||||||
const firstChild = tree.children[0]
|
const firstChild = tree.children[0]
|
||||||
|
@ -898,23 +887,23 @@ describe('Test multiple servers', function () {
|
||||||
it('Should delete the thread comments', async function () {
|
it('Should delete the thread comments', async function () {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
|
|
||||||
const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5)
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID })
|
||||||
const threadId = res.body.data.find(c => c.text === 'my super first comment').id
|
const commentId = data.find(c => c.text === 'my super first comment').id
|
||||||
await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
|
await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the threads marked as deleted on other servers too', async function () {
|
it('Should have the threads marked as deleted on other servers too', async function () {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
|
const body = await server.commentsCommand.listThreads({ videoId: videoUUID })
|
||||||
|
|
||||||
expect(res.body.total).to.equal(2)
|
expect(body.total).to.equal(2)
|
||||||
expect(res.body.data).to.be.an('array')
|
expect(body.data).to.be.an('array')
|
||||||
expect(res.body.data).to.have.lengthOf(2)
|
expect(body.data).to.have.lengthOf(2)
|
||||||
|
|
||||||
{
|
{
|
||||||
const comment: VideoComment = res.body.data[0]
|
const comment = body.data[0]
|
||||||
expect(comment).to.not.be.undefined
|
expect(comment).to.not.be.undefined
|
||||||
expect(comment.inReplyToCommentId).to.be.null
|
expect(comment.inReplyToCommentId).to.be.null
|
||||||
expect(comment.account.name).to.equal('root')
|
expect(comment.account.name).to.equal('root')
|
||||||
|
@ -925,7 +914,7 @@ describe('Test multiple servers', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const deletedComment: VideoComment = res.body.data[1]
|
const deletedComment = body.data[1]
|
||||||
expect(deletedComment).to.not.be.undefined
|
expect(deletedComment).to.not.be.undefined
|
||||||
expect(deletedComment.isDeleted).to.be.true
|
expect(deletedComment.isDeleted).to.be.true
|
||||||
expect(deletedComment.deletedAt).to.not.be.null
|
expect(deletedComment.deletedAt).to.not.be.null
|
||||||
|
@ -943,22 +932,22 @@ describe('Test multiple servers', function () {
|
||||||
it('Should delete a remote thread by the origin server', async function () {
|
it('Should delete a remote thread by the origin server', async function () {
|
||||||
this.timeout(5000)
|
this.timeout(5000)
|
||||||
|
|
||||||
const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5)
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID })
|
||||||
const threadId = res.body.data.find(c => c.text === 'my super second comment').id
|
const commentId = data.find(c => c.text === 'my super second comment').id
|
||||||
await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
|
await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId })
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the threads marked as deleted on other servers too', async function () {
|
it('Should have the threads marked as deleted on other servers too', async function () {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
|
const body = await server.commentsCommand.listThreads({ videoId: videoUUID })
|
||||||
|
|
||||||
expect(res.body.total).to.equal(2)
|
expect(body.total).to.equal(2)
|
||||||
expect(res.body.data).to.have.lengthOf(2)
|
expect(body.data).to.have.lengthOf(2)
|
||||||
|
|
||||||
{
|
{
|
||||||
const comment: VideoComment = res.body.data[0]
|
const comment = body.data[0]
|
||||||
expect(comment.text).to.equal('')
|
expect(comment.text).to.equal('')
|
||||||
expect(comment.isDeleted).to.be.true
|
expect(comment.isDeleted).to.be.true
|
||||||
expect(comment.createdAt).to.not.be.null
|
expect(comment.createdAt).to.not.be.null
|
||||||
|
@ -968,7 +957,7 @@ describe('Test multiple servers', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const comment: VideoComment = res.body.data[1]
|
const comment = body.data[1]
|
||||||
expect(comment.text).to.equal('')
|
expect(comment.text).to.equal('')
|
||||||
expect(comment.isDeleted).to.be.true
|
expect(comment.isDeleted).to.be.true
|
||||||
expect(comment.createdAt).to.not.be.null
|
expect(comment.createdAt).to.not.be.null
|
||||||
|
@ -997,7 +986,7 @@ describe('Test multiple servers', function () {
|
||||||
expect(res.body.downloadEnabled).to.be.false
|
expect(res.body.downloadEnabled).to.be.false
|
||||||
|
|
||||||
const text = 'my super forbidden comment'
|
const text = 'my super forbidden comment'
|
||||||
await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, HttpStatusCode.CONFLICT_409)
|
await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,38 +2,33 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '@shared/models'
|
|
||||||
import { cleanupTests, testImage } from '../../../../shared/extra-utils'
|
|
||||||
import {
|
import {
|
||||||
|
cleanupTests,
|
||||||
|
CommentsCommand,
|
||||||
createUser,
|
createUser,
|
||||||
dateIsValid,
|
dateIsValid,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
getAccessToken,
|
getAccessToken,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
|
testImage,
|
||||||
updateMyAvatar,
|
updateMyAvatar,
|
||||||
uploadVideo
|
uploadVideo
|
||||||
} from '../../../../shared/extra-utils/index'
|
} from '@shared/extra-utils'
|
||||||
import {
|
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
deleteVideoComment,
|
|
||||||
getAdminVideoComments,
|
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideoThreadComments
|
|
||||||
} from '../../../../shared/extra-utils/videos/video-comments'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Test video comments', function () {
|
describe('Test video comments', function () {
|
||||||
let server: ServerInfo
|
let server: ServerInfo
|
||||||
let videoId
|
let videoId: number
|
||||||
let videoUUID
|
let videoUUID: string
|
||||||
let threadId
|
let threadId: number
|
||||||
let replyToDeleteId: number
|
let replyToDeleteId: number
|
||||||
|
|
||||||
let userAccessTokenServer1: string
|
let userAccessTokenServer1: string
|
||||||
|
|
||||||
|
let command: CommentsCommand
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(30000)
|
this.timeout(30000)
|
||||||
|
|
||||||
|
@ -58,24 +53,25 @@ describe('Test video comments', function () {
|
||||||
password: 'password'
|
password: 'password'
|
||||||
})
|
})
|
||||||
userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password')
|
userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password')
|
||||||
|
|
||||||
|
command = server.commentsCommand
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('User comments', function () {
|
describe('User comments', function () {
|
||||||
|
|
||||||
it('Should not have threads on this video', async function () {
|
it('Should not have threads on this video', async function () {
|
||||||
const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
|
const body = await command.listThreads({ videoId: videoUUID })
|
||||||
|
|
||||||
expect(res.body.total).to.equal(0)
|
expect(body.total).to.equal(0)
|
||||||
expect(res.body.totalNotDeletedComments).to.equal(0)
|
expect(body.totalNotDeletedComments).to.equal(0)
|
||||||
expect(res.body.data).to.be.an('array')
|
expect(body.data).to.be.an('array')
|
||||||
expect(res.body.data).to.have.lengthOf(0)
|
expect(body.data).to.have.lengthOf(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should create a thread in this video', async function () {
|
it('Should create a thread in this video', async function () {
|
||||||
const text = 'my super first comment'
|
const text = 'my super first comment'
|
||||||
|
|
||||||
const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
|
const comment = await command.createThread({ videoId: videoUUID, text })
|
||||||
const comment = res.body.comment
|
|
||||||
|
|
||||||
expect(comment.inReplyToCommentId).to.be.null
|
expect(comment.inReplyToCommentId).to.be.null
|
||||||
expect(comment.text).equal('my super first comment')
|
expect(comment.text).equal('my super first comment')
|
||||||
|
@ -91,14 +87,14 @@ describe('Test video comments', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list threads of this video', async function () {
|
it('Should list threads of this video', async function () {
|
||||||
const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
|
const body = await command.listThreads({ videoId: videoUUID })
|
||||||
|
|
||||||
expect(res.body.total).to.equal(1)
|
expect(body.total).to.equal(1)
|
||||||
expect(res.body.totalNotDeletedComments).to.equal(1)
|
expect(body.totalNotDeletedComments).to.equal(1)
|
||||||
expect(res.body.data).to.be.an('array')
|
expect(body.data).to.be.an('array')
|
||||||
expect(res.body.data).to.have.lengthOf(1)
|
expect(body.data).to.have.lengthOf(1)
|
||||||
|
|
||||||
const comment: VideoComment = res.body.data[0]
|
const comment = body.data[0]
|
||||||
expect(comment.inReplyToCommentId).to.be.null
|
expect(comment.inReplyToCommentId).to.be.null
|
||||||
expect(comment.text).equal('my super first comment')
|
expect(comment.text).equal('my super first comment')
|
||||||
expect(comment.videoId).to.equal(videoId)
|
expect(comment.videoId).to.equal(videoId)
|
||||||
|
@ -117,9 +113,9 @@ describe('Test video comments', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should get all the thread created', async function () {
|
it('Should get all the thread created', async function () {
|
||||||
const res = await getVideoThreadComments(server.url, videoUUID, threadId)
|
const body = await command.getThread({ videoId: videoUUID, threadId })
|
||||||
|
|
||||||
const rootComment = res.body.comment
|
const rootComment = body.comment
|
||||||
expect(rootComment.inReplyToCommentId).to.be.null
|
expect(rootComment.inReplyToCommentId).to.be.null
|
||||||
expect(rootComment.text).equal('my super first comment')
|
expect(rootComment.text).equal('my super first comment')
|
||||||
expect(rootComment.videoId).to.equal(videoId)
|
expect(rootComment.videoId).to.equal(videoId)
|
||||||
|
@ -129,20 +125,19 @@ describe('Test video comments', function () {
|
||||||
|
|
||||||
it('Should create multiple replies in this thread', async function () {
|
it('Should create multiple replies in this thread', async function () {
|
||||||
const text1 = 'my super answer to thread 1'
|
const text1 = 'my super answer to thread 1'
|
||||||
const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1)
|
const created = await command.addReply({ videoId, toCommentId: threadId, text: text1 })
|
||||||
const childCommentId = childCommentRes.body.comment.id
|
const childCommentId = created.id
|
||||||
|
|
||||||
const text2 = 'my super answer to answer of thread 1'
|
const text2 = 'my super answer to answer of thread 1'
|
||||||
await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2)
|
await command.addReply({ videoId, toCommentId: childCommentId, text: text2 })
|
||||||
|
|
||||||
const text3 = 'my second answer to thread 1'
|
const text3 = 'my second answer to thread 1'
|
||||||
await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3)
|
await command.addReply({ videoId, toCommentId: threadId, text: text3 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should get correctly the replies', async function () {
|
it('Should get correctly the replies', async function () {
|
||||||
const res = await getVideoThreadComments(server.url, videoUUID, threadId)
|
const tree = await command.getThread({ videoId: videoUUID, threadId })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = res.body
|
|
||||||
expect(tree.comment.text).equal('my super first comment')
|
expect(tree.comment.text).equal('my super first comment')
|
||||||
expect(tree.children).to.have.lengthOf(2)
|
expect(tree.children).to.have.lengthOf(2)
|
||||||
|
|
||||||
|
@ -163,42 +158,41 @@ describe('Test video comments', function () {
|
||||||
|
|
||||||
it('Should create other threads', async function () {
|
it('Should create other threads', async function () {
|
||||||
const text1 = 'super thread 2'
|
const text1 = 'super thread 2'
|
||||||
await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1)
|
await command.createThread({ videoId: videoUUID, text: text1 })
|
||||||
|
|
||||||
const text2 = 'super thread 3'
|
const text2 = 'super thread 3'
|
||||||
await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2)
|
await command.createThread({ videoId: videoUUID, text: text2 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list the threads', async function () {
|
it('Should list the threads', async function () {
|
||||||
const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
|
const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
|
||||||
|
|
||||||
expect(res.body.total).to.equal(3)
|
expect(body.total).to.equal(3)
|
||||||
expect(res.body.totalNotDeletedComments).to.equal(6)
|
expect(body.totalNotDeletedComments).to.equal(6)
|
||||||
expect(res.body.data).to.be.an('array')
|
expect(body.data).to.be.an('array')
|
||||||
expect(res.body.data).to.have.lengthOf(3)
|
expect(body.data).to.have.lengthOf(3)
|
||||||
|
|
||||||
expect(res.body.data[0].text).to.equal('my super first comment')
|
expect(body.data[0].text).to.equal('my super first comment')
|
||||||
expect(res.body.data[0].totalReplies).to.equal(3)
|
expect(body.data[0].totalReplies).to.equal(3)
|
||||||
expect(res.body.data[1].text).to.equal('super thread 2')
|
expect(body.data[1].text).to.equal('super thread 2')
|
||||||
expect(res.body.data[1].totalReplies).to.equal(0)
|
expect(body.data[1].totalReplies).to.equal(0)
|
||||||
expect(res.body.data[2].text).to.equal('super thread 3')
|
expect(body.data[2].text).to.equal('super thread 3')
|
||||||
expect(res.body.data[2].totalReplies).to.equal(0)
|
expect(body.data[2].totalReplies).to.equal(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should delete a reply', async function () {
|
it('Should delete a reply', async function () {
|
||||||
await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId)
|
await command.delete({ videoId, commentId: replyToDeleteId })
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
|
const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
|
||||||
|
|
||||||
expect(res.body.total).to.equal(3)
|
expect(body.total).to.equal(3)
|
||||||
expect(res.body.totalNotDeletedComments).to.equal(5)
|
expect(body.totalNotDeletedComments).to.equal(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideoThreadComments(server.url, videoUUID, threadId)
|
const tree = await command.getThread({ videoId: videoUUID, threadId })
|
||||||
|
|
||||||
const tree: VideoCommentThreadTree = res.body
|
|
||||||
expect(tree.comment.text).equal('my super first comment')
|
expect(tree.comment.text).equal('my super first comment')
|
||||||
expect(tree.children).to.have.lengthOf(2)
|
expect(tree.children).to.have.lengthOf(2)
|
||||||
|
|
||||||
|
@ -220,99 +214,88 @@ describe('Test video comments', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should delete a complete thread', async function () {
|
it('Should delete a complete thread', async function () {
|
||||||
await deleteVideoComment(server.url, server.accessToken, videoId, threadId)
|
await command.delete({ videoId, commentId: threadId })
|
||||||
|
|
||||||
const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
|
const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
|
||||||
expect(res.body.total).to.equal(3)
|
expect(body.total).to.equal(3)
|
||||||
expect(res.body.data).to.be.an('array')
|
expect(body.data).to.be.an('array')
|
||||||
expect(res.body.data).to.have.lengthOf(3)
|
expect(body.data).to.have.lengthOf(3)
|
||||||
|
|
||||||
expect(res.body.data[0].text).to.equal('')
|
expect(body.data[0].text).to.equal('')
|
||||||
expect(res.body.data[0].isDeleted).to.be.true
|
expect(body.data[0].isDeleted).to.be.true
|
||||||
expect(res.body.data[0].deletedAt).to.not.be.null
|
expect(body.data[0].deletedAt).to.not.be.null
|
||||||
expect(res.body.data[0].account).to.be.null
|
expect(body.data[0].account).to.be.null
|
||||||
expect(res.body.data[0].totalReplies).to.equal(2)
|
expect(body.data[0].totalReplies).to.equal(2)
|
||||||
expect(res.body.data[1].text).to.equal('super thread 2')
|
expect(body.data[1].text).to.equal('super thread 2')
|
||||||
expect(res.body.data[1].totalReplies).to.equal(0)
|
expect(body.data[1].totalReplies).to.equal(0)
|
||||||
expect(res.body.data[2].text).to.equal('super thread 3')
|
expect(body.data[2].text).to.equal('super thread 3')
|
||||||
expect(res.body.data[2].totalReplies).to.equal(0)
|
expect(body.data[2].totalReplies).to.equal(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should count replies from the video author correctly', async function () {
|
it('Should count replies from the video author correctly', async function () {
|
||||||
const text = 'my super first comment'
|
await command.createThread({ videoId: videoUUID, text: 'my super first comment' })
|
||||||
await addVideoCommentThread(server.url, server.accessToken, videoUUID, text)
|
|
||||||
let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
|
const { data } = await command.listThreads({ videoId: videoUUID })
|
||||||
const comment: VideoComment = res.body.data[0]
|
const threadId2 = data[0].threadId
|
||||||
const threadId2 = comment.threadId
|
|
||||||
|
|
||||||
const text2 = 'a first answer to thread 4 by a third party'
|
const text2 = 'a first answer to thread 4 by a third party'
|
||||||
await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2)
|
await command.addReply({ token: userAccessTokenServer1, videoId, toCommentId: threadId2, text: text2 })
|
||||||
|
|
||||||
const text3 = 'my second answer to thread 4'
|
const text3 = 'my second answer to thread 4'
|
||||||
await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3)
|
await command.addReply({ videoId, toCommentId: threadId2, text: text3 })
|
||||||
|
|
||||||
res = await getVideoThreadComments(server.url, videoUUID, threadId2)
|
const tree = await command.getThread({ videoId: videoUUID, threadId: threadId2 })
|
||||||
const tree: VideoCommentThreadTree = res.body
|
|
||||||
expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1)
|
expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('All instance comments', function () {
|
describe('All instance comments', function () {
|
||||||
async function getComments (options: any = {}) {
|
|
||||||
const res = await getAdminVideoComments(Object.assign({
|
|
||||||
url: server.url,
|
|
||||||
token: server.accessToken,
|
|
||||||
start: 0,
|
|
||||||
count: 10
|
|
||||||
}, options))
|
|
||||||
|
|
||||||
return { comments: res.body.data as VideoCommentAdmin[], total: res.body.total as number }
|
|
||||||
}
|
|
||||||
|
|
||||||
it('Should list instance comments as admin', async function () {
|
it('Should list instance comments as admin', async function () {
|
||||||
const { comments } = await getComments({ start: 0, count: 1 })
|
const { data } = await command.listForAdmin({ start: 0, count: 1 })
|
||||||
|
|
||||||
expect(comments[0].text).to.equal('my second answer to thread 4')
|
expect(data[0].text).to.equal('my second answer to thread 4')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should filter instance comments by isLocal', async function () {
|
it('Should filter instance comments by isLocal', async function () {
|
||||||
const { total, comments } = await getComments({ isLocal: false })
|
const { total, data } = await command.listForAdmin({ isLocal: false })
|
||||||
|
|
||||||
expect(comments).to.have.lengthOf(0)
|
expect(data).to.have.lengthOf(0)
|
||||||
expect(total).to.equal(0)
|
expect(total).to.equal(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should search instance comments by account', async function () {
|
it('Should search instance comments by account', async function () {
|
||||||
const { total, comments } = await getComments({ searchAccount: 'user' })
|
const { total, data } = await command.listForAdmin({ searchAccount: 'user' })
|
||||||
|
|
||||||
expect(comments).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
expect(total).to.equal(1)
|
expect(total).to.equal(1)
|
||||||
|
|
||||||
expect(comments[0].text).to.equal('a first answer to thread 4 by a third party')
|
expect(data[0].text).to.equal('a first answer to thread 4 by a third party')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should search instance comments by video', async function () {
|
it('Should search instance comments by video', async function () {
|
||||||
{
|
{
|
||||||
const { total, comments } = await getComments({ searchVideo: 'video' })
|
const { total, data } = await command.listForAdmin({ searchVideo: 'video' })
|
||||||
|
|
||||||
expect(comments).to.have.lengthOf(7)
|
expect(data).to.have.lengthOf(7)
|
||||||
expect(total).to.equal(7)
|
expect(total).to.equal(7)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const { total, comments } = await getComments({ searchVideo: 'hello' })
|
const { total, data } = await command.listForAdmin({ searchVideo: 'hello' })
|
||||||
|
|
||||||
expect(comments).to.have.lengthOf(0)
|
expect(data).to.have.lengthOf(0)
|
||||||
expect(total).to.equal(0)
|
expect(total).to.equal(0)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should search instance comments', async function () {
|
it('Should search instance comments', async function () {
|
||||||
const { total, comments } = await getComments({ search: 'super thread 3' })
|
const { total, data } = await command.listForAdmin({ search: 'super thread 3' })
|
||||||
|
|
||||||
expect(comments).to.have.lengthOf(1)
|
|
||||||
expect(total).to.equal(1)
|
expect(total).to.equal(1)
|
||||||
expect(comments[0].text).to.equal('super thread 3')
|
|
||||||
|
expect(data).to.have.lengthOf(1)
|
||||||
|
expect(data[0].text).to.equal('super thread 3')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import {
|
import {
|
||||||
addVideoCommentThread,
|
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
|
@ -55,7 +54,7 @@ describe('Test update host scripts', function () {
|
||||||
|
|
||||||
// Create comments
|
// Create comments
|
||||||
const text = 'my super first comment'
|
const text = 'my super first comment'
|
||||||
await addVideoCommentThread(server.url, server.accessToken, video1UUID, text)
|
await server.commentsCommand.createThread({ videoId: video1UUID, text })
|
||||||
|
|
||||||
await waitJobs(server)
|
await waitJobs(server)
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,6 @@ import * as chai from 'chai'
|
||||||
import * as xmlParser from 'fast-xml-parser'
|
import * as xmlParser from 'fast-xml-parser'
|
||||||
import { HttpStatusCode } from '@shared/core-utils'
|
import { HttpStatusCode } from '@shared/core-utils'
|
||||||
import {
|
import {
|
||||||
addVideoCommentThread,
|
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createUser,
|
createUser,
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
|
@ -90,8 +89,8 @@ describe('Test syndication feeds', () => {
|
||||||
const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
|
||||||
const videoId = res.body.video.id
|
const videoId = res.body.video.id
|
||||||
|
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1')
|
await servers[0].commentsCommand.createThread({ videoId, text: 'super comment 1' })
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
|
await servers[0].commentsCommand.createThread({ videoId, text: 'super comment 2' })
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -99,7 +98,7 @@ describe('Test syndication feeds', () => {
|
||||||
const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
|
||||||
const videoId = res.body.video.id
|
const videoId = res.body.video.id
|
||||||
|
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video')
|
await servers[0].commentsCommand.createThread({ videoId, text: 'comment on unlisted video' })
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
@ -277,7 +276,7 @@ describe('Test syndication feeds', () => {
|
||||||
{
|
{
|
||||||
const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
|
const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'super comment')
|
await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'super comment' })
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 3 } })
|
const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 3 } })
|
||||||
|
|
|
@ -3,11 +3,8 @@
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
|
import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
|
||||||
import {
|
import {
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
blockUser,
|
blockUser,
|
||||||
createUser,
|
createUser,
|
||||||
deleteVideoComment,
|
|
||||||
PluginsCommand,
|
PluginsCommand,
|
||||||
registerUser,
|
registerUser,
|
||||||
removeUser,
|
removeUser,
|
||||||
|
@ -101,20 +98,20 @@ describe('Test plugin action hooks', function () {
|
||||||
|
|
||||||
describe('Comments hooks', function () {
|
describe('Comments hooks', function () {
|
||||||
it('Should run action:api.video-thread.created', async function () {
|
it('Should run action:api.video-thread.created', async function () {
|
||||||
const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
|
const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' })
|
||||||
threadId = res.body.comment.id
|
threadId = created.id
|
||||||
|
|
||||||
await checkHook('action:api.video-thread.created')
|
await checkHook('action:api.video-thread.created')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should run action:api.video-comment-reply.created', async function () {
|
it('Should run action:api.video-comment-reply.created', async function () {
|
||||||
await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply')
|
await servers[0].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
|
||||||
|
|
||||||
await checkHook('action:api.video-comment-reply.created')
|
await checkHook('action:api.video-comment-reply.created')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should run action:api.video-comment.deleted', async function () {
|
it('Should run action:api.video-comment.deleted', async function () {
|
||||||
await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
|
await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId: threadId })
|
||||||
|
|
||||||
await checkHook('action:api.video-comment.deleted')
|
await checkHook('action:api.video-comment.deleted')
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,8 +4,6 @@ import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import { HttpStatusCode } from '@shared/core-utils'
|
import { HttpStatusCode } from '@shared/core-utils'
|
||||||
import {
|
import {
|
||||||
addVideoCommentReply,
|
|
||||||
addVideoCommentThread,
|
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
|
@ -13,10 +11,8 @@ import {
|
||||||
getMyVideos,
|
getMyVideos,
|
||||||
getVideo,
|
getVideo,
|
||||||
getVideoChannelVideos,
|
getVideoChannelVideos,
|
||||||
getVideoCommentThreads,
|
|
||||||
getVideosList,
|
getVideosList,
|
||||||
getVideosListPagination,
|
getVideosListPagination,
|
||||||
getVideoThreadComments,
|
|
||||||
getVideoWithToken,
|
getVideoWithToken,
|
||||||
ImportsCommand,
|
ImportsCommand,
|
||||||
makeRawRequest,
|
makeRawRequest,
|
||||||
|
@ -31,7 +27,7 @@ import {
|
||||||
waitJobs,
|
waitJobs,
|
||||||
waitUntilLog
|
waitUntilLog
|
||||||
} from '@shared/extra-utils'
|
} from '@shared/extra-utils'
|
||||||
import { VideoCommentThreadTree, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
|
import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
|
@ -226,44 +222,50 @@ describe('Test plugin filter hooks', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should run filter:api.video-thread.create.accept.result', async function () {
|
it('Should run filter:api.video-thread.create.accept.result', async function () {
|
||||||
await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', HttpStatusCode.FORBIDDEN_403)
|
await servers[0].commentsCommand.createThread({
|
||||||
|
videoId: videoUUID,
|
||||||
|
text: 'comment with bad word',
|
||||||
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
|
it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
|
||||||
const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
|
const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' })
|
||||||
threadId = res.body.comment.id
|
threadId = created.id
|
||||||
|
|
||||||
await addVideoCommentReply(
|
await servers[0].commentsCommand.addReply({
|
||||||
servers[0].url,
|
videoId: videoUUID,
|
||||||
servers[0].accessToken,
|
toCommentId: threadId,
|
||||||
videoUUID,
|
text: 'comment with bad word',
|
||||||
threadId,
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
||||||
'comment with bad word',
|
})
|
||||||
HttpStatusCode.FORBIDDEN_403
|
await servers[0].commentsCommand.addReply({
|
||||||
)
|
videoId: videoUUID,
|
||||||
await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', HttpStatusCode.OK_200)
|
toCommentId: threadId,
|
||||||
|
text: 'comment with good word',
|
||||||
|
expectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should run filter:api.video-threads.list.params', async function () {
|
it('Should run filter:api.video-threads.list.params', async function () {
|
||||||
const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 0 })
|
||||||
|
|
||||||
// our plugin do +1 to the count parameter
|
// our plugin do +1 to the count parameter
|
||||||
expect(res.body.data).to.have.lengthOf(1)
|
expect(data).to.have.lengthOf(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should run filter:api.video-threads.list.result', async function () {
|
it('Should run filter:api.video-threads.list.result', async function () {
|
||||||
const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
|
const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 0 })
|
||||||
|
|
||||||
// Plugin do +1 to the total result
|
// Plugin do +1 to the total result
|
||||||
expect(res.body.total).to.equal(2)
|
expect(total).to.equal(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should run filter:api.video-thread-comments.list.params')
|
it('Should run filter:api.video-thread-comments.list.params')
|
||||||
|
|
||||||
it('Should run filter:api.video-thread-comments.list.result', async function () {
|
it('Should run filter:api.video-thread-comments.list.result', async function () {
|
||||||
const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId)
|
const thread = await servers[0].commentsCommand.getThread({ videoId: videoUUID, threadId })
|
||||||
|
|
||||||
const thread = res.body as VideoCommentThreadTree
|
|
||||||
expect(thread.comment.text.endsWith(' <3')).to.be.true
|
expect(thread.comment.text.endsWith(' <3')).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import {
|
||||||
ServicesCommand,
|
ServicesCommand,
|
||||||
StreamingPlaylistsCommand
|
StreamingPlaylistsCommand
|
||||||
} from '../videos'
|
} from '../videos'
|
||||||
|
import { CommentsCommand } from '../videos/comments-command'
|
||||||
import { ConfigCommand } from './config-command'
|
import { ConfigCommand } from './config-command'
|
||||||
import { ContactFormCommand } from './contact-form-command'
|
import { ContactFormCommand } from './contact-form-command'
|
||||||
import { DebugCommand } from './debug-command'
|
import { DebugCommand } from './debug-command'
|
||||||
|
@ -121,6 +122,7 @@ interface ServerInfo {
|
||||||
importsCommand?: ImportsCommand
|
importsCommand?: ImportsCommand
|
||||||
streamingPlaylistsCommand?: StreamingPlaylistsCommand
|
streamingPlaylistsCommand?: StreamingPlaylistsCommand
|
||||||
channelsCommand?: ChannelsCommand
|
channelsCommand?: ChannelsCommand
|
||||||
|
commentsCommand?: CommentsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
function parallelTests () {
|
function parallelTests () {
|
||||||
|
@ -356,6 +358,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
|
||||||
server.importsCommand = new ImportsCommand(server)
|
server.importsCommand = new ImportsCommand(server)
|
||||||
server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server)
|
server.streamingPlaylistsCommand = new StreamingPlaylistsCommand(server)
|
||||||
server.channelsCommand = new ChannelsCommand(server)
|
server.channelsCommand = new ChannelsCommand(server)
|
||||||
|
server.commentsCommand = new CommentsCommand(server)
|
||||||
|
|
||||||
res(server)
|
res(server)
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
import { pick } from 'lodash'
|
||||||
|
import { ResultList, VideoComment, VideoCommentThreads, VideoCommentThreadTree } from '@shared/models'
|
||||||
|
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
|
||||||
|
import { unwrapBody } from '../requests'
|
||||||
|
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
||||||
|
|
||||||
|
export class CommentsCommand extends AbstractCommand {
|
||||||
|
|
||||||
|
listForAdmin (options: OverrideCommandOptions & {
|
||||||
|
start?: number
|
||||||
|
count?: number
|
||||||
|
sort?: string
|
||||||
|
isLocal?: boolean
|
||||||
|
search?: string
|
||||||
|
searchAccount?: string
|
||||||
|
searchVideo?: string
|
||||||
|
} = {}) {
|
||||||
|
const { sort = '-createdAt' } = options
|
||||||
|
const path = '/api/v1/videos/comments'
|
||||||
|
|
||||||
|
const query = { sort, ...pick(options, [ 'start', 'count', 'isLocal', 'search', 'searchAccount', 'searchVideo' ]) }
|
||||||
|
|
||||||
|
return this.getRequestBody<ResultList<VideoComment>>({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
path,
|
||||||
|
query,
|
||||||
|
implicitToken: true,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
listThreads (options: OverrideCommandOptions & {
|
||||||
|
videoId: number | string
|
||||||
|
start?: number
|
||||||
|
count?: number
|
||||||
|
sort?: string
|
||||||
|
}) {
|
||||||
|
const { start, count, sort, videoId } = options
|
||||||
|
const path = '/api/v1/videos/' + videoId + '/comment-threads'
|
||||||
|
|
||||||
|
return this.getRequestBody<VideoCommentThreads>({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
path,
|
||||||
|
query: { start, count, sort },
|
||||||
|
implicitToken: false,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
getThread (options: OverrideCommandOptions & {
|
||||||
|
videoId: number | string
|
||||||
|
threadId: number
|
||||||
|
}) {
|
||||||
|
const { videoId, threadId } = options
|
||||||
|
const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
|
||||||
|
|
||||||
|
return this.getRequestBody<VideoCommentThreadTree>({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
path,
|
||||||
|
implicitToken: false,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async createThread (options: OverrideCommandOptions & {
|
||||||
|
videoId: number | string
|
||||||
|
text: string
|
||||||
|
}) {
|
||||||
|
const { videoId, text } = options
|
||||||
|
const path = '/api/v1/videos/' + videoId + '/comment-threads'
|
||||||
|
|
||||||
|
const body = await unwrapBody<{ comment: VideoComment }>(this.postBodyRequest({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
path,
|
||||||
|
fields: { text },
|
||||||
|
implicitToken: true,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
|
}))
|
||||||
|
|
||||||
|
return body.comment
|
||||||
|
}
|
||||||
|
|
||||||
|
async addReply (options: OverrideCommandOptions & {
|
||||||
|
videoId: number | string
|
||||||
|
toCommentId: number
|
||||||
|
text: string
|
||||||
|
}) {
|
||||||
|
const { videoId, toCommentId, text } = options
|
||||||
|
const path = '/api/v1/videos/' + videoId + '/comments/' + toCommentId
|
||||||
|
|
||||||
|
const body = await unwrapBody<{ comment: VideoComment }>(this.postBodyRequest({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
path,
|
||||||
|
fields: { text },
|
||||||
|
implicitToken: true,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
|
}))
|
||||||
|
|
||||||
|
return body.comment
|
||||||
|
}
|
||||||
|
|
||||||
|
async findCommentId (options: OverrideCommandOptions & {
|
||||||
|
videoId: number | string
|
||||||
|
text: string
|
||||||
|
}) {
|
||||||
|
const { videoId, text } = options
|
||||||
|
const { data } = await this.listThreads({ videoId, count: 25, sort: '-createdAt' })
|
||||||
|
|
||||||
|
return data.find(c => c.text === text).id
|
||||||
|
}
|
||||||
|
|
||||||
|
delete (options: OverrideCommandOptions & {
|
||||||
|
videoId: number | string
|
||||||
|
commentId: number
|
||||||
|
}) {
|
||||||
|
const { videoId, commentId } = options
|
||||||
|
const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
|
||||||
|
|
||||||
|
return this.deleteRequest({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
path,
|
||||||
|
implicitToken: true,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ export * from './captions'
|
||||||
export * from './change-ownership-command'
|
export * from './change-ownership-command'
|
||||||
export * from './channels'
|
export * from './channels'
|
||||||
export * from './channels-command'
|
export * from './channels-command'
|
||||||
|
export * from './comments-command'
|
||||||
export * from './history-command'
|
export * from './history-command'
|
||||||
export * from './imports-command'
|
export * from './imports-command'
|
||||||
export * from './live-command'
|
export * from './live-command'
|
||||||
|
@ -13,5 +14,5 @@ export * from './playlists'
|
||||||
export * from './services-command'
|
export * from './services-command'
|
||||||
export * from './streaming-playlists-command'
|
export * from './streaming-playlists-command'
|
||||||
export * from './streaming-playlists'
|
export * from './streaming-playlists'
|
||||||
export * from './video-comments'
|
export * from './comments-command'
|
||||||
export * from './videos'
|
export * from './videos'
|
||||||
|
|
|
@ -27,7 +27,7 @@ export class StreamingPlaylistsCommand extends AbstractCommand {
|
||||||
url: options.url,
|
url: options.url,
|
||||||
range: options.range,
|
range: options.range,
|
||||||
implicitToken: false,
|
implicitToken: false,
|
||||||
defaultExpectedStatus: HttpStatusCode.OK_200,
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,138 +0,0 @@
|
||||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
||||||
|
|
||||||
import * as request from 'supertest'
|
|
||||||
import { makeDeleteRequest, makeGetRequest } from '../requests/requests'
|
|
||||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
|
||||||
|
|
||||||
function getAdminVideoComments (options: {
|
|
||||||
url: string
|
|
||||||
token: string
|
|
||||||
start: number
|
|
||||||
count: number
|
|
||||||
sort?: string
|
|
||||||
isLocal?: boolean
|
|
||||||
search?: string
|
|
||||||
searchAccount?: string
|
|
||||||
searchVideo?: string
|
|
||||||
}) {
|
|
||||||
const { url, token, start, count, sort, isLocal, search, searchAccount, searchVideo } = options
|
|
||||||
const path = '/api/v1/videos/comments'
|
|
||||||
|
|
||||||
const query = {
|
|
||||||
start,
|
|
||||||
count,
|
|
||||||
sort: sort || '-createdAt'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLocal !== undefined) Object.assign(query, { isLocal })
|
|
||||||
if (search !== undefined) Object.assign(query, { search })
|
|
||||||
if (searchAccount !== undefined) Object.assign(query, { searchAccount })
|
|
||||||
if (searchVideo !== undefined) Object.assign(query, { searchVideo })
|
|
||||||
|
|
||||||
return makeGetRequest({
|
|
||||||
url,
|
|
||||||
path,
|
|
||||||
token,
|
|
||||||
query,
|
|
||||||
statusCodeExpected: HttpStatusCode.OK_200
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) {
|
|
||||||
const path = '/api/v1/videos/' + videoId + '/comment-threads'
|
|
||||||
|
|
||||||
const req = request(url)
|
|
||||||
.get(path)
|
|
||||||
.query({ start: start })
|
|
||||||
.query({ count: count })
|
|
||||||
|
|
||||||
if (sort) req.query({ sort })
|
|
||||||
if (token) req.set('Authorization', 'Bearer ' + token)
|
|
||||||
|
|
||||||
return req.set('Accept', 'application/json')
|
|
||||||
.expect(HttpStatusCode.OK_200)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) {
|
|
||||||
const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId
|
|
||||||
|
|
||||||
const req = request(url)
|
|
||||||
.get(path)
|
|
||||||
.set('Accept', 'application/json')
|
|
||||||
|
|
||||||
if (token) req.set('Authorization', 'Bearer ' + token)
|
|
||||||
|
|
||||||
return req.expect(HttpStatusCode.OK_200)
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
}
|
|
||||||
|
|
||||||
function addVideoCommentThread (
|
|
||||||
url: string,
|
|
||||||
token: string,
|
|
||||||
videoId: number | string,
|
|
||||||
text: string,
|
|
||||||
expectedStatus = HttpStatusCode.OK_200
|
|
||||||
) {
|
|
||||||
const path = '/api/v1/videos/' + videoId + '/comment-threads'
|
|
||||||
|
|
||||||
return request(url)
|
|
||||||
.post(path)
|
|
||||||
.send({ text })
|
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.set('Authorization', 'Bearer ' + token)
|
|
||||||
.expect(expectedStatus)
|
|
||||||
}
|
|
||||||
|
|
||||||
function addVideoCommentReply (
|
|
||||||
url: string,
|
|
||||||
token: string,
|
|
||||||
videoId: number | string,
|
|
||||||
inReplyToCommentId: number,
|
|
||||||
text: string,
|
|
||||||
expectedStatus = HttpStatusCode.OK_200
|
|
||||||
) {
|
|
||||||
const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId
|
|
||||||
|
|
||||||
return request(url)
|
|
||||||
.post(path)
|
|
||||||
.send({ text })
|
|
||||||
.set('Accept', 'application/json')
|
|
||||||
.set('Authorization', 'Bearer ' + token)
|
|
||||||
.expect(expectedStatus)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function findCommentId (url: string, videoId: number | string, text: string) {
|
|
||||||
const res = await getVideoCommentThreads(url, videoId, 0, 25, '-createdAt')
|
|
||||||
|
|
||||||
return res.body.data.find(c => c.text === text).id as number
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteVideoComment (
|
|
||||||
url: string,
|
|
||||||
token: string,
|
|
||||||
videoId: number | string,
|
|
||||||
commentId: number,
|
|
||||||
statusCodeExpected = HttpStatusCode.NO_CONTENT_204
|
|
||||||
) {
|
|
||||||
const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
|
|
||||||
|
|
||||||
return makeDeleteRequest({
|
|
||||||
url,
|
|
||||||
path,
|
|
||||||
token,
|
|
||||||
statusCodeExpected
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export {
|
|
||||||
getVideoCommentThreads,
|
|
||||||
getAdminVideoComments,
|
|
||||||
getVideoThreadComments,
|
|
||||||
addVideoCommentThread,
|
|
||||||
addVideoCommentReply,
|
|
||||||
findCommentId,
|
|
||||||
deleteVideoComment
|
|
||||||
}
|
|
|
@ -1 +1,2 @@
|
||||||
|
export * from './video-comment-create.model'
|
||||||
export * from './video-comment.model'
|
export * from './video-comment.model'
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export interface VideoCommentCreate {
|
||||||
|
text: string
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ResultList } from '@shared/models/common'
|
||||||
import { Account } from '../../actors'
|
import { Account } from '../../actors'
|
||||||
|
|
||||||
export interface VideoComment {
|
export interface VideoComment {
|
||||||
|
@ -36,11 +37,9 @@ export interface VideoCommentAdmin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type VideoCommentThreads = ResultList<VideoComment> & { totalNotDeletedComments: number }
|
||||||
|
|
||||||
export interface VideoCommentThreadTree {
|
export interface VideoCommentThreadTree {
|
||||||
comment: VideoComment
|
comment: VideoComment
|
||||||
children: VideoCommentThreadTree[]
|
children: VideoCommentThreadTree[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VideoCommentCreate {
|
|
||||||
text: string
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue