aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/notifications
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 14:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (patch)
tree7a166515e4d57a06eb3c08be569f106ed049988b /server/tests/api/notifications
parentd0a0fa429d4651710ed951a3c11af0219e408964 (diff)
downloadPeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.gz
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.zst
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.zip
Introduce user command
Diffstat (limited to 'server/tests/api/notifications')
-rw-r--r--server/tests/api/notifications/comments-notifications.ts14
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts11
-rw-r--r--server/tests/api/notifications/notifications-api.ts25
-rw-r--r--server/tests/api/notifications/user-notifications.ts18
4 files changed, 20 insertions, 48 deletions
diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts
index ea6055386..62569f810 100644
--- a/server/tests/api/notifications/comments-notifications.ts
+++ b/server/tests/api/notifications/comments-notifications.ts
@@ -10,7 +10,6 @@ import {
10 MockSmtpServer, 10 MockSmtpServer,
11 prepareNotificationsTest, 11 prepareNotificationsTest,
12 ServerInfo, 12 ServerInfo,
13 updateMyUser,
14 uploadVideo, 13 uploadVideo,
15 waitJobs 14 waitJobs
16} from '@shared/extra-utils' 15} from '@shared/extra-utils'
@@ -193,17 +192,8 @@ describe('Test comments notifications', function () {
193 token: userToken 192 token: userToken
194 } 193 }
195 194
196 await updateMyUser({ 195 await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
197 url: servers[0].url, 196 await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
198 accessToken: servers[0].accessToken,
199 displayName: 'super root name'
200 })
201
202 await updateMyUser({
203 url: servers[1].url,
204 accessToken: servers[1].accessToken,
205 displayName: 'super root 2 name'
206 })
207 }) 197 })
208 198
209 it('Should not send a new mention comment notification if I mention the video owner', async function () { 199 it('Should not send a new mention comment notification if I mention the video owner', async function () {
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index 99b434606..0269124c5 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -17,13 +17,10 @@ import {
17 checkVideoAutoBlacklistForModerators, 17 checkVideoAutoBlacklistForModerators,
18 checkVideoIsPublished, 18 checkVideoIsPublished,
19 cleanupTests, 19 cleanupTests,
20 createUser,
21 generateUserAccessToken,
22 getVideoIdFromUUID, 20 getVideoIdFromUUID,
23 MockInstancesIndex, 21 MockInstancesIndex,
24 MockSmtpServer, 22 MockSmtpServer,
25 prepareNotificationsTest, 23 prepareNotificationsTest,
26 registerUser,
27 ServerInfo, 24 ServerInfo,
28 uploadVideo, 25 uploadVideo,
29 wait, 26 wait,
@@ -139,8 +136,8 @@ describe('Test moderation notifications', function () {
139 this.timeout(20000) 136 this.timeout(20000)
140 137
141 const username = 'user' + new Date().getTime() 138 const username = 'user' + new Date().getTime()
142 const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) 139 const { account } = await servers[0].usersCommand.create({ username, password: 'donald' })
143 const accountId = resUser.body.user.account.id 140 const accountId = account.id
144 141
145 await servers[0].abusesCommand.report({ accountId, reason: 'super reason' }) 142 await servers[0].abusesCommand.report({ accountId, reason: 'super reason' })
146 143
@@ -152,7 +149,7 @@ describe('Test moderation notifications', function () {
152 this.timeout(20000) 149 this.timeout(20000)
153 150
154 const username = 'user' + new Date().getTime() 151 const username = 'user' + new Date().getTime()
155 const tmpToken = await generateUserAccessToken(servers[0], username) 152 const tmpToken = await servers[0].usersCommand.generateUserAndToken(username)
156 await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) 153 await uploadVideo(servers[0].url, tmpToken, { name: 'super video' })
157 154
158 await waitJobs(servers) 155 await waitJobs(servers)
@@ -339,7 +336,7 @@ describe('Test moderation notifications', function () {
339 it('Should send a notification only to moderators when a user registers on the instance', async function () { 336 it('Should send a notification only to moderators when a user registers on the instance', async function () {
340 this.timeout(10000) 337 this.timeout(10000)
341 338
342 await registerUser(servers[0].url, 'user_45', 'password') 339 await servers[0].usersCommand.register({ username: 'user_45' })
343 340
344 await waitJobs(servers) 341 await waitJobs(servers)
345 342
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index e5864f1c2..f33d8e64d 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -7,14 +7,13 @@ import {
7 checkNewVideoFromSubscription, 7 checkNewVideoFromSubscription,
8 cleanupTests, 8 cleanupTests,
9 getAllNotificationsSettings, 9 getAllNotificationsSettings,
10 getMyUserInformation,
11 MockSmtpServer, 10 MockSmtpServer,
12 prepareNotificationsTest, 11 prepareNotificationsTest,
13 ServerInfo, 12 ServerInfo,
14 uploadRandomVideo, 13 uploadRandomVideo,
15 waitJobs 14 waitJobs
16} from '@shared/extra-utils' 15} from '@shared/extra-utils'
17import { User, UserNotification, UserNotificationSettingValue } from '@shared/models' 16import { UserNotification, UserNotificationSettingValue } from '@shared/models'
18 17
19const expect = chai.expect 18const expect = chai.expect
20 19
@@ -109,15 +108,14 @@ describe('Test notifications API', function () {
109 }) 108 })
110 109
111 { 110 {
112 const res = await getMyUserInformation(server.url, userToken) 111 const info = await server.usersCommand.getMyInfo({ token: userToken })
113 const info = res.body as User
114 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) 112 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
115 } 113 }
116 114
117 const { name, uuid } = await uploadRandomVideo(server) 115 const { name, uuid } = await uploadRandomVideo(server)
118 116
119 const check = { web: true, mail: true } 117 const check = { web: true, mail: true }
120 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') 118 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
121 }) 119 })
122 120
123 it('Should only have web notifications', async function () { 121 it('Should only have web notifications', async function () {
@@ -129,8 +127,7 @@ describe('Test notifications API', function () {
129 }) 127 })
130 128
131 { 129 {
132 const res = await getMyUserInformation(server.url, userToken) 130 const info = await server.usersCommand.getMyInfo({ token: userToken })
133 const info = res.body as User
134 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) 131 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
135 } 132 }
136 133
@@ -138,12 +135,12 @@ describe('Test notifications API', function () {
138 135
139 { 136 {
140 const check = { mail: true, web: false } 137 const check = { mail: true, web: false }
141 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') 138 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
142 } 139 }
143 140
144 { 141 {
145 const check = { mail: false, web: true } 142 const check = { mail: false, web: true }
146 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') 143 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
147 } 144 }
148 }) 145 })
149 146
@@ -156,8 +153,7 @@ describe('Test notifications API', function () {
156 }) 153 })
157 154
158 { 155 {
159 const res = await getMyUserInformation(server.url, userToken) 156 const info = await server.usersCommand.getMyInfo({ token: userToken })
160 const info = res.body as User
161 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) 157 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
162 } 158 }
163 159
@@ -165,12 +161,12 @@ describe('Test notifications API', function () {
165 161
166 { 162 {
167 const check = { mail: false, web: true } 163 const check = { mail: false, web: true }
168 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') 164 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
169 } 165 }
170 166
171 { 167 {
172 const check = { mail: true, web: false } 168 const check = { mail: true, web: false }
173 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') 169 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
174 } 170 }
175 }) 171 })
176 172
@@ -186,8 +182,7 @@ describe('Test notifications API', function () {
186 }) 182 })
187 183
188 { 184 {
189 const res = await getMyUserInformation(server.url, userToken) 185 const info = await server.usersCommand.getMyInfo({ token: userToken })
190 const info = res.body as User
191 expect(info.notificationSettings.newVideoFromSubscription).to.equal( 186 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
192 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 187 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
193 ) 188 )
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 4b31edf25..465349fb9 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -14,7 +14,6 @@ import {
14 MockSmtpServer, 14 MockSmtpServer,
15 prepareNotificationsTest, 15 prepareNotificationsTest,
16 ServerInfo, 16 ServerInfo,
17 updateMyUser,
18 updateVideo, 17 updateVideo,
19 uploadRandomVideoOnServers, 18 uploadRandomVideoOnServers,
20 wait, 19 wait,
@@ -384,23 +383,14 @@ describe('Test user notifications', function () {
384 token: userAccessToken 383 token: userAccessToken
385 } 384 }
386 385
387 await updateMyUser({ 386 await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
388 url: servers[0].url,
389 accessToken: servers[0].accessToken,
390 displayName: 'super root name'
391 })
392 387
393 await updateMyUser({ 388 await servers[0].usersCommand.updateMe({
394 url: servers[0].url, 389 token: userAccessToken,
395 accessToken: userAccessToken,
396 displayName: myUserName 390 displayName: myUserName
397 }) 391 })
398 392
399 await updateMyUser({ 393 await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
400 url: servers[1].url,
401 accessToken: servers[1].accessToken,
402 displayName: 'super root 2 name'
403 })
404 394
405 await servers[0].channelsCommand.update({ 395 await servers[0].channelsCommand.update({
406 token: userAccessToken, 396 token: userAccessToken,