aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/notifications
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/notifications')
-rw-r--r--server/tests/api/notifications/admin-notifications.ts49
-rw-r--r--server/tests/api/notifications/comments-notifications.ts207
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts288
-rw-r--r--server/tests/api/notifications/notifications-api.ts132
-rw-r--r--server/tests/api/notifications/user-notifications.ts197
5 files changed, 401 insertions, 472 deletions
diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts
index cfe0bd2bb..c00d4e257 100644
--- a/server/tests/api/notifications/admin-notifications.ts
+++ b/server/tests/api/notifications/admin-notifications.ts
@@ -2,21 +2,21 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { MockJoinPeerTubeVersions } from '@shared/extra-utils/mock-servers/joinpeertube-versions'
6import { PluginType } from '@shared/models'
7import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils'
8import { ServerInfo } from '../../../../shared/extra-utils/index'
9import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
10import { 5import {
11 CheckerBaseParams, 6 CheckerBaseParams,
12 checkNewPeerTubeVersion, 7 checkNewPeerTubeVersion,
13 checkNewPluginVersion, 8 checkNewPluginVersion,
14 prepareNotificationsTest 9 cleanupTests,
15} from '../../../../shared/extra-utils/users/user-notifications' 10 MockJoinPeerTubeVersions,
16import { UserNotification, UserNotificationType } from '../../../../shared/models/users' 11 MockSmtpServer,
12 PeerTubeServer,
13 prepareNotificationsTest,
14 wait
15} from '@shared/extra-utils'
16import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
17 17
18describe('Test admin notifications', function () { 18describe('Test admin notifications', function () {
19 let server: ServerInfo 19 let server: PeerTubeServer
20 let userNotifications: UserNotification[] = [] 20 let userNotifications: UserNotification[] = []
21 let adminNotifications: UserNotification[] = [] 21 let adminNotifications: UserNotification[] = []
22 let emails: object[] = [] 22 let emails: object[] = []
@@ -58,17 +58,8 @@ describe('Test admin notifications', function () {
58 token: server.accessToken 58 token: server.accessToken
59 } 59 }
60 60
61 await installPlugin({ 61 await server.plugins.install({ npmName: 'peertube-plugin-hello-world' })
62 url: server.url, 62 await server.plugins.install({ npmName: 'peertube-theme-background-red' })
63 accessToken: server.accessToken,
64 npmName: 'peertube-plugin-hello-world'
65 })
66
67 await installPlugin({
68 url: server.url,
69 accessToken: server.accessToken,
70 npmName: 'peertube-theme-background-red'
71 })
72 }) 63 })
73 64
74 describe('Latest PeerTube version notification', function () { 65 describe('Latest PeerTube version notification', function () {
@@ -79,7 +70,7 @@ describe('Test admin notifications', function () {
79 joinPeerTubeServer.setLatestVersion('1.4.2') 70 joinPeerTubeServer.setLatestVersion('1.4.2')
80 71
81 await wait(3000) 72 await wait(3000)
82 await checkNewPeerTubeVersion(baseParams, '1.4.2', 'absence') 73 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' })
83 }) 74 })
84 75
85 it('Should send a notification to admins on new plugin version', async function () { 76 it('Should send a notification to admins on new plugin version', async function () {
@@ -88,7 +79,7 @@ describe('Test admin notifications', function () {
88 joinPeerTubeServer.setLatestVersion('15.4.2') 79 joinPeerTubeServer.setLatestVersion('15.4.2')
89 80
90 await wait(3000) 81 await wait(3000)
91 await checkNewPeerTubeVersion(baseParams, '15.4.2', 'presence') 82 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' })
92 }) 83 })
93 84
94 it('Should not send the same notification to admins', async function () { 85 it('Should not send the same notification to admins', async function () {
@@ -110,7 +101,7 @@ describe('Test admin notifications', function () {
110 joinPeerTubeServer.setLatestVersion('15.4.3') 101 joinPeerTubeServer.setLatestVersion('15.4.3')
111 102
112 await wait(3000) 103 await wait(3000)
113 await checkNewPeerTubeVersion(baseParams, '15.4.3', 'presence') 104 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' })
114 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2) 105 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
115 }) 106 })
116 }) 107 })
@@ -121,17 +112,17 @@ describe('Test admin notifications', function () {
121 this.timeout(30000) 112 this.timeout(30000)
122 113
123 await wait(6000) 114 await wait(6000)
124 await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'absence') 115 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' })
125 }) 116 })
126 117
127 it('Should send a notification to admins on new plugin version', async function () { 118 it('Should send a notification to admins on new plugin version', async function () {
128 this.timeout(30000) 119 this.timeout(30000)
129 120
130 await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') 121 await server.sql.setPluginVersion('hello-world', '0.0.1')
131 await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1') 122 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
132 await wait(6000) 123 await wait(6000)
133 124
134 await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'presence') 125 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' })
135 }) 126 })
136 127
137 it('Should not send the same notification to admins', async function () { 128 it('Should not send the same notification to admins', async function () {
@@ -149,8 +140,8 @@ describe('Test admin notifications', function () {
149 it('Should send a new notification after a new plugin release', async function () { 140 it('Should send a new notification after a new plugin release', async function () {
150 this.timeout(30000) 141 this.timeout(30000)
151 142
152 await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') 143 await server.sql.setPluginVersion('hello-world', '0.0.1')
153 await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1') 144 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
154 await wait(6000) 145 await wait(6000)
155 146
156 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2) 147 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts
index d2badf237..7cbb21397 100644
--- a/server/tests/api/notifications/comments-notifications.ts
+++ b/server/tests/api/notifications/comments-notifications.ts
@@ -3,30 +3,22 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addAccountToAccountBlocklist,
7 addVideoCommentReply,
8 addVideoCommentThread,
9 checkCommentMention, 6 checkCommentMention,
10 CheckerBaseParams, 7 CheckerBaseParams,
11 checkNewCommentOnMyVideo, 8 checkNewCommentOnMyVideo,
12 cleanupTests, 9 cleanupTests,
13 getVideoCommentThreads,
14 getVideoThreadComments,
15 MockSmtpServer, 10 MockSmtpServer,
11 PeerTubeServer,
16 prepareNotificationsTest, 12 prepareNotificationsTest,
17 removeAccountFromAccountBlocklist,
18 ServerInfo,
19 updateMyUser,
20 uploadVideo,
21 waitJobs 13 waitJobs
22} from '@shared/extra-utils' 14} from '@shared/extra-utils'
23import { UserNotification, VideoCommentThreadTree } from '@shared/models' 15import { UserNotification } from '@shared/models'
24 16
25const expect = chai.expect 17const expect = chai.expect
26 18
27describe('Test comments notifications', function () { 19describe('Test comments notifications', function () {
28 let servers: ServerInfo[] = [] 20 let servers: PeerTubeServer[] = []
29 let userAccessToken: string 21 let userToken: string
30 let userNotifications: UserNotification[] = [] 22 let userNotifications: UserNotification[] = []
31 let emails: object[] = [] 23 let emails: object[] = []
32 24
@@ -40,7 +32,7 @@ describe('Test comments notifications', function () {
40 32
41 const res = await prepareNotificationsTest(2) 33 const res = await prepareNotificationsTest(2)
42 emails = res.emails 34 emails = res.emails
43 userAccessToken = res.userAccessToken 35 userToken = res.userAccessToken
44 servers = res.servers 36 servers = res.servers
45 userNotifications = res.userNotifications 37 userNotifications = res.userNotifications
46 }) 38 })
@@ -53,136 +45,125 @@ describe('Test comments notifications', function () {
53 server: servers[0], 45 server: servers[0],
54 emails, 46 emails,
55 socketNotifications: userNotifications, 47 socketNotifications: userNotifications,
56 token: userAccessToken 48 token: userToken
57 } 49 }
58 }) 50 })
59 51
60 it('Should not send a new comment notification after a comment on another video', async function () { 52 it('Should not send a new comment notification after a comment on another video', async function () {
61 this.timeout(20000) 53 this.timeout(20000)
62 54
63 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 55 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
64 const uuid = resVideo.body.video.uuid
65 56
66 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') 57 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
67 const commentId = resComment.body.comment.id 58 const commentId = created.id
68 59
69 await waitJobs(servers) 60 await waitJobs(servers)
70 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') 61 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
71 }) 62 })
72 63
73 it('Should not send a new comment notification if I comment my own video', async function () { 64 it('Should not send a new comment notification if I comment my own video', async function () {
74 this.timeout(20000) 65 this.timeout(20000)
75 66
76 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) 67 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
77 const uuid = resVideo.body.video.uuid
78 68
79 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment') 69 const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' })
80 const commentId = resComment.body.comment.id 70 const commentId = created.id
81 71
82 await waitJobs(servers) 72 await waitJobs(servers)
83 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') 73 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
84 }) 74 })
85 75
86 it('Should not send a new comment notification if the account is muted', async function () { 76 it('Should not send a new comment notification if the account is muted', async function () {
87 this.timeout(20000) 77 this.timeout(20000)
88 78
89 await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root') 79 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
90 80
91 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) 81 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
92 const uuid = resVideo.body.video.uuid
93 82
94 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') 83 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
95 const commentId = resComment.body.comment.id 84 const commentId = created.id
96 85
97 await waitJobs(servers) 86 await waitJobs(servers)
98 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') 87 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
99 88
100 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') 89 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
101 }) 90 })
102 91
103 it('Should send a new comment notification after a local comment on my video', async function () { 92 it('Should send a new comment notification after a local comment on my video', async function () {
104 this.timeout(20000) 93 this.timeout(20000)
105 94
106 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) 95 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
107 const uuid = resVideo.body.video.uuid
108 96
109 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') 97 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
110 const commentId = resComment.body.comment.id 98 const commentId = created.id
111 99
112 await waitJobs(servers) 100 await waitJobs(servers)
113 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') 101 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
114 }) 102 })
115 103
116 it('Should send a new comment notification after a remote comment on my video', async function () { 104 it('Should send a new comment notification after a remote comment on my video', async function () {
117 this.timeout(20000) 105 this.timeout(20000)
118 106
119 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) 107 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
120 const uuid = resVideo.body.video.uuid
121 108
122 await waitJobs(servers) 109 await waitJobs(servers)
123 110
124 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') 111 await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
125 112
126 await waitJobs(servers) 113 await waitJobs(servers)
127 114
128 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) 115 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
129 expect(resComment.body.data).to.have.lengthOf(1) 116 expect(data).to.have.lengthOf(1)
130 const commentId = resComment.body.data[0].id
131 117
132 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') 118 const commentId = data[0].id
119 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
133 }) 120 })
134 121
135 it('Should send a new comment notification after a local reply on my video', async function () { 122 it('Should send a new comment notification after a local reply on my video', async function () {
136 this.timeout(20000) 123 this.timeout(20000)
137 124
138 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) 125 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
139 const uuid = resVideo.body.video.uuid
140 126
141 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') 127 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
142 const threadId = resThread.body.comment.id
143 128
144 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply') 129 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
145 const commentId = resComment.body.comment.id
146 130
147 await waitJobs(servers) 131 await waitJobs(servers)
148 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') 132 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
149 }) 133 })
150 134
151 it('Should send a new comment notification after a remote reply on my video', async function () { 135 it('Should send a new comment notification after a remote reply on my video', async function () {
152 this.timeout(20000) 136 this.timeout(20000)
153 137
154 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) 138 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
155 const uuid = resVideo.body.video.uuid
156 await waitJobs(servers) 139 await waitJobs(servers)
157 140
158 { 141 {
159 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') 142 const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
160 const threadId = resThread.body.comment.id 143 const threadId = created.id
161 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply') 144 await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
162 } 145 }
163 146
164 await waitJobs(servers) 147 await waitJobs(servers)
165 148
166 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) 149 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
167 expect(resThread.body.data).to.have.lengthOf(1) 150 expect(data).to.have.lengthOf(1)
168 const threadId = resThread.body.data[0].id
169 151
170 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId) 152 const threadId = data[0].id
171 const tree = resComments.body as VideoCommentThreadTree 153 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
172 154
173 expect(tree.children).to.have.lengthOf(1) 155 expect(tree.children).to.have.lengthOf(1)
174 const commentId = tree.children[0].comment.id 156 const commentId = tree.children[0].comment.id
175 157
176 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') 158 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
177 }) 159 })
178 160
179 it('Should convert markdown in comment to html', async function () { 161 it('Should convert markdown in comment to html', async function () {
180 this.timeout(20000) 162 this.timeout(20000)
181 163
182 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'cool video' }) 164 const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } })
183 const uuid = resVideo.body.video.uuid
184 165
185 await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, commentText) 166 await servers[0].comments.createThread({ videoId: uuid, text: commentText })
186 167
187 await waitJobs(servers) 168 await waitJobs(servers)
188 169
@@ -193,147 +174,127 @@ describe('Test comments notifications', function () {
193 174
194 describe('Mention notifications', function () { 175 describe('Mention notifications', function () {
195 let baseParams: CheckerBaseParams 176 let baseParams: CheckerBaseParams
177 const byAccountDisplayName = 'super root name'
196 178
197 before(async () => { 179 before(async () => {
198 baseParams = { 180 baseParams = {
199 server: servers[0], 181 server: servers[0],
200 emails, 182 emails,
201 socketNotifications: userNotifications, 183 socketNotifications: userNotifications,
202 token: userAccessToken 184 token: userToken
203 } 185 }
204 186
205 await updateMyUser({ 187 await servers[0].users.updateMe({ displayName: 'super root name' })
206 url: servers[0].url, 188 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
207 accessToken: servers[0].accessToken,
208 displayName: 'super root name'
209 })
210
211 await updateMyUser({
212 url: servers[1].url,
213 accessToken: servers[1].accessToken,
214 displayName: 'super root 2 name'
215 })
216 }) 189 })
217 190
218 it('Should not send a new mention comment notification if I mention the video owner', async function () { 191 it('Should not send a new mention comment notification if I mention the video owner', async function () {
219 this.timeout(10000) 192 this.timeout(10000)
220 193
221 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) 194 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
222 const uuid = resVideo.body.video.uuid
223 195
224 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') 196 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
225 const commentId = resComment.body.comment.id
226 197
227 await waitJobs(servers) 198 await waitJobs(servers)
228 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') 199 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
229 }) 200 })
230 201
231 it('Should not send a new mention comment notification if I mention myself', async function () { 202 it('Should not send a new mention comment notification if I mention myself', async function () {
232 this.timeout(10000) 203 this.timeout(10000)
233 204
234 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 205 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
235 const uuid = resVideo.body.video.uuid
236 206
237 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello') 207 const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
238 const commentId = resComment.body.comment.id
239 208
240 await waitJobs(servers) 209 await waitJobs(servers)
241 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') 210 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
242 }) 211 })
243 212
244 it('Should not send a new mention notification if the account is muted', async function () { 213 it('Should not send a new mention notification if the account is muted', async function () {
245 this.timeout(10000) 214 this.timeout(10000)
246 215
247 await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root') 216 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
248 217
249 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 218 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
250 const uuid = resVideo.body.video.uuid
251 219
252 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') 220 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
253 const commentId = resComment.body.comment.id
254 221
255 await waitJobs(servers) 222 await waitJobs(servers)
256 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') 223 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
257 224
258 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') 225 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
259 }) 226 })
260 227
261 it('Should not send a new mention notification if the remote account mention a local account', async function () { 228 it('Should not send a new mention notification if the remote account mention a local account', async function () {
262 this.timeout(20000) 229 this.timeout(20000)
263 230
264 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 231 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
265 const uuid = resVideo.body.video.uuid
266 232
267 await waitJobs(servers) 233 await waitJobs(servers)
268 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello') 234 const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
269 const threadId = resThread.body.comment.id
270 235
271 await waitJobs(servers) 236 await waitJobs(servers)
272 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') 237
238 const byAccountDisplayName = 'super root 2 name'
239 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' })
273 }) 240 })
274 241
275 it('Should send a new mention notification after local comments', async function () { 242 it('Should send a new mention notification after local comments', async function () {
276 this.timeout(10000) 243 this.timeout(10000)
277 244
278 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 245 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
279 const uuid = resVideo.body.video.uuid
280 246
281 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') 247 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
282 const threadId = resThread.body.comment.id
283 248
284 await waitJobs(servers) 249 await waitJobs(servers)
285 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') 250 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' })
286 251
287 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1') 252 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
288 const commentId = resComment.body.comment.id
289 253
290 await waitJobs(servers) 254 await waitJobs(servers)
291 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') 255 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
292 }) 256 })
293 257
294 it('Should send a new mention notification after remote comments', async function () { 258 it('Should send a new mention notification after remote comments', async function () {
295 this.timeout(20000) 259 this.timeout(20000)
296 260
297 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 261 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
298 const uuid = resVideo.body.video.uuid
299 262
300 await waitJobs(servers) 263 await waitJobs(servers)
301 264
302 const text1 = `hello @user_1@localhost:${servers[0].port} 1` 265 const text1 = `hello @user_1@localhost:${servers[0].port} 1`
303 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1) 266 const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 })
304 const server2ThreadId = resThread.body.comment.id
305 267
306 await waitJobs(servers) 268 await waitJobs(servers)
307 269
308 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) 270 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
309 expect(resThread2.body.data).to.have.lengthOf(1) 271 expect(data).to.have.lengthOf(1)
310 const server1ThreadId = resThread2.body.data[0].id 272
311 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') 273 const byAccountDisplayName = 'super root 2 name'
274 const threadId = data[0].id
275 await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' })
312 276
313 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` 277 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
314 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2) 278 await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
315 279
316 await waitJobs(servers) 280 await waitJobs(servers)
317 281
318 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId) 282 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
319 const tree = resComments.body as VideoCommentThreadTree
320 283
321 expect(tree.children).to.have.lengthOf(1) 284 expect(tree.children).to.have.lengthOf(1)
322 const commentId = tree.children[0].comment.id 285 const commentId = tree.children[0].comment.id
323 286
324 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence') 287 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
325 }) 288 })
326 289
327 it('Should convert markdown in comment to html', async function () { 290 it('Should convert markdown in comment to html', async function () {
328 this.timeout(10000) 291 this.timeout(10000)
329 292
330 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) 293 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
331 const uuid = resVideo.body.video.uuid
332 294
333 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') 295 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' })
334 const threadId = resThread.body.comment.id
335 296
336 await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, '@user_1 ' + commentText) 297 await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
337 298
338 await waitJobs(servers) 299 await waitJobs(servers)
339 300
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index 3425480ae..eb3c29fe7 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -2,33 +2,6 @@
2 2
3import 'mocha' 3import 'mocha'
4import { buildUUID } from '@server/helpers/uuid' 4import { buildUUID } from '@server/helpers/uuid'
5import { AbuseState } from '@shared/models'
6import {
7 addAbuseMessage,
8 addVideoCommentThread,
9 addVideoToBlacklist,
10 cleanupTests,
11 createUser,
12 follow,
13 generateUserAccessToken,
14 getAccount,
15 getCustomConfig,
16 getVideoCommentThreads,
17 getVideoIdFromUUID,
18 immutableAssign,
19 MockInstancesIndex,
20 registerUser,
21 removeVideoFromBlacklist,
22 reportAbuse,
23 unfollow,
24 updateAbuse,
25 updateCustomConfig,
26 updateCustomSubConfig,
27 wait
28} from '../../../../shared/extra-utils'
29import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
30import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
31import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
32import { 5import {
33 checkAbuseStateChange, 6 checkAbuseStateChange,
34 checkAutoInstanceFollowing, 7 checkAutoInstanceFollowing,
@@ -43,15 +16,18 @@ import {
43 checkUserRegistered, 16 checkUserRegistered,
44 checkVideoAutoBlacklistForModerators, 17 checkVideoAutoBlacklistForModerators,
45 checkVideoIsPublished, 18 checkVideoIsPublished,
46 prepareNotificationsTest 19 cleanupTests,
47} from '../../../../shared/extra-utils/users/user-notifications' 20 MockInstancesIndex,
48import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' 21 MockSmtpServer,
49import { CustomConfig } from '../../../../shared/models/server' 22 PeerTubeServer,
50import { UserNotification } from '../../../../shared/models/users' 23 prepareNotificationsTest,
51import { VideoPrivacy } from '../../../../shared/models/videos' 24 wait,
25 waitJobs
26} from '@shared/extra-utils'
27import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models'
52 28
53describe('Test moderation notifications', function () { 29describe('Test moderation notifications', function () {
54 let servers: ServerInfo[] = [] 30 let servers: PeerTubeServer[] = []
55 let userAccessToken: string 31 let userAccessToken: string
56 let userNotifications: UserNotification[] = [] 32 let userNotifications: UserNotification[] = []
57 let adminNotifications: UserNotification[] = [] 33 let adminNotifications: UserNotification[] = []
@@ -86,93 +62,97 @@ describe('Test moderation notifications', function () {
86 this.timeout(20000) 62 this.timeout(20000)
87 63
88 const name = 'video for abuse ' + buildUUID() 64 const name = 'video for abuse ' + buildUUID()
89 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 65 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
90 const video = resVideo.body.video
91 66
92 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video.id, reason: 'super reason' }) 67 await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' })
93 68
94 await waitJobs(servers) 69 await waitJobs(servers)
95 await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') 70 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
96 }) 71 })
97 72
98 it('Should send a notification to moderators on remote video abuse', async function () { 73 it('Should send a notification to moderators on remote video abuse', async function () {
99 this.timeout(20000) 74 this.timeout(20000)
100 75
101 const name = 'video for abuse ' + buildUUID() 76 const name = 'video for abuse ' + buildUUID()
102 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 77 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
103 const video = resVideo.body.video
104 78
105 await waitJobs(servers) 79 await waitJobs(servers)
106 80
107 const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) 81 const videoId = await servers[1].videos.getId({ uuid: video.uuid })
108 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'super reason' }) 82 await servers[1].abuses.report({ videoId, reason: 'super reason' })
109 83
110 await waitJobs(servers) 84 await waitJobs(servers)
111 await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') 85 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
112 }) 86 })
113 87
114 it('Should send a notification to moderators on local comment abuse', async function () { 88 it('Should send a notification to moderators on local comment abuse', async function () {
115 this.timeout(20000) 89 this.timeout(20000)
116 90
117 const name = 'video for abuse ' + buildUUID() 91 const name = 'video for abuse ' + buildUUID()
118 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 92 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
119 const video = resVideo.body.video 93 const comment = await servers[0].comments.createThread({
120 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID()) 94 token: userAccessToken,
121 const comment = resComment.body.comment 95 videoId: video.id,
96 text: 'comment abuse ' + buildUUID()
97 })
122 98
123 await waitJobs(servers) 99 await waitJobs(servers)
124 100
125 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason: 'super reason' }) 101 await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' })
126 102
127 await waitJobs(servers) 103 await waitJobs(servers)
128 await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') 104 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
129 }) 105 })
130 106
131 it('Should send a notification to moderators on remote comment abuse', async function () { 107 it('Should send a notification to moderators on remote comment abuse', async function () {
132 this.timeout(20000) 108 this.timeout(20000)
133 109
134 const name = 'video for abuse ' + buildUUID() 110 const name = 'video for abuse ' + buildUUID()
135 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 111 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
136 const video = resVideo.body.video 112
137 await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID()) 113 await servers[0].comments.createThread({
114 token: userAccessToken,
115 videoId: video.id,
116 text: 'comment abuse ' + buildUUID()
117 })
138 118
139 await waitJobs(servers) 119 await waitJobs(servers)
140 120
141 const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5) 121 const { data } = await servers[1].comments.listThreads({ videoId: video.uuid })
142 const commentId = resComments.body.data[0].id 122 const commentId = data[0].id
143 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, commentId, reason: 'super reason' }) 123 await servers[1].abuses.report({ commentId, reason: 'super reason' })
144 124
145 await waitJobs(servers) 125 await waitJobs(servers)
146 await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') 126 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
147 }) 127 })
148 128
149 it('Should send a notification to moderators on local account abuse', async function () { 129 it('Should send a notification to moderators on local account abuse', async function () {
150 this.timeout(20000) 130 this.timeout(20000)
151 131
152 const username = 'user' + new Date().getTime() 132 const username = 'user' + new Date().getTime()
153 const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) 133 const { account } = await servers[0].users.create({ username, password: 'donald' })
154 const accountId = resUser.body.user.account.id 134 const accountId = account.id
155 135
156 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId, reason: 'super reason' }) 136 await servers[0].abuses.report({ accountId, reason: 'super reason' })
157 137
158 await waitJobs(servers) 138 await waitJobs(servers)
159 await checkNewAccountAbuseForModerators(baseParams, username, 'presence') 139 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
160 }) 140 })
161 141
162 it('Should send a notification to moderators on remote account abuse', async function () { 142 it('Should send a notification to moderators on remote account abuse', async function () {
163 this.timeout(20000) 143 this.timeout(20000)
164 144
165 const username = 'user' + new Date().getTime() 145 const username = 'user' + new Date().getTime()
166 const tmpToken = await generateUserAccessToken(servers[0], username) 146 const tmpToken = await servers[0].users.generateUserAndToken(username)
167 await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) 147 await servers[0].videos.upload({ token: tmpToken, attributes: { name: 'super video' } })
168 148
169 await waitJobs(servers) 149 await waitJobs(servers)
170 150
171 const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) 151 const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host })
172 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, accountId: resAccount.body.id, reason: 'super reason' }) 152 await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' })
173 153
174 await waitJobs(servers) 154 await waitJobs(servers)
175 await checkNewAccountAbuseForModerators(baseParams, username, 'presence') 155 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
176 }) 156 })
177 }) 157 })
178 158
@@ -189,29 +169,28 @@ describe('Test moderation notifications', function () {
189 } 169 }
190 170
191 const name = 'abuse ' + buildUUID() 171 const name = 'abuse ' + buildUUID()
192 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 172 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
193 const video = resVideo.body.video
194 173
195 const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) 174 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
196 abuseId = res.body.abuse.id 175 abuseId = body.abuse.id
197 }) 176 })
198 177
199 it('Should send a notification to reporter if the abuse has been accepted', async function () { 178 it('Should send a notification to reporter if the abuse has been accepted', async function () {
200 this.timeout(10000) 179 this.timeout(10000)
201 180
202 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.ACCEPTED }) 181 await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
203 await waitJobs(servers) 182 await waitJobs(servers)
204 183
205 await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') 184 await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.ACCEPTED, checkType: 'presence' })
206 }) 185 })
207 186
208 it('Should send a notification to reporter if the abuse has been rejected', async function () { 187 it('Should send a notification to reporter if the abuse has been rejected', async function () {
209 this.timeout(10000) 188 this.timeout(10000)
210 189
211 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.REJECTED }) 190 await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } })
212 await waitJobs(servers) 191 await waitJobs(servers)
213 192
214 await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') 193 await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.REJECTED, checkType: 'presence' })
215 }) 194 })
216 }) 195 })
217 196
@@ -237,17 +216,16 @@ describe('Test moderation notifications', function () {
237 } 216 }
238 217
239 const name = 'abuse ' + buildUUID() 218 const name = 'abuse ' + buildUUID()
240 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 219 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
241 const video = resVideo.body.video
242 220
243 { 221 {
244 const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) 222 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
245 abuseId = res.body.abuse.id 223 abuseId = body.abuse.id
246 } 224 }
247 225
248 { 226 {
249 const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) 227 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' })
250 abuseId2 = res.body.abuse.id 228 abuseId2 = body.abuse.id
251 } 229 }
252 }) 230 })
253 231
@@ -255,40 +233,43 @@ describe('Test moderation notifications', function () {
255 this.timeout(10000) 233 this.timeout(10000)
256 234
257 const message = 'my super message to users' 235 const message = 'my super message to users'
258 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) 236 await servers[0].abuses.addMessage({ abuseId, message })
259 await waitJobs(servers) 237 await waitJobs(servers)
260 238
261 await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') 239 await checkNewAbuseMessage({ ...baseParamsUser, abuseId, message, toEmail: 'user_1@example.com', checkType: 'presence' })
262 }) 240 })
263 241
264 it('Should not send a notification to the admin if sent by the admin', async function () { 242 it('Should not send a notification to the admin if sent by the admin', async function () {
265 this.timeout(10000) 243 this.timeout(10000)
266 244
267 const message = 'my super message that should not be sent to the admin' 245 const message = 'my super message that should not be sent to the admin'
268 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) 246 await servers[0].abuses.addMessage({ abuseId, message })
269 await waitJobs(servers) 247 await waitJobs(servers)
270 248
271 await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') 249 const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com'
250 await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId, message, toEmail, checkType: 'absence' })
272 }) 251 })
273 252
274 it('Should send a notification to moderators', async function () { 253 it('Should send a notification to moderators', async function () {
275 this.timeout(10000) 254 this.timeout(10000)
276 255
277 const message = 'my super message to moderators' 256 const message = 'my super message to moderators'
278 await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) 257 await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message })
279 await waitJobs(servers) 258 await waitJobs(servers)
280 259
281 await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') 260 const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com'
261 await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId: abuseId2, message, toEmail, checkType: 'presence' })
282 }) 262 })
283 263
284 it('Should not send a notification to reporter if sent by the reporter', async function () { 264 it('Should not send a notification to reporter if sent by the reporter', async function () {
285 this.timeout(10000) 265 this.timeout(10000)
286 266
287 const message = 'my super message that should not be sent to reporter' 267 const message = 'my super message that should not be sent to reporter'
288 await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) 268 await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message })
289 await waitJobs(servers) 269 await waitJobs(servers)
290 270
291 await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') 271 const toEmail = 'user_1@example.com'
272 await checkNewAbuseMessage({ ...baseParamsUser, abuseId: abuseId2, message, toEmail, checkType: 'absence' })
292 }) 273 })
293 }) 274 })
294 275
@@ -308,30 +289,28 @@ describe('Test moderation notifications', function () {
308 this.timeout(10000) 289 this.timeout(10000)
309 290
310 const name = 'video for abuse ' + buildUUID() 291 const name = 'video for abuse ' + buildUUID()
311 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 292 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
312 const uuid = resVideo.body.video.uuid
313 293
314 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) 294 await servers[0].blacklist.add({ videoId: uuid })
315 295
316 await waitJobs(servers) 296 await waitJobs(servers)
317 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') 297 await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'blacklist' })
318 }) 298 })
319 299
320 it('Should send a notification to video owner on unblacklist', async function () { 300 it('Should send a notification to video owner on unblacklist', async function () {
321 this.timeout(10000) 301 this.timeout(10000)
322 302
323 const name = 'video for abuse ' + buildUUID() 303 const name = 'video for abuse ' + buildUUID()
324 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 304 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
325 const uuid = resVideo.body.video.uuid
326 305
327 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) 306 await servers[0].blacklist.add({ videoId: uuid })
328 307
329 await waitJobs(servers) 308 await waitJobs(servers)
330 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) 309 await servers[0].blacklist.remove({ videoId: uuid })
331 await waitJobs(servers) 310 await waitJobs(servers)
332 311
333 await wait(500) 312 await wait(500)
334 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') 313 await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' })
335 }) 314 })
336 }) 315 })
337 316
@@ -350,14 +329,14 @@ describe('Test moderation notifications', function () {
350 it('Should send a notification only to moderators when a user registers on the instance', async function () { 329 it('Should send a notification only to moderators when a user registers on the instance', async function () {
351 this.timeout(10000) 330 this.timeout(10000)
352 331
353 await registerUser(servers[0].url, 'user_45', 'password') 332 await servers[0].users.register({ username: 'user_45' })
354 333
355 await waitJobs(servers) 334 await waitJobs(servers)
356 335
357 await checkUserRegistered(baseParams, 'user_45', 'presence') 336 await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' })
358 337
359 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 338 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
360 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') 339 await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' })
361 }) 340 })
362 }) 341 })
363 342
@@ -392,20 +371,20 @@ describe('Test moderation notifications', function () {
392 it('Should send a notification only to admin when there is a new instance follower', async function () { 371 it('Should send a notification only to admin when there is a new instance follower', async function () {
393 this.timeout(20000) 372 this.timeout(20000)
394 373
395 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) 374 await servers[2].follows.follow({ hosts: [ servers[0].url ] })
396 375
397 await waitJobs(servers) 376 await waitJobs(servers)
398 377
399 await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') 378 await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' })
400 379
401 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 380 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
402 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') 381 await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' })
403 }) 382 })
404 383
405 it('Should send a notification on auto follow back', async function () { 384 it('Should send a notification on auto follow back', async function () {
406 this.timeout(40000) 385 this.timeout(40000)
407 386
408 await unfollow(servers[2].url, servers[2].accessToken, servers[0]) 387 await servers[2].follows.unfollow({ target: servers[0] })
409 await waitJobs(servers) 388 await waitJobs(servers)
410 389
411 const config = { 390 const config = {
@@ -415,41 +394,41 @@ describe('Test moderation notifications', function () {
415 } 394 }
416 } 395 }
417 } 396 }
418 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 397 await servers[0].config.updateCustomSubConfig({ newConfig: config })
419 398
420 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) 399 await servers[2].follows.follow({ hosts: [ servers[0].url ] })
421 400
422 await waitJobs(servers) 401 await waitJobs(servers)
423 402
424 const followerHost = servers[0].host 403 const followerHost = servers[0].host
425 const followingHost = servers[2].host 404 const followingHost = servers[2].host
426 await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') 405 await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' })
427 406
428 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 407 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
429 await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') 408 await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' })
430 409
431 config.followings.instance.autoFollowBack.enabled = false 410 config.followings.instance.autoFollowBack.enabled = false
432 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 411 await servers[0].config.updateCustomSubConfig({ newConfig: config })
433 await unfollow(servers[0].url, servers[0].accessToken, servers[2]) 412 await servers[0].follows.unfollow({ target: servers[2] })
434 await unfollow(servers[2].url, servers[2].accessToken, servers[0]) 413 await servers[2].follows.unfollow({ target: servers[0] })
435 }) 414 })
436 415
437 it('Should send a notification on auto instances index follow', async function () { 416 it('Should send a notification on auto instances index follow', async function () {
438 this.timeout(30000) 417 this.timeout(30000)
439 await unfollow(servers[0].url, servers[0].accessToken, servers[1]) 418 await servers[0].follows.unfollow({ target: servers[1] })
440 419
441 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 420 await servers[0].config.updateCustomSubConfig({ newConfig: config })
442 421
443 await wait(5000) 422 await wait(5000)
444 await waitJobs(servers) 423 await waitJobs(servers)
445 424
446 const followerHost = servers[0].host 425 const followerHost = servers[0].host
447 const followingHost = servers[1].host 426 const followingHost = servers[1].host
448 await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') 427 await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' })
449 428
450 config.followings.instance.autoFollowIndex.enabled = false 429 config.followings.instance.autoFollowIndex.enabled = false
451 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 430 await servers[0].config.updateCustomSubConfig({ newConfig: config })
452 await unfollow(servers[0].url, servers[0].accessToken, servers[1]) 431 await servers[0].follows.unfollow({ target: servers[1] })
453 }) 432 })
454 }) 433 })
455 434
@@ -457,7 +436,8 @@ describe('Test moderation notifications', function () {
457 let userBaseParams: CheckerBaseParams 436 let userBaseParams: CheckerBaseParams
458 let adminBaseParamsServer1: CheckerBaseParams 437 let adminBaseParamsServer1: CheckerBaseParams
459 let adminBaseParamsServer2: CheckerBaseParams 438 let adminBaseParamsServer2: CheckerBaseParams
460 let videoUUID: string 439 let uuid: string
440 let shortUUID: string
461 let videoName: string 441 let videoName: string
462 let currentCustomConfig: CustomConfig 442 let currentCustomConfig: CustomConfig
463 443
@@ -484,9 +464,11 @@ describe('Test moderation notifications', function () {
484 token: userAccessToken 464 token: userAccessToken
485 } 465 }
486 466
487 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) 467 currentCustomConfig = await servers[0].config.getCustomConfig()
488 currentCustomConfig = resCustomConfig.body 468
489 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { 469 const autoBlacklistTestsCustomConfig = {
470 ...currentCustomConfig,
471
490 autoBlacklist: { 472 autoBlacklist: {
491 videos: { 473 videos: {
492 ofUsers: { 474 ofUsers: {
@@ -494,43 +476,44 @@ describe('Test moderation notifications', function () {
494 } 476 }
495 } 477 }
496 } 478 }
497 }) 479 }
480
498 // enable transcoding otherwise own publish notification after transcoding not expected 481 // enable transcoding otherwise own publish notification after transcoding not expected
499 autoBlacklistTestsCustomConfig.transcoding.enabled = true 482 autoBlacklistTestsCustomConfig.transcoding.enabled = true
500 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) 483 await servers[0].config.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig })
501
502 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port)
503 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port)
504 484
485 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
486 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
505 }) 487 })
506 488
507 it('Should send notification to moderators on new video with auto-blacklist', async function () { 489 it('Should send notification to moderators on new video with auto-blacklist', async function () {
508 this.timeout(40000) 490 this.timeout(40000)
509 491
510 videoName = 'video with auto-blacklist ' + buildUUID() 492 videoName = 'video with auto-blacklist ' + buildUUID()
511 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) 493 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } })
512 videoUUID = resVideo.body.video.uuid 494 shortUUID = video.shortUUID
495 uuid = video.uuid
513 496
514 await waitJobs(servers) 497 await waitJobs(servers)
515 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') 498 await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName, checkType: 'presence' })
516 }) 499 })
517 500
518 it('Should not send video publish notification if auto-blacklisted', async function () { 501 it('Should not send video publish notification if auto-blacklisted', async function () {
519 await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') 502 await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' })
520 }) 503 })
521 504
522 it('Should not send a local user subscription notification if auto-blacklisted', async function () { 505 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
523 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') 506 await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' })
524 }) 507 })
525 508
526 it('Should not send a remote user subscription notification if auto-blacklisted', async function () { 509 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
527 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') 510 await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'absence' })
528 }) 511 })
529 512
530 it('Should send video published and unblacklist after video unblacklisted', async function () { 513 it('Should send video published and unblacklist after video unblacklisted', async function () {
531 this.timeout(40000) 514 this.timeout(40000)
532 515
533 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) 516 await servers[0].blacklist.remove({ videoId: uuid })
534 517
535 await waitJobs(servers) 518 await waitJobs(servers)
536 519
@@ -541,11 +524,11 @@ describe('Test moderation notifications', function () {
541 }) 524 })
542 525
543 it('Should send a local user subscription notification after removed from blacklist', async function () { 526 it('Should send a local user subscription notification after removed from blacklist', async function () {
544 await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') 527 await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' })
545 }) 528 })
546 529
547 it('Should send a remote user subscription notification after removed from blacklist', async function () { 530 it('Should send a remote user subscription notification after removed from blacklist', async function () {
548 await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') 531 await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' })
549 }) 532 })
550 533
551 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { 534 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
@@ -555,29 +538,28 @@ describe('Test moderation notifications', function () {
555 538
556 const name = 'video with auto-blacklist and future schedule ' + buildUUID() 539 const name = 'video with auto-blacklist and future schedule ' + buildUUID()
557 540
558 const data = { 541 const attributes = {
559 name, 542 name,
560 privacy: VideoPrivacy.PRIVATE, 543 privacy: VideoPrivacy.PRIVATE,
561 scheduleUpdate: { 544 scheduleUpdate: {
562 updateAt: updateAt.toISOString(), 545 updateAt: updateAt.toISOString(),
563 privacy: VideoPrivacy.PUBLIC 546 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
564 } 547 }
565 } 548 }
566 549
567 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) 550 const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes })
568 const uuid = resVideo.body.video.uuid
569 551
570 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) 552 await servers[0].blacklist.remove({ videoId: uuid })
571 553
572 await waitJobs(servers) 554 await waitJobs(servers)
573 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') 555 await checkNewBlacklistOnMyVideo({ ...userBaseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' })
574 556
575 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one 557 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
576 // One notification might be better anyways 558 // One notification might be better anyways
577 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') 559 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
578 560
579 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') 561 await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' })
580 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') 562 await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' })
581 }) 563 })
582 564
583 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { 565 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
@@ -588,22 +570,21 @@ describe('Test moderation notifications', function () {
588 570
589 const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() 571 const name = 'video with schedule done and still auto-blacklisted ' + buildUUID()
590 572
591 const data = { 573 const attributes = {
592 name, 574 name,
593 privacy: VideoPrivacy.PRIVATE, 575 privacy: VideoPrivacy.PRIVATE,
594 scheduleUpdate: { 576 scheduleUpdate: {
595 updateAt: updateAt.toISOString(), 577 updateAt: updateAt.toISOString(),
596 privacy: VideoPrivacy.PUBLIC 578 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
597 } 579 }
598 } 580 }
599 581
600 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) 582 const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes })
601 const uuid = resVideo.body.video.uuid
602 583
603 await wait(6000) 584 await wait(6000)
604 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') 585 await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' })
605 await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') 586 await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' })
606 await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') 587 await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' })
607 }) 588 })
608 589
609 it('Should not send a notification to moderators on new video without auto-blacklist', async function () { 590 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
@@ -612,18 +593,17 @@ describe('Test moderation notifications', function () {
612 const name = 'video without auto-blacklist ' + buildUUID() 593 const name = 'video without auto-blacklist ' + buildUUID()
613 594
614 // admin with blacklist right will not be auto-blacklisted 595 // admin with blacklist right will not be auto-blacklisted
615 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) 596 const { shortUUID } = await servers[0].videos.upload({ attributes: { name } })
616 const uuid = resVideo.body.video.uuid
617 597
618 await waitJobs(servers) 598 await waitJobs(servers)
619 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') 599 await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName: name, checkType: 'absence' })
620 }) 600 })
621 601
622 after(async () => { 602 after(async () => {
623 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) 603 await servers[0].config.updateCustomConfig({ newCustomConfig: currentCustomConfig })
624 604
625 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 605 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
626 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 606 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
627 }) 607 })
628 }) 608 })
629 609
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index b81995449..a529a9bf7 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -2,28 +2,24 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { addUserSubscription } from '@shared/extra-utils/users/user-subscriptions'
6import { cleanupTests, getMyUserInformation, immutableAssign, uploadRandomVideo, waitJobs } from '../../../../shared/extra-utils'
7import { ServerInfo } from '../../../../shared/extra-utils/index'
8import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
9import { 5import {
10 CheckerBaseParams, 6 CheckerBaseParams,
11 checkNewVideoFromSubscription, 7 checkNewVideoFromSubscription,
8 cleanupTests,
12 getAllNotificationsSettings, 9 getAllNotificationsSettings,
13 getUserNotifications, 10 MockSmtpServer,
14 markAsReadAllNotifications, 11 PeerTubeServer,
15 markAsReadNotifications,
16 prepareNotificationsTest, 12 prepareNotificationsTest,
17 updateMyNotificationSettings 13 waitJobs
18} from '../../../../shared/extra-utils/users/user-notifications' 14} from '@shared/extra-utils'
19import { User, UserNotification, UserNotificationSettingValue } from '../../../../shared/models/users' 15import { UserNotification, UserNotificationSettingValue } from '@shared/models'
20 16
21const expect = chai.expect 17const expect = chai.expect
22 18
23describe('Test notifications API', function () { 19describe('Test notifications API', function () {
24 let server: ServerInfo 20 let server: PeerTubeServer
25 let userNotifications: UserNotification[] = [] 21 let userNotifications: UserNotification[] = []
26 let userAccessToken: string 22 let userToken: string
27 let emails: object[] = [] 23 let emails: object[] = []
28 24
29 before(async function () { 25 before(async function () {
@@ -31,14 +27,14 @@ describe('Test notifications API', function () {
31 27
32 const res = await prepareNotificationsTest(1) 28 const res = await prepareNotificationsTest(1)
33 emails = res.emails 29 emails = res.emails
34 userAccessToken = res.userAccessToken 30 userToken = res.userAccessToken
35 userNotifications = res.userNotifications 31 userNotifications = res.userNotifications
36 server = res.servers[0] 32 server = res.servers[0]
37 33
38 await addUserSubscription(server.url, userAccessToken, 'root_channel@localhost:' + server.port) 34 await server.subscriptions.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
39 35
40 for (let i = 0; i < 10; i++) { 36 for (let i = 0; i < 10; i++) {
41 await uploadRandomVideo(server, false) 37 await server.videos.randomUpload({ wait: false })
42 } 38 }
43 39
44 await waitJobs([ server ]) 40 await waitJobs([ server ])
@@ -47,49 +43,46 @@ describe('Test notifications API', function () {
47 describe('Mark as read', function () { 43 describe('Mark as read', function () {
48 44
49 it('Should mark as read some notifications', async function () { 45 it('Should mark as read some notifications', async function () {
50 const res = await getUserNotifications(server.url, userAccessToken, 2, 3) 46 const { data } = await server.notifications.list({ token: userToken, start: 2, count: 3 })
51 const ids = res.body.data.map(n => n.id) 47 const ids = data.map(n => n.id)
52 48
53 await markAsReadNotifications(server.url, userAccessToken, ids) 49 await server.notifications.markAsRead({ token: userToken, ids })
54 }) 50 })
55 51
56 it('Should have the notifications marked as read', async function () { 52 it('Should have the notifications marked as read', async function () {
57 const res = await getUserNotifications(server.url, userAccessToken, 0, 10) 53 const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10 })
58 54
59 const notifications = res.body.data as UserNotification[] 55 expect(data[0].read).to.be.false
60 expect(notifications[0].read).to.be.false 56 expect(data[1].read).to.be.false
61 expect(notifications[1].read).to.be.false 57 expect(data[2].read).to.be.true
62 expect(notifications[2].read).to.be.true 58 expect(data[3].read).to.be.true
63 expect(notifications[3].read).to.be.true 59 expect(data[4].read).to.be.true
64 expect(notifications[4].read).to.be.true 60 expect(data[5].read).to.be.false
65 expect(notifications[5].read).to.be.false
66 }) 61 })
67 62
68 it('Should only list read notifications', async function () { 63 it('Should only list read notifications', async function () {
69 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, false) 64 const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: false })
70 65
71 const notifications = res.body.data as UserNotification[] 66 for (const notification of data) {
72 for (const notification of notifications) {
73 expect(notification.read).to.be.true 67 expect(notification.read).to.be.true
74 } 68 }
75 }) 69 })
76 70
77 it('Should only list unread notifications', async function () { 71 it('Should only list unread notifications', async function () {
78 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) 72 const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true })
79 73
80 const notifications = res.body.data as UserNotification[] 74 for (const notification of data) {
81 for (const notification of notifications) {
82 expect(notification.read).to.be.false 75 expect(notification.read).to.be.false
83 } 76 }
84 }) 77 })
85 78
86 it('Should mark as read all notifications', async function () { 79 it('Should mark as read all notifications', async function () {
87 await markAsReadAllNotifications(server.url, userAccessToken) 80 await server.notifications.markAsReadAll({ token: userToken })
88 81
89 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) 82 const body = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true })
90 83
91 expect(res.body.total).to.equal(0) 84 expect(body.total).to.equal(0)
92 expect(res.body.data).to.have.lengthOf(0) 85 expect(body.data).to.have.lengthOf(0)
93 }) 86 })
94 }) 87 })
95 88
@@ -101,99 +94,102 @@ describe('Test notifications API', function () {
101 server: server, 94 server: server,
102 emails, 95 emails,
103 socketNotifications: userNotifications, 96 socketNotifications: userNotifications,
104 token: userAccessToken 97 token: userToken
105 } 98 }
106 }) 99 })
107 100
108 it('Should not have notifications', async function () { 101 it('Should not have notifications', async function () {
109 this.timeout(20000) 102 this.timeout(20000)
110 103
111 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 104 await server.notifications.updateMySettings({
112 newVideoFromSubscription: UserNotificationSettingValue.NONE 105 token: userToken,
113 })) 106 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE }
107 })
114 108
115 { 109 {
116 const res = await getMyUserInformation(server.url, userAccessToken) 110 const info = await server.users.getMyInfo({ token: userToken })
117 const info = res.body as User
118 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) 111 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
119 } 112 }
120 113
121 const { name, uuid } = await uploadRandomVideo(server) 114 const { name, shortUUID } = await server.videos.randomUpload()
122 115
123 const check = { web: true, mail: true } 116 const check = { web: true, mail: true }
124 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') 117 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
125 }) 118 })
126 119
127 it('Should only have web notifications', async function () { 120 it('Should only have web notifications', async function () {
128 this.timeout(20000) 121 this.timeout(20000)
129 122
130 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 123 await server.notifications.updateMySettings({
131 newVideoFromSubscription: UserNotificationSettingValue.WEB 124 token: userToken,
132 })) 125 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB }
126 })
133 127
134 { 128 {
135 const res = await getMyUserInformation(server.url, userAccessToken) 129 const info = await server.users.getMyInfo({ token: userToken })
136 const info = res.body as User
137 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) 130 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
138 } 131 }
139 132
140 const { name, uuid } = await uploadRandomVideo(server) 133 const { name, shortUUID } = await server.videos.randomUpload()
141 134
142 { 135 {
143 const check = { mail: true, web: false } 136 const check = { mail: true, web: false }
144 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') 137 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
145 } 138 }
146 139
147 { 140 {
148 const check = { mail: false, web: true } 141 const check = { mail: false, web: true }
149 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') 142 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' })
150 } 143 }
151 }) 144 })
152 145
153 it('Should only have mail notifications', async function () { 146 it('Should only have mail notifications', async function () {
154 this.timeout(20000) 147 this.timeout(20000)
155 148
156 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 149 await server.notifications.updateMySettings({
157 newVideoFromSubscription: UserNotificationSettingValue.EMAIL 150 token: userToken,
158 })) 151 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL }
152 })
159 153
160 { 154 {
161 const res = await getMyUserInformation(server.url, userAccessToken) 155 const info = await server.users.getMyInfo({ token: userToken })
162 const info = res.body as User
163 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) 156 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
164 } 157 }
165 158
166 const { name, uuid } = await uploadRandomVideo(server) 159 const { name, shortUUID } = await server.videos.randomUpload()
167 160
168 { 161 {
169 const check = { mail: false, web: true } 162 const check = { mail: false, web: true }
170 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') 163 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
171 } 164 }
172 165
173 { 166 {
174 const check = { mail: true, web: false } 167 const check = { mail: true, web: false }
175 await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') 168 await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' })
176 } 169 }
177 }) 170 })
178 171
179 it('Should have email and web notifications', async function () { 172 it('Should have email and web notifications', async function () {
180 this.timeout(20000) 173 this.timeout(20000)
181 174
182 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 175 await server.notifications.updateMySettings({
183 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 176 token: userToken,
184 })) 177 settings: {
178 ...getAllNotificationsSettings(),
179 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
180 }
181 })
185 182
186 { 183 {
187 const res = await getMyUserInformation(server.url, userAccessToken) 184 const info = await server.users.getMyInfo({ token: userToken })
188 const info = res.body as User
189 expect(info.notificationSettings.newVideoFromSubscription).to.equal( 185 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
190 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 186 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
191 ) 187 )
192 } 188 }
193 189
194 const { name, uuid } = await uploadRandomVideo(server) 190 const { name, shortUUID } = await server.videos.randomUpload()
195 191
196 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 192 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
197 }) 193 })
198 }) 194 })
199 195
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index e981c1718..e53ab2aa5 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -4,34 +4,26 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { buildUUID } from '@server/helpers/uuid' 5import { buildUUID } from '@server/helpers/uuid'
6import { 6import {
7 cleanupTests,
8 updateMyUser,
9 updateVideo,
10 updateVideoChannel,
11 uploadRandomVideoOnServers,
12 wait
13} from '../../../../shared/extra-utils'
14import { ServerInfo } from '../../../../shared/extra-utils/index'
15import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
16import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
17import {
18 CheckerBaseParams, 7 CheckerBaseParams,
19 checkMyVideoImportIsFinished, 8 checkMyVideoImportIsFinished,
20 checkNewActorFollow, 9 checkNewActorFollow,
21 checkNewVideoFromSubscription, 10 checkNewVideoFromSubscription,
22 checkVideoIsPublished, 11 checkVideoIsPublished,
23 getLastNotification, 12 cleanupTests,
24 prepareNotificationsTest 13 FIXTURE_URLS,
25} from '../../../../shared/extra-utils/users/user-notifications' 14 MockSmtpServer,
26import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' 15 PeerTubeServer,
27import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' 16 prepareNotificationsTest,
28import { UserNotification, UserNotificationType } from '../../../../shared/models/users' 17 uploadRandomVideoOnServers,
29import { VideoPrivacy } from '../../../../shared/models/videos' 18 wait,
19 waitJobs
20} from '@shared/extra-utils'
21import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models'
30 22
31const expect = chai.expect 23const expect = chai.expect
32 24
33describe('Test user notifications', function () { 25describe('Test user notifications', function () {
34 let servers: ServerInfo[] = [] 26 let servers: PeerTubeServer[] = []
35 let userAccessToken: string 27 let userAccessToken: string
36 let userNotifications: UserNotification[] = [] 28 let userNotifications: UserNotification[] = []
37 let adminNotifications: UserNotification[] = [] 29 let adminNotifications: UserNotification[] = []
@@ -69,7 +61,7 @@ describe('Test user notifications', function () {
69 61
70 await uploadRandomVideoOnServers(servers, 1) 62 await uploadRandomVideoOnServers(servers, 1)
71 63
72 const notification = await getLastNotification(servers[0].url, userAccessToken) 64 const notification = await servers[0].notifications.getLastest({ token: userAccessToken })
73 expect(notification).to.be.undefined 65 expect(notification).to.be.undefined
74 66
75 expect(emails).to.have.lengthOf(0) 67 expect(emails).to.have.lengthOf(0)
@@ -79,21 +71,21 @@ describe('Test user notifications', function () {
79 it('Should send a new video notification if the user follows the local video publisher', async function () { 71 it('Should send a new video notification if the user follows the local video publisher', async function () {
80 this.timeout(15000) 72 this.timeout(15000)
81 73
82 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) 74 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
83 await waitJobs(servers) 75 await waitJobs(servers)
84 76
85 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) 77 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
86 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 78 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
87 }) 79 })
88 80
89 it('Should send a new video notification from a remote account', async function () { 81 it('Should send a new video notification from a remote account', async function () {
90 this.timeout(150000) // Server 2 has transcoding enabled 82 this.timeout(150000) // Server 2 has transcoding enabled
91 83
92 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) 84 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
93 await waitJobs(servers) 85 await waitJobs(servers)
94 86
95 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) 87 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2)
96 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 88 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
97 }) 89 })
98 90
99 it('Should send a new video notification on a scheduled publication', async function () { 91 it('Should send a new video notification on a scheduled publication', async function () {
@@ -106,13 +98,13 @@ describe('Test user notifications', function () {
106 privacy: VideoPrivacy.PRIVATE, 98 privacy: VideoPrivacy.PRIVATE,
107 scheduleUpdate: { 99 scheduleUpdate: {
108 updateAt: updateAt.toISOString(), 100 updateAt: updateAt.toISOString(),
109 privacy: VideoPrivacy.PUBLIC 101 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
110 } 102 }
111 } 103 }
112 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 104 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
113 105
114 await wait(6000) 106 await wait(6000)
115 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 107 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
116 }) 108 })
117 109
118 it('Should send a new video notification on a remote scheduled publication', async function () { 110 it('Should send a new video notification on a remote scheduled publication', async function () {
@@ -125,14 +117,14 @@ describe('Test user notifications', function () {
125 privacy: VideoPrivacy.PRIVATE, 117 privacy: VideoPrivacy.PRIVATE,
126 scheduleUpdate: { 118 scheduleUpdate: {
127 updateAt: updateAt.toISOString(), 119 updateAt: updateAt.toISOString(),
128 privacy: VideoPrivacy.PUBLIC 120 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
129 } 121 }
130 } 122 }
131 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 123 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
132 await waitJobs(servers) 124 await waitJobs(servers)
133 125
134 await wait(6000) 126 await wait(6000)
135 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 127 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
136 }) 128 })
137 129
138 it('Should not send a notification before the video is published', async function () { 130 it('Should not send a notification before the video is published', async function () {
@@ -144,64 +136,64 @@ describe('Test user notifications', function () {
144 privacy: VideoPrivacy.PRIVATE, 136 privacy: VideoPrivacy.PRIVATE,
145 scheduleUpdate: { 137 scheduleUpdate: {
146 updateAt: updateAt.toISOString(), 138 updateAt: updateAt.toISOString(),
147 privacy: VideoPrivacy.PUBLIC 139 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
148 } 140 }
149 } 141 }
150 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 142 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
151 143
152 await wait(6000) 144 await wait(6000)
153 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 145 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
154 }) 146 })
155 147
156 it('Should send a new video notification when a video becomes public', async function () { 148 it('Should send a new video notification when a video becomes public', async function () {
157 this.timeout(50000) 149 this.timeout(50000)
158 150
159 const data = { privacy: VideoPrivacy.PRIVATE } 151 const data = { privacy: VideoPrivacy.PRIVATE }
160 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 152 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
161 153
162 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 154 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
163 155
164 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) 156 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
165 157
166 await waitJobs(servers) 158 await waitJobs(servers)
167 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 159 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
168 }) 160 })
169 161
170 it('Should send a new video notification when a remote video becomes public', async function () { 162 it('Should send a new video notification when a remote video becomes public', async function () {
171 this.timeout(50000) 163 this.timeout(50000)
172 164
173 const data = { privacy: VideoPrivacy.PRIVATE } 165 const data = { privacy: VideoPrivacy.PRIVATE }
174 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 166 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
175 167
176 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 168 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
177 169
178 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) 170 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
179 171
180 await waitJobs(servers) 172 await waitJobs(servers)
181 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 173 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
182 }) 174 })
183 175
184 it('Should not send a new video notification when a video becomes unlisted', async function () { 176 it('Should not send a new video notification when a video becomes unlisted', async function () {
185 this.timeout(50000) 177 this.timeout(50000)
186 178
187 const data = { privacy: VideoPrivacy.PRIVATE } 179 const data = { privacy: VideoPrivacy.PRIVATE }
188 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) 180 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
189 181
190 await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) 182 await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
191 183
192 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 184 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
193 }) 185 })
194 186
195 it('Should not send a new video notification when a remote video becomes unlisted', async function () { 187 it('Should not send a new video notification when a remote video becomes unlisted', async function () {
196 this.timeout(50000) 188 this.timeout(50000)
197 189
198 const data = { privacy: VideoPrivacy.PRIVATE } 190 const data = { privacy: VideoPrivacy.PRIVATE }
199 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 191 const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
200 192
201 await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) 193 await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
202 194
203 await waitJobs(servers) 195 await waitJobs(servers)
204 await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') 196 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
205 }) 197 })
206 198
207 it('Should send a new video notification after a video import', async function () { 199 it('Should send a new video notification after a video import', async function () {
@@ -213,14 +205,13 @@ describe('Test user notifications', function () {
213 name, 205 name,
214 channelId, 206 channelId,
215 privacy: VideoPrivacy.PUBLIC, 207 privacy: VideoPrivacy.PUBLIC,
216 targetUrl: getGoodVideoUrl() 208 targetUrl: FIXTURE_URLS.goodVideo
217 } 209 }
218 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 210 const { video } = await servers[0].imports.importVideo({ attributes })
219 const uuid = res.body.video.uuid
220 211
221 await waitJobs(servers) 212 await waitJobs(servers)
222 213
223 await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') 214 await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
224 }) 215 })
225 }) 216 })
226 217
@@ -239,10 +230,10 @@ describe('Test user notifications', function () {
239 it('Should not send a notification if transcoding is not enabled', async function () { 230 it('Should not send a notification if transcoding is not enabled', async function () {
240 this.timeout(50000) 231 this.timeout(50000)
241 232
242 const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) 233 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
243 await waitJobs(servers) 234 await waitJobs(servers)
244 235
245 await checkVideoIsPublished(baseParams, name, uuid, 'absence') 236 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
246 }) 237 })
247 238
248 it('Should not send a notification if the wait transcoding is false', async function () { 239 it('Should not send a notification if the wait transcoding is false', async function () {
@@ -251,7 +242,7 @@ describe('Test user notifications', function () {
251 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false }) 242 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
252 await waitJobs(servers) 243 await waitJobs(servers)
253 244
254 const notification = await getLastNotification(servers[0].url, userAccessToken) 245 const notification = await servers[0].notifications.getLastest({ token: userAccessToken })
255 if (notification) { 246 if (notification) {
256 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED) 247 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
257 } 248 }
@@ -260,19 +251,19 @@ describe('Test user notifications', function () {
260 it('Should send a notification even if the video is not transcoded in other resolutions', async function () { 251 it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
261 this.timeout(50000) 252 this.timeout(50000)
262 253
263 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) 254 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
264 await waitJobs(servers) 255 await waitJobs(servers)
265 256
266 await checkVideoIsPublished(baseParams, name, uuid, 'presence') 257 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
267 }) 258 })
268 259
269 it('Should send a notification with a transcoded video', async function () { 260 it('Should send a notification with a transcoded video', async function () {
270 this.timeout(50000) 261 this.timeout(50000)
271 262
272 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true }) 263 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
273 await waitJobs(servers) 264 await waitJobs(servers)
274 265
275 await checkVideoIsPublished(baseParams, name, uuid, 'presence') 266 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
276 }) 267 })
277 268
278 it('Should send a notification when an imported video is transcoded', async function () { 269 it('Should send a notification when an imported video is transcoded', async function () {
@@ -284,14 +275,13 @@ describe('Test user notifications', function () {
284 name, 275 name,
285 channelId, 276 channelId,
286 privacy: VideoPrivacy.PUBLIC, 277 privacy: VideoPrivacy.PUBLIC,
287 targetUrl: getGoodVideoUrl(), 278 targetUrl: FIXTURE_URLS.goodVideo,
288 waitTranscoding: true 279 waitTranscoding: true
289 } 280 }
290 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) 281 const { video } = await servers[1].imports.importVideo({ attributes })
291 const uuid = res.body.video.uuid
292 282
293 await waitJobs(servers) 283 await waitJobs(servers)
294 await checkVideoIsPublished(baseParams, name, uuid, 'presence') 284 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
295 }) 285 })
296 286
297 it('Should send a notification when the scheduled update has been proceeded', async function () { 287 it('Should send a notification when the scheduled update has been proceeded', async function () {
@@ -304,13 +294,13 @@ describe('Test user notifications', function () {
304 privacy: VideoPrivacy.PRIVATE, 294 privacy: VideoPrivacy.PRIVATE,
305 scheduleUpdate: { 295 scheduleUpdate: {
306 updateAt: updateAt.toISOString(), 296 updateAt: updateAt.toISOString(),
307 privacy: VideoPrivacy.PUBLIC 297 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
308 } 298 }
309 } 299 }
310 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 300 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
311 301
312 await wait(6000) 302 await wait(6000)
313 await checkVideoIsPublished(baseParams, name, uuid, 'presence') 303 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
314 }) 304 })
315 305
316 it('Should not send a notification before the video is published', async function () { 306 it('Should not send a notification before the video is published', async function () {
@@ -322,13 +312,13 @@ describe('Test user notifications', function () {
322 privacy: VideoPrivacy.PRIVATE, 312 privacy: VideoPrivacy.PRIVATE,
323 scheduleUpdate: { 313 scheduleUpdate: {
324 updateAt: updateAt.toISOString(), 314 updateAt: updateAt.toISOString(),
325 privacy: VideoPrivacy.PUBLIC 315 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
326 } 316 }
327 } 317 }
328 const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) 318 const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
329 319
330 await wait(6000) 320 await wait(6000)
331 await checkVideoIsPublished(baseParams, name, uuid, 'absence') 321 await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
332 }) 322 })
333 }) 323 })
334 324
@@ -353,13 +343,14 @@ describe('Test user notifications', function () {
353 name, 343 name,
354 channelId, 344 channelId,
355 privacy: VideoPrivacy.PRIVATE, 345 privacy: VideoPrivacy.PRIVATE,
356 targetUrl: getBadVideoUrl() 346 targetUrl: FIXTURE_URLS.badVideo
357 } 347 }
358 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 348 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
359 const uuid = res.body.video.uuid
360 349
361 await waitJobs(servers) 350 await waitJobs(servers)
362 await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence') 351
352 const url = FIXTURE_URLS.badVideo
353 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' })
363 }) 354 })
364 355
365 it('Should send a notification when the video import succeeded', async function () { 356 it('Should send a notification when the video import succeeded', async function () {
@@ -371,13 +362,14 @@ describe('Test user notifications', function () {
371 name, 362 name,
372 channelId, 363 channelId,
373 privacy: VideoPrivacy.PRIVATE, 364 privacy: VideoPrivacy.PRIVATE,
374 targetUrl: getGoodVideoUrl() 365 targetUrl: FIXTURE_URLS.goodVideo
375 } 366 }
376 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 367 const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
377 const uuid = res.body.video.uuid
378 368
379 await waitJobs(servers) 369 await waitJobs(servers)
380 await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence') 370
371 const url = FIXTURE_URLS.goodVideo
372 await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' })
381 }) 373 })
382 }) 374 })
383 375
@@ -394,47 +386,56 @@ describe('Test user notifications', function () {
394 token: userAccessToken 386 token: userAccessToken
395 } 387 }
396 388
397 await updateMyUser({ 389 await servers[0].users.updateMe({ displayName: 'super root name' })
398 url: servers[0].url,
399 accessToken: servers[0].accessToken,
400 displayName: 'super root name'
401 })
402 390
403 await updateMyUser({ 391 await servers[0].users.updateMe({
404 url: servers[0].url, 392 token: userAccessToken,
405 accessToken: userAccessToken,
406 displayName: myUserName 393 displayName: myUserName
407 }) 394 })
408 395
409 await updateMyUser({ 396 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
410 url: servers[1].url,
411 accessToken: servers[1].accessToken,
412 displayName: 'super root 2 name'
413 })
414 397
415 await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName }) 398 await servers[0].channels.update({
399 token: userAccessToken,
400 channelName: 'user_1_channel',
401 attributes: { displayName: myChannelName }
402 })
416 }) 403 })
417 404
418 it('Should notify when a local channel is following one of our channel', async function () { 405 it('Should notify when a local channel is following one of our channel', async function () {
419 this.timeout(50000) 406 this.timeout(50000)
420 407
421 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 408 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
422 await waitJobs(servers) 409 await waitJobs(servers)
423 410
424 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') 411 await checkNewActorFollow({
412 ...baseParams,
413 followType: 'channel',
414 followerName: 'root',
415 followerDisplayName: 'super root name',
416 followingDisplayName: myChannelName,
417 checkType: 'presence'
418 })
425 419
426 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 420 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
427 }) 421 })
428 422
429 it('Should notify when a remote channel is following one of our channel', async function () { 423 it('Should notify when a remote channel is following one of our channel', async function () {
430 this.timeout(50000) 424 this.timeout(50000)
431 425
432 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 426 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
433 await waitJobs(servers) 427 await waitJobs(servers)
434 428
435 await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') 429 await checkNewActorFollow({
430 ...baseParams,
431 followType: 'channel',
432 followerName: 'root',
433 followerDisplayName: 'super root 2 name',
434 followingDisplayName: myChannelName,
435 checkType: 'presence'
436 })
436 437
437 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 438 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
438 }) 439 })
439 440
440 // PeerTube does not support accout -> account follows 441 // PeerTube does not support accout -> account follows