2020-06-16 08:52:05 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import {
|
|
|
|
checkCommentMention,
|
|
|
|
CheckerBaseParams,
|
|
|
|
checkNewCommentOnMyVideo,
|
2021-05-11 04:27:40 -05:00
|
|
|
cleanupTests,
|
|
|
|
MockSmtpServer,
|
|
|
|
prepareNotificationsTest,
|
|
|
|
ServerInfo,
|
|
|
|
updateMyUser,
|
|
|
|
uploadVideo,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/extra-utils'
|
2021-07-09 07:15:11 -05:00
|
|
|
import { UserNotification } from '@shared/models'
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test comments notifications', function () {
|
|
|
|
let servers: ServerInfo[] = []
|
2021-07-09 07:15:11 -05:00
|
|
|
let userToken: string
|
2020-06-16 08:52:05 -05:00
|
|
|
let userNotifications: UserNotification[] = []
|
|
|
|
let emails: object[] = []
|
|
|
|
|
2020-11-17 07:38:27 -06:00
|
|
|
const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
|
|
|
|
const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
|
|
|
|
'<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
|
|
|
|
'-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
|
|
|
|
|
2020-06-16 08:52:05 -05:00
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
|
|
|
const res = await prepareNotificationsTest(2)
|
|
|
|
emails = res.emails
|
2021-07-09 07:15:11 -05:00
|
|
|
userToken = res.userAccessToken
|
2020-06-16 08:52:05 -05:00
|
|
|
servers = res.servers
|
|
|
|
userNotifications = res.userNotifications
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Comment on my video notifications', function () {
|
|
|
|
let baseParams: CheckerBaseParams
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
baseParams = {
|
|
|
|
server: servers[0],
|
|
|
|
emails,
|
|
|
|
socketNotifications: userNotifications,
|
2021-07-09 07:15:11 -05:00
|
|
|
token: userToken
|
2020-06-16 08:52:05 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send a new comment notification after a comment on another video', async function () {
|
2020-12-30 04:27:59 -06:00
|
|
|
this.timeout(20000)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
|
|
|
const commentId = created.id
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send a new comment notification if I comment my own video', async function () {
|
2020-12-30 04:27:59 -06:00
|
|
|
this.timeout(20000)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
|
2020-06-16 08:52:05 -05:00
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
|
|
|
|
const commentId = created.id
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send a new comment notification if the account is muted', async function () {
|
2020-12-30 04:27:59 -06:00
|
|
|
this.timeout(20000)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
|
2020-06-16 08:52:05 -05:00
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
|
|
|
const commentId = created.id
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
|
2020-06-16 08:52:05 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a new comment notification after a local comment on my video', async function () {
|
2020-12-30 04:27:59 -06:00
|
|
|
this.timeout(20000)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
|
2020-06-16 08:52:05 -05:00
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
|
|
|
const commentId = created.id
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a new comment notification after a remote comment on my video', async function () {
|
2020-12-30 04:27:59 -06:00
|
|
|
this.timeout(20000)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
|
2020-06-16 08:52:05 -05:00
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const commentId = data[0].id
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a new comment notification after a local reply on my video', async function () {
|
2020-12-30 04:27:59 -06:00
|
|
|
this.timeout(20000)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
|
2020-06-16 08:52:05 -05:00
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a new comment notification after a remote reply on my video', async function () {
|
2020-12-30 04:27:59 -06:00
|
|
|
this.timeout(20000)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
|
2020-06-16 08:52:05 -05:00
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
{
|
2021-07-09 07:15:11 -05:00
|
|
|
const created = await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
|
|
|
|
const threadId = created.id
|
|
|
|
await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
|
2020-06-16 08:52:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const threadId = data[0].id
|
|
|
|
const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
expect(tree.children).to.have.lengthOf(1)
|
|
|
|
const commentId = tree.children[0].comment.id
|
|
|
|
|
|
|
|
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
|
|
|
|
})
|
2020-11-17 07:24:55 -06:00
|
|
|
|
|
|
|
it('Should convert markdown in comment to html', async function () {
|
2020-12-30 04:27:59 -06:00
|
|
|
this.timeout(20000)
|
2020-11-17 07:24:55 -06:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' })
|
2020-11-17 07:24:55 -06:00
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText })
|
2020-11-17 07:24:55 -06:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
const latestEmail = emails[emails.length - 1]
|
2020-11-17 07:38:27 -06:00
|
|
|
expect(latestEmail['html']).to.contain(expectedHtml)
|
2020-11-17 07:24:55 -06:00
|
|
|
})
|
2020-06-16 08:52:05 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('Mention notifications', function () {
|
|
|
|
let baseParams: CheckerBaseParams
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
baseParams = {
|
|
|
|
server: servers[0],
|
|
|
|
emails,
|
|
|
|
socketNotifications: userNotifications,
|
2021-07-09 07:15:11 -05:00
|
|
|
token: userToken
|
2020-06-16 08:52:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateMyUser({
|
|
|
|
url: servers[0].url,
|
|
|
|
accessToken: servers[0].accessToken,
|
|
|
|
displayName: 'super root name'
|
|
|
|
})
|
|
|
|
|
|
|
|
await updateMyUser({
|
|
|
|
url: servers[1].url,
|
|
|
|
accessToken: servers[1].accessToken,
|
|
|
|
displayName: 'super root 2 name'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send a new mention comment notification if I mention the video owner', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
|
2020-06-16 08:52:05 -05:00
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send a new mention comment notification if I mention myself', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send a new mention notification if the account is muted', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
|
2020-06-16 08:52:05 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send a new mention notification if the remote account mention a local account', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a new mention notification after local comments', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
await waitJobs(servers)
|
2020-06-16 08:52:05 -05:00
|
|
|
await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a new mention notification after remote comments', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
const text1 = `hello @user_1@localhost:${servers[0].port} 1`
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: server2ThreadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: text1 })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
|
|
|
|
expect(data).to.have.lengthOf(1)
|
|
|
|
|
|
|
|
const server1ThreadId = data[0].id
|
2020-06-16 08:52:05 -05:00
|
|
|
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}`
|
2021-07-09 07:15:11 -05:00
|
|
|
await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId: server1ThreadId })
|
2020-06-16 08:52:05 -05:00
|
|
|
|
|
|
|
expect(tree.children).to.have.lengthOf(1)
|
|
|
|
const commentId = tree.children[0].comment.id
|
|
|
|
|
|
|
|
await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
|
|
|
|
})
|
2020-11-17 07:38:27 -06:00
|
|
|
|
|
|
|
it('Should convert markdown in comment to html', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
|
|
|
|
const uuid = resVideo.body.video.uuid
|
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' })
|
2020-11-17 07:38:27 -06:00
|
|
|
|
2021-07-09 07:15:11 -05:00
|
|
|
await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
|
2020-11-17 07:38:27 -06:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
const latestEmail = emails[emails.length - 1]
|
|
|
|
expect(latestEmail['html']).to.contain(expectedHtml)
|
|
|
|
})
|
2020-06-16 08:52:05 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
MockSmtpServer.Instance.kill()
|
|
|
|
|
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|