-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
getVideoCommentThreads,
getVideoThreadComments,
immutableAssign,
+ MockInstancesIndex,
registerUser,
removeVideoFromBlacklist,
reportVideoAbuse,
+ unfollow,
updateCustomConfig,
+ updateCustomSubConfig,
updateMyUser,
updateVideo,
updateVideoChannel,
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
import {
+ checkAutoInstanceFollowing,
checkCommentMention,
CheckerBaseParams,
checkMyVideoImportIsFinished,
import { VideoPrivacy } from '../../../../shared/models/videos'
import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
-import * as uuidv4 from 'uuid/v4'
+import { v4 as uuidv4 } from 'uuid'
import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
import { CustomConfig } from '../../../../shared/models/server'
import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
const name = 'remote video ' + uuidv4()
const data = Object.assign({ name }, additionalParams)
- const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, data)
+ const res = await uploadVideo(servers[1].url, servers[1].accessToken, data)
await waitJobs(servers)
const name = 'local video ' + uuidv4()
const data = Object.assign({ name }, additionalParams)
- const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, data)
+ const res = await uploadVideo(servers[0].url, servers[0].accessToken, data)
await waitJobs(servers)
describe('Test users notifications', function () {
let servers: ServerInfo[] = []
let userAccessToken: string
- let userNotifications: UserNotification[] = []
- let adminNotifications: UserNotification[] = []
- let adminNotificationsServer2: UserNotification[] = []
+ const userNotifications: UserNotification[] = []
+ const adminNotifications: UserNotification[] = []
+ const adminNotificationsServer2: UserNotification[] = []
const emails: object[] = []
let channelId: number
commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
- newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
+ newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
+ autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
}
before(async function () {
password: 'super password'
}
await createUser({
- url: servers[ 0 ].url,
- accessToken: servers[ 0 ].accessToken,
+ url: servers[0].url,
+ accessToken: servers[0].accessToken,
username: user.username,
password: user.password,
videoQuota: 10 * 1000 * 1000
await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings)
{
- const socket = getUserNotificationSocket(servers[ 0 ].url, userAccessToken)
+ const socket = getUserNotificationSocket(servers[0].url, userAccessToken)
socket.on('new-notification', n => userNotifications.push(n))
}
{
- const socket = getUserNotificationSocket(servers[ 0 ].url, servers[0].accessToken)
+ const socket = getUserNotificationSocket(servers[0].url, servers[0].accessToken)
socket.on('new-notification', n => adminNotifications.push(n))
}
{
- const socket = getUserNotificationSocket(servers[ 1 ].url, servers[1].accessToken)
+ const socket = getUserNotificationSocket(servers[1].url, servers[1].accessToken)
socket.on('new-notification', n => adminNotificationsServer2.push(n))
}
await uploadVideoByLocalAccount(servers)
- const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
+ const notification = await getLastNotification(servers[0].url, userAccessToken)
expect(notification).to.be.undefined
expect(emails).to.have.lengthOf(0)
this.timeout(20000)
// In 2 seconds
- let updateAt = new Date(new Date().getTime() + 2000)
+ const updateAt = new Date(new Date().getTime() + 2000)
const data = {
privacy: VideoPrivacy.PRIVATE,
this.timeout(50000)
// In 2 seconds
- let updateAt = new Date(new Date().getTime() + 2000)
+ const updateAt = new Date(new Date().getTime() + 2000)
const data = {
privacy: VideoPrivacy.PRIVATE,
it('Should not send a notification before the video is published', async function () {
this.timeout(20000)
- let updateAt = new Date(new Date().getTime() + 1000000)
+ const updateAt = new Date(new Date().getTime() + 1000000)
const data = {
privacy: VideoPrivacy.PRIVATE,
it('Should not send a new comment notification if the account is muted', async function () {
this.timeout(10000)
- await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
+ await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
await wait(500)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
- await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
+ await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
})
it('Should send a new comment notification after a local comment on my video', async function () {
await waitJobs(servers)
{
- const resThread = await addVideoCommentThread(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, 'comment')
+ const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
const threadId = resThread.body.comment.id
- await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, uuid, threadId, 'reply')
+ await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
}
await waitJobs(servers)
it('Should not send a new mention notification if the account is muted', async function () {
this.timeout(10000)
- await addAccountToAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
+ await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
const uuid = resVideo.body.video.uuid
await wait(500)
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
- await removeAccountFromAccountBlocklist(servers[ 0 ].url, userAccessToken, 'root')
+ await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
})
it('Should not send a new mention notification if the remote account mention a local account', async function () {
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 server2ThreadId = resThread.body.comment.id
const server1ThreadId = resThread2.body.data[0].id
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 waitJobs(servers)
})
})
- describe('Video abuse for moderators notification' , function () {
+ describe('Video abuse for moderators notification', function () {
let baseParams: CheckerBaseParams
before(() => {
await uploadVideoByRemoteAccount(servers, { waitTranscoding: false })
await waitJobs(servers)
- const notification = await getLastNotification(servers[ 0 ].url, userAccessToken)
+ const notification = await getLastNotification(servers[0].url, userAccessToken)
if (notification) {
expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
}
this.timeout(70000)
// In 2 seconds
- let updateAt = new Date(new Date().getTime() + 2000)
+ const updateAt = new Date(new Date().getTime() + 2000)
const data = {
privacy: VideoPrivacy.PRIVATE,
it('Should not send a notification before the video is published', async function () {
this.timeout(20000)
- let updateAt = new Date(new Date().getTime() + 100000)
+ const updateAt = new Date(new Date().getTime() + 1000000)
const data = {
privacy: VideoPrivacy.PRIVATE,
})
})
- describe('New instance follower', function () {
+ describe('New instance follows', function () {
+ const instanceIndexServer = new MockInstancesIndex()
+ const config = {
+ followings: {
+ instance: {
+ autoFollowIndex: {
+ indexUrl: 'http://localhost:42100',
+ enabled: true
+ }
+ }
+ }
+ }
let baseParams: CheckerBaseParams
before(async () => {
socketNotifications: adminNotifications,
token: servers[0].accessToken
}
+
+ await instanceIndexServer.initialize()
+ instanceIndexServer.addInstance(servers[1].host)
})
it('Should send a notification only to admin when there is a new instance follower', async function () {
const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence')
})
+
+ it('Should send a notification on auto follow back', async function () {
+ this.timeout(40000)
+
+ await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+ await waitJobs(servers)
+
+ const config = {
+ followings: {
+ instance: {
+ autoFollowBack: { enabled: true }
+ }
+ }
+ }
+ await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+
+ await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
+
+ await waitJobs(servers)
+
+ const followerHost = servers[0].host
+ const followingHost = servers[2].host
+ await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
+
+ const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
+ await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence')
+
+ config.followings.instance.autoFollowBack.enabled = false
+ await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+ await unfollow(servers[0].url, servers[0].accessToken, servers[2])
+ await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+ })
+
+ it('Should send a notification on auto instances index follow', async function () {
+ this.timeout(30000)
+ await unfollow(servers[0].url, servers[0].accessToken, servers[1])
+
+ await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+
+ await wait(5000)
+ await waitJobs(servers)
+
+ const followerHost = servers[0].host
+ const followingHost = servers[1].host
+ await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
+
+ config.followings.instance.autoFollowIndex.enabled = false
+ await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+ await unfollow(servers[0].url, servers[0].accessToken, servers[1])
+ })
})
describe('New actor follow', function () {
let baseParams: CheckerBaseParams
- let myChannelName = 'super channel name'
- let myUserName = 'super user name'
+ const myChannelName = 'super channel name'
+ const myUserName = 'super user name'
before(async () => {
baseParams = {
await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
})
- it('Should notify when a local account is following one of our channel', async function () {
- this.timeout(10000)
-
- await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
-
- await waitJobs(servers)
-
- await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
- })
+ // PeerTube does not support accout -> account follows
+ // it('Should notify when a local account is following one of our channel', async function () {
+ // this.timeout(10000)
+ //
+ // await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1@localhost:' + servers[0].port)
+ //
+ // await waitJobs(servers)
+ //
+ // await checkNewActorFollow(baseParams, 'account', 'root', 'super root name', myUserName, 'presence')
+ // })
it('Should notify when a remote account is following one of our channel', async function () {
this.timeout(10000)
it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
this.timeout(20000)
- let updateAt = new Date(new Date().getTime() + 100000)
+ const updateAt = new Date(new Date().getTime() + 1000000)
const name = 'video with auto-blacklist and future schedule ' + uuidv4()
this.timeout(20000)
// In 2 seconds
- let updateAt = new Date(new Date().getTime() + 2000)
+ const updateAt = new Date(new Date().getTime() + 2000)
const name = 'video with schedule done and still auto-blacklisted ' + uuidv4()
describe('Mark as read', function () {
it('Should mark as read some notifications', async function () {
- const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 2, 3)
+ const res = await getUserNotifications(servers[0].url, userAccessToken, 2, 3)
const ids = res.body.data.map(n => n.id)
- await markAsReadNotifications(servers[ 0 ].url, userAccessToken, ids)
+ await markAsReadNotifications(servers[0].url, userAccessToken, ids)
})
it('Should have the notifications marked as read', async function () {
- const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10)
+ const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10)
const notifications = res.body.data as UserNotification[]
- expect(notifications[ 0 ].read).to.be.false
- expect(notifications[ 1 ].read).to.be.false
- expect(notifications[ 2 ].read).to.be.true
- expect(notifications[ 3 ].read).to.be.true
- expect(notifications[ 4 ].read).to.be.true
- expect(notifications[ 5 ].read).to.be.false
+ expect(notifications[0].read).to.be.false
+ expect(notifications[1].read).to.be.false
+ expect(notifications[2].read).to.be.true
+ expect(notifications[3].read).to.be.true
+ expect(notifications[4].read).to.be.true
+ expect(notifications[5].read).to.be.false
})
it('Should only list read notifications', async function () {
- const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, false)
+ const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10, false)
const notifications = res.body.data as UserNotification[]
for (const notification of notifications) {
})
it('Should only list unread notifications', async function () {
- const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
+ const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10, true)
const notifications = res.body.data as UserNotification[]
for (const notification of notifications) {
})
it('Should mark as read all notifications', async function () {
- await markAsReadAllNotifications(servers[ 0 ].url, userAccessToken)
+ await markAsReadAllNotifications(servers[0].url, userAccessToken)
- const res = await getUserNotifications(servers[ 0 ].url, userAccessToken, 0, 10, true)
+ const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10, true)
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)