aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-09 16:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitdd0ebb715123dfa126a82d4e4fe3a04064ae77b8 (patch)
treee0741f35b31c66f09f7d9ad808b224ef86151bb1 /server/tests/api
parent9293139fde7091e9badcafa9b570b83cea9a10ad (diff)
downloadPeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.tar.gz
PeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.tar.zst
PeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.zip
Introduce notifications command
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/contact-form.ts2
-rw-r--r--server/tests/api/check-params/video-comments.ts2
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts47
-rw-r--r--server/tests/api/moderation/blocklist.ts28
-rw-r--r--server/tests/api/notifications/notifications-api.ts92
-rw-r--r--server/tests/api/notifications/user-notifications.ts5
-rw-r--r--server/tests/api/server/plugins.ts3
-rw-r--r--server/tests/api/videos/video-hls.ts1
-rw-r--r--server/tests/api/videos/video-nsfw.ts142
9 files changed, 154 insertions, 168 deletions
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts
index 5539266b8..4eed1661a 100644
--- a/server/tests/api/check-params/contact-form.ts
+++ b/server/tests/api/check-params/contact-form.ts
@@ -69,7 +69,7 @@ describe('Test contact form API validators', function () {
69 }) 69 })
70 70
71 it('Should accept a contact form with the correct parameters', async function () { 71 it('Should accept a contact form with the correct parameters', async function () {
72 await command.send({ ...defaultBody }) 72 await command.send(defaultBody)
73 }) 73 })
74 74
75 after(async function () { 75 after(async function () {
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index ff94645cb..0f8c81392 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -278,7 +278,7 @@ describe('Test video comments API validator', function () {
278 let commentToDelete: number 278 let commentToDelete: number
279 279
280 { 280 {
281 const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'hello' }) 281 const created = await server.commentsCommand.createThread({ videoId: video.uuid, token: userAccessToken, text: 'hello' })
282 commentToDelete = created.id 282 commentToDelete = created.id
283 } 283 }
284 284
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index a077d8739..b676a4db4 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -7,27 +7,22 @@ import {
7 createUser, 7 createUser,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getUserNotifications,
11 markAsReadAllNotifications,
12 ServerInfo, 10 ServerInfo,
13 setAccessTokensToServers, 11 setAccessTokensToServers,
14 uploadVideo, 12 uploadVideo,
15 userLogin, 13 userLogin,
16 waitJobs 14 waitJobs
17} from '@shared/extra-utils' 15} from '@shared/extra-utils'
18import { UserNotification, UserNotificationType } from '@shared/models' 16import { UserNotificationType } from '@shared/models'
19 17
20const expect = chai.expect 18const expect = chai.expect
21 19
22async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) { 20async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) {
23 const res = await getUserNotifications(url, token, 0, 10, true) 21 const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true })
24 22 expect(data).to.have.lengthOf(expected.length)
25 const notifications: UserNotification[] = res.body.data
26
27 expect(notifications).to.have.lengthOf(expected.length)
28 23
29 for (const type of expected) { 24 for (const type of expected) {
30 expect(notifications.find(n => n.type === type)).to.exist 25 expect(data.find(n => n.type === type)).to.exist
31 } 26 }
32} 27}
33 28
@@ -47,8 +42,8 @@ describe('Test blocklist', function () {
47 42
48 await waitJobs(servers) 43 await waitJobs(servers)
49 44
50 await markAsReadAllNotifications(servers[0].url, userToken1) 45 await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 })
51 await markAsReadAllNotifications(servers[0].url, userToken2) 46 await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 })
52 47
53 { 48 {
54 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) 49 const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' })
@@ -122,7 +117,7 @@ describe('Test blocklist', function () {
122 117
123 it('Should have appropriate notifications', async function () { 118 it('Should have appropriate notifications', async function () {
124 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 119 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
125 await checkNotifications(servers[0].url, userToken1, notifs) 120 await checkNotifications(servers[0], userToken1, notifs)
126 }) 121 })
127 122
128 it('Should block an account', async function () { 123 it('Should block an account', async function () {
@@ -133,13 +128,13 @@ describe('Test blocklist', function () {
133 }) 128 })
134 129
135 it('Should not have notifications from this account', async function () { 130 it('Should not have notifications from this account', async function () {
136 await checkNotifications(servers[0].url, userToken1, []) 131 await checkNotifications(servers[0], userToken1, [])
137 }) 132 })
138 133
139 it('Should have notifications of this account on user 2', async function () { 134 it('Should have notifications of this account on user 2', async function () {
140 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 135 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
141 136
142 await checkNotifications(servers[0].url, userToken2, notifs) 137 await checkNotifications(servers[0], userToken2, notifs)
143 138
144 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) 139 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
145 }) 140 })
@@ -155,7 +150,7 @@ describe('Test blocklist', function () {
155 150
156 it('Should have appropriate notifications', async function () { 151 it('Should have appropriate notifications', async function () {
157 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 152 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
158 await checkNotifications(servers[0].url, userToken1, notifs) 153 await checkNotifications(servers[0], userToken1, notifs)
159 }) 154 })
160 155
161 it('Should block an account', async function () { 156 it('Should block an account', async function () {
@@ -166,13 +161,13 @@ describe('Test blocklist', function () {
166 }) 161 })
167 162
168 it('Should not have notifications from this account', async function () { 163 it('Should not have notifications from this account', async function () {
169 await checkNotifications(servers[0].url, userToken1, []) 164 await checkNotifications(servers[0], userToken1, [])
170 }) 165 })
171 166
172 it('Should have notifications of this account on user 2', async function () { 167 it('Should have notifications of this account on user 2', async function () {
173 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 168 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
174 169
175 await checkNotifications(servers[0].url, userToken2, notifs) 170 await checkNotifications(servers[0], userToken2, notifs)
176 171
177 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) 172 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
178 }) 173 })
@@ -189,12 +184,12 @@ describe('Test blocklist', function () {
189 it('Should have appropriate notifications', async function () { 184 it('Should have appropriate notifications', async function () {
190 { 185 {
191 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 186 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
192 await checkNotifications(servers[0].url, userToken1, notifs) 187 await checkNotifications(servers[0], userToken1, notifs)
193 } 188 }
194 189
195 { 190 {
196 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 191 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
197 await checkNotifications(servers[0].url, userToken2, notifs) 192 await checkNotifications(servers[0], userToken2, notifs)
198 } 193 }
199 }) 194 })
200 195
@@ -206,8 +201,8 @@ describe('Test blocklist', function () {
206 }) 201 })
207 202
208 it('Should not have notifications from this account', async function () { 203 it('Should not have notifications from this account', async function () {
209 await checkNotifications(servers[0].url, userToken1, []) 204 await checkNotifications(servers[0], userToken1, [])
210 await checkNotifications(servers[0].url, userToken2, []) 205 await checkNotifications(servers[0], userToken2, [])
211 206
212 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) 207 await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
213 }) 208 })
@@ -224,12 +219,12 @@ describe('Test blocklist', function () {
224 it('Should have appropriate notifications', async function () { 219 it('Should have appropriate notifications', async function () {
225 { 220 {
226 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] 221 const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
227 await checkNotifications(servers[0].url, userToken1, notifs) 222 await checkNotifications(servers[0], userToken1, notifs)
228 } 223 }
229 224
230 { 225 {
231 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] 226 const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
232 await checkNotifications(servers[0].url, userToken2, notifs) 227 await checkNotifications(servers[0], userToken2, notifs)
233 } 228 }
234 }) 229 })
235 230
@@ -241,8 +236,8 @@ describe('Test blocklist', function () {
241 }) 236 })
242 237
243 it('Should not have notifications from this account', async function () { 238 it('Should not have notifications from this account', async function () {
244 await checkNotifications(servers[0].url, userToken1, []) 239 await checkNotifications(servers[0], userToken1, [])
245 await checkNotifications(servers[0].url, userToken2, []) 240 await checkNotifications(servers[0], userToken2, [])
246 }) 241 })
247 }) 242 })
248 243
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index 00cb6c65c..44e3de4e4 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -9,7 +9,6 @@ import {
9 createUser, 9 createUser,
10 doubleFollow, 10 doubleFollow,
11 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
12 getUserNotifications,
13 getVideosList, 12 getVideosList,
14 getVideosListWithToken, 13 getVideosListWithToken,
15 ServerInfo, 14 ServerInfo,
@@ -18,7 +17,7 @@ import {
18 userLogin, 17 userLogin,
19 waitJobs 18 waitJobs
20} from '@shared/extra-utils' 19} from '@shared/extra-utils'
21import { UserNotification, UserNotificationType, Video } from '@shared/models' 20import { UserNotificationType, Video } from '@shared/models'
22 21
23const expect = chai.expect 22const expect = chai.expect
24 23
@@ -59,9 +58,8 @@ async function checkCommentNotification (
59 58
60 await waitJobs([ mainServer, comment.server ]) 59 await waitJobs([ mainServer, comment.server ])
61 60
62 const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30) 61 const { data } = await mainServer.notificationsCommand.list({ start: 0, count: 30 })
63 const commentNotifications = (res.body.data as UserNotification[]) 62 const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
64 .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
65 63
66 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) 64 if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
67 else expect(commentNotifications).to.have.lengthOf(0) 65 else expect(commentNotifications).to.have.lengthOf(0)
@@ -710,12 +708,10 @@ describe('Test blocklist', function () {
710 708
711 await waitJobs(servers) 709 await waitJobs(servers)
712 710
713 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) 711 const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 })
714 const commentNotifications = (res.body.data as UserNotification[]) 712 const commentNotifications = data.filter(n => {
715 .filter(n => { 713 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
716 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && 714 })
717 n.createdAt >= now.toISOString()
718 })
719 715
720 expect(commentNotifications).to.have.lengthOf(0) 716 expect(commentNotifications).to.have.lengthOf(0)
721 } 717 }
@@ -773,12 +769,10 @@ describe('Test blocklist', function () {
773 769
774 await waitJobs(servers) 770 await waitJobs(servers)
775 771
776 const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) 772 const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 })
777 const commentNotifications = (res.body.data as UserNotification[]) 773 const commentNotifications = data.filter(n => {
778 .filter(n => { 774 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
779 return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && 775 })
780 n.createdAt >= now.toISOString()
781 })
782 776
783 expect(commentNotifications).to.have.lengthOf(1) 777 expect(commentNotifications).to.have.lengthOf(1)
784 } 778 }
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index 1ed98ae7a..447492c5f 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -8,14 +8,10 @@ import {
8 cleanupTests, 8 cleanupTests,
9 getAllNotificationsSettings, 9 getAllNotificationsSettings,
10 getMyUserInformation, 10 getMyUserInformation,
11 getUserNotifications,
12 immutableAssign, 11 immutableAssign,
13 markAsReadAllNotifications,
14 markAsReadNotifications,
15 MockSmtpServer, 12 MockSmtpServer,
16 prepareNotificationsTest, 13 prepareNotificationsTest,
17 ServerInfo, 14 ServerInfo,
18 updateMyNotificationSettings,
19 uploadRandomVideo, 15 uploadRandomVideo,
20 waitJobs 16 waitJobs
21} from '@shared/extra-utils' 17} from '@shared/extra-utils'
@@ -26,7 +22,7 @@ const expect = chai.expect
26describe('Test notifications API', function () { 22describe('Test notifications API', function () {
27 let server: ServerInfo 23 let server: ServerInfo
28 let userNotifications: UserNotification[] = [] 24 let userNotifications: UserNotification[] = []
29 let userAccessToken: string 25 let userToken: string
30 let emails: object[] = [] 26 let emails: object[] = []
31 27
32 before(async function () { 28 before(async function () {
@@ -34,11 +30,11 @@ describe('Test notifications API', function () {
34 30
35 const res = await prepareNotificationsTest(1) 31 const res = await prepareNotificationsTest(1)
36 emails = res.emails 32 emails = res.emails
37 userAccessToken = res.userAccessToken 33 userToken = res.userAccessToken
38 userNotifications = res.userNotifications 34 userNotifications = res.userNotifications
39 server = res.servers[0] 35 server = res.servers[0]
40 36
41 await server.subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + server.port }) 37 await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port })
42 38
43 for (let i = 0; i < 10; i++) { 39 for (let i = 0; i < 10; i++) {
44 await uploadRandomVideo(server, false) 40 await uploadRandomVideo(server, false)
@@ -50,49 +46,46 @@ describe('Test notifications API', function () {
50 describe('Mark as read', function () { 46 describe('Mark as read', function () {
51 47
52 it('Should mark as read some notifications', async function () { 48 it('Should mark as read some notifications', async function () {
53 const res = await getUserNotifications(server.url, userAccessToken, 2, 3) 49 const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 })
54 const ids = res.body.data.map(n => n.id) 50 const ids = data.map(n => n.id)
55 51
56 await markAsReadNotifications(server.url, userAccessToken, ids) 52 await server.notificationsCommand.markAsRead({ token: userToken, ids })
57 }) 53 })
58 54
59 it('Should have the notifications marked as read', async function () { 55 it('Should have the notifications marked as read', async function () {
60 const res = await getUserNotifications(server.url, userAccessToken, 0, 10) 56 const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 })
61 57
62 const notifications = res.body.data as UserNotification[] 58 expect(data[0].read).to.be.false
63 expect(notifications[0].read).to.be.false 59 expect(data[1].read).to.be.false
64 expect(notifications[1].read).to.be.false 60 expect(data[2].read).to.be.true
65 expect(notifications[2].read).to.be.true 61 expect(data[3].read).to.be.true
66 expect(notifications[3].read).to.be.true 62 expect(data[4].read).to.be.true
67 expect(notifications[4].read).to.be.true 63 expect(data[5].read).to.be.false
68 expect(notifications[5].read).to.be.false
69 }) 64 })
70 65
71 it('Should only list read notifications', async function () { 66 it('Should only list read notifications', async function () {
72 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, false) 67 const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false })
73 68
74 const notifications = res.body.data as UserNotification[] 69 for (const notification of data) {
75 for (const notification of notifications) {
76 expect(notification.read).to.be.true 70 expect(notification.read).to.be.true
77 } 71 }
78 }) 72 })
79 73
80 it('Should only list unread notifications', async function () { 74 it('Should only list unread notifications', async function () {
81 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) 75 const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true })
82 76
83 const notifications = res.body.data as UserNotification[] 77 for (const notification of data) {
84 for (const notification of notifications) {
85 expect(notification.read).to.be.false 78 expect(notification.read).to.be.false
86 } 79 }
87 }) 80 })
88 81
89 it('Should mark as read all notifications', async function () { 82 it('Should mark as read all notifications', async function () {
90 await markAsReadAllNotifications(server.url, userAccessToken) 83 await server.notificationsCommand.markAsReadAll({ token: userToken })
91 84
92 const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) 85 const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true })
93 86
94 expect(res.body.total).to.equal(0) 87 expect(body.total).to.equal(0)
95 expect(res.body.data).to.have.lengthOf(0) 88 expect(body.data).to.have.lengthOf(0)
96 }) 89 })
97 }) 90 })
98 91
@@ -104,19 +97,20 @@ describe('Test notifications API', function () {
104 server: server, 97 server: server,
105 emails, 98 emails,
106 socketNotifications: userNotifications, 99 socketNotifications: userNotifications,
107 token: userAccessToken 100 token: userToken
108 } 101 }
109 }) 102 })
110 103
111 it('Should not have notifications', async function () { 104 it('Should not have notifications', async function () {
112 this.timeout(20000) 105 this.timeout(20000)
113 106
114 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 107 await server.notificationsCommand.updateMySettings({
115 newVideoFromSubscription: UserNotificationSettingValue.NONE 108 token: userToken,
116 })) 109 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE }
110 })
117 111
118 { 112 {
119 const res = await getMyUserInformation(server.url, userAccessToken) 113 const res = await getMyUserInformation(server.url, userToken)
120 const info = res.body as User 114 const info = res.body as User
121 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) 115 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
122 } 116 }
@@ -130,12 +124,13 @@ describe('Test notifications API', function () {
130 it('Should only have web notifications', async function () { 124 it('Should only have web notifications', async function () {
131 this.timeout(20000) 125 this.timeout(20000)
132 126
133 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 127 await server.notificationsCommand.updateMySettings({
134 newVideoFromSubscription: UserNotificationSettingValue.WEB 128 token: userToken,
135 })) 129 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB }
130 })
136 131
137 { 132 {
138 const res = await getMyUserInformation(server.url, userAccessToken) 133 const res = await getMyUserInformation(server.url, userToken)
139 const info = res.body as User 134 const info = res.body as User
140 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) 135 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
141 } 136 }
@@ -156,12 +151,13 @@ describe('Test notifications API', function () {
156 it('Should only have mail notifications', async function () { 151 it('Should only have mail notifications', async function () {
157 this.timeout(20000) 152 this.timeout(20000)
158 153
159 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 154 await server.notificationsCommand.updateMySettings({
160 newVideoFromSubscription: UserNotificationSettingValue.EMAIL 155 token: userToken,
161 })) 156 settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL }
157 })
162 158
163 { 159 {
164 const res = await getMyUserInformation(server.url, userAccessToken) 160 const res = await getMyUserInformation(server.url, userToken)
165 const info = res.body as User 161 const info = res.body as User
166 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) 162 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
167 } 163 }
@@ -182,12 +178,16 @@ describe('Test notifications API', function () {
182 it('Should have email and web notifications', async function () { 178 it('Should have email and web notifications', async function () {
183 this.timeout(20000) 179 this.timeout(20000)
184 180
185 await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { 181 await server.notificationsCommand.updateMySettings({
186 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 182 token: userToken,
187 })) 183 settings: {
184 ...getAllNotificationsSettings(),
185 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
186 }
187 })
188 188
189 { 189 {
190 const res = await getMyUserInformation(server.url, userAccessToken) 190 const res = await getMyUserInformation(server.url, userToken)
191 const info = res.body as User 191 const info = res.body as User
192 expect(info.notificationSettings.newVideoFromSubscription).to.equal( 192 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
193 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 193 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 1d159c48f..4b31edf25 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -10,7 +10,6 @@ import {
10 checkNewVideoFromSubscription, 10 checkNewVideoFromSubscription,
11 checkVideoIsPublished, 11 checkVideoIsPublished,
12 cleanupTests, 12 cleanupTests,
13 getLastNotification,
14 ImportsCommand, 13 ImportsCommand,
15 MockSmtpServer, 14 MockSmtpServer,
16 prepareNotificationsTest, 15 prepareNotificationsTest,
@@ -64,7 +63,7 @@ describe('Test user notifications', function () {
64 63
65 await uploadRandomVideoOnServers(servers, 1) 64 await uploadRandomVideoOnServers(servers, 1)
66 65
67 const notification = await getLastNotification(servers[0].url, userAccessToken) 66 const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken })
68 expect(notification).to.be.undefined 67 expect(notification).to.be.undefined
69 68
70 expect(emails).to.have.lengthOf(0) 69 expect(emails).to.have.lengthOf(0)
@@ -245,7 +244,7 @@ describe('Test user notifications', function () {
245 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false }) 244 await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false })
246 await waitJobs(servers) 245 await waitJobs(servers)
247 246
248 const notification = await getLastNotification(servers[0].url, userAccessToken) 247 const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken })
249 if (notification) { 248 if (notification) {
250 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED) 249 expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED)
251 } 250 }
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts
index 655cf00fa..d4a43276f 100644
--- a/server/tests/api/server/plugins.ts
+++ b/server/tests/api/server/plugins.ts
@@ -146,13 +146,12 @@ describe('Test plugins', function () {
146 } 146 }
147 147
148 { 148 {
149 const body = await command.list({ 149 const { data } = await command.list({
150 count: 2, 150 count: 2,
151 start: 0, 151 start: 0,
152 sort: 'name' 152 sort: 'name'
153 }) 153 })
154 154
155 const data = body
156 expect(data[0].name).to.equal('background-red') 155 expect(data[0].name).to.equal('background-red')
157 expect(data[1].name).to.equal('hello-world') 156 expect(data[1].name).to.equal('hello-world')
158 } 157 }
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts
index 3dd8c9066..428e1316d 100644
--- a/server/tests/api/videos/video-hls.ts
+++ b/server/tests/api/videos/video-hls.ts
@@ -109,6 +109,7 @@ describe('Test HLS videos', function () {
109 let videoAudioUUID = '' 109 let videoAudioUUID = ''
110 110
111 function runTestSuite (hlsOnly: boolean) { 111 function runTestSuite (hlsOnly: boolean) {
112
112 it('Should upload a video and transcode it to HLS', async function () { 113 it('Should upload a video and transcode it to HLS', async function () {
113 this.timeout(120000) 114 this.timeout(120000)
114 115
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index 65813517d..5f30939cc 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -18,13 +18,13 @@ import {
18 uploadVideo, 18 uploadVideo,
19 userLogin 19 userLogin
20} from '@shared/extra-utils' 20} from '@shared/extra-utils'
21import { BooleanBothQuery, CustomConfig, User, VideosOverview } from '@shared/models' 21import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models'
22 22
23const expect = chai.expect 23const expect = chai.expect
24 24
25function createOverviewRes (overview: VideosOverview) { 25function createOverviewRes (overview: VideosOverview) {
26 const videos = overview.categories[0].videos 26 const videos = overview.categories[0].videos
27 return { body: { data: videos, total: videos.length } } 27 return { data: videos, total: videos.length }
28} 28}
29 29
30describe('Test video NSFW policy', function () { 30describe('Test video NSFW policy', function () {
@@ -32,49 +32,47 @@ describe('Test video NSFW policy', function () {
32 let userAccessToken: string 32 let userAccessToken: string
33 let customConfig: CustomConfig 33 let customConfig: CustomConfig
34 34
35 function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { 35 async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) {
36 return getMyUserInformation(server.url, server.accessToken) 36 const res = await getMyUserInformation(server.url, server.accessToken)
37 .then(res => { 37 const user: User = res.body
38 const user: User = res.body 38 const videoChannelName = user.videoChannels[0].name
39 const videoChannelName = user.videoChannels[0].name 39 const accountName = user.account.name + '@' + user.account.host
40 const accountName = user.account.name + '@' + user.account.host 40 const hasQuery = Object.keys(query).length !== 0
41 const hasQuery = Object.keys(query).length !== 0 41 let promises: Promise<ResultList<Video>>[]
42 let promises: Promise<any>[] 42
43 43 if (token) {
44 if (token) { 44 promises = [
45 promises = [ 45 getVideosListWithToken(server.url, token, query).then(res => res.body),
46 getVideosListWithToken(server.url, token, query), 46 server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }),
47 server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), 47 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body),
48 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), 48 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body)
49 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) 49 ]
50 ] 50
51 51 // Overviews do not support video filters
52 // Overviews do not support video filters 52 if (!hasQuery) {
53 if (!hasQuery) { 53 const p = server.overviewsCommand.getVideos({ page: 1, token })
54 const p = server.overviewsCommand.getVideos({ page: 1, token }) 54 .then(res => createOverviewRes(res))
55 .then(res => createOverviewRes(res)) 55 promises.push(p)
56 promises.push(p) 56 }
57 } 57
58 58 return Promise.all(promises)
59 return Promise.all(promises) 59 }
60 } 60
61 61 promises = [
62 promises = [ 62 getVideosList(server.url).then(res => res.body),
63 getVideosList(server.url), 63 server.searchCommand.searchVideos({ search: 'n' }),
64 server.searchCommand.searchVideos({ search: 'n' }), 64 getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body),
65 getAccountVideos(server.url, undefined, accountName, 0, 5), 65 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body)
66 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) 66 ]
67 ] 67
68 68 // Overviews do not support video filters
69 // Overviews do not support video filters 69 if (!hasQuery) {
70 if (!hasQuery) { 70 const p = server.overviewsCommand.getVideos({ page: 1 })
71 const p = server.overviewsCommand.getVideos({ page: 1 }) 71 .then(res => createOverviewRes(res))
72 .then(res => createOverviewRes(res)) 72 promises.push(p)
73 promises.push(p) 73 }
74 } 74
75 75 return Promise.all(promises)
76 return Promise.all(promises)
77 })
78 } 76 }
79 77
80 before(async function () { 78 before(async function () {
@@ -102,10 +100,10 @@ describe('Test video NSFW policy', function () {
102 const serverConfig = await server.configCommand.getConfig() 100 const serverConfig = await server.configCommand.getConfig()
103 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') 101 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
104 102
105 for (const res of await getVideosFunctions()) { 103 for (const body of await getVideosFunctions()) {
106 expect(res.body.total).to.equal(2) 104 expect(body.total).to.equal(2)
107 105
108 const videos = res.body.data 106 const videos = body.data
109 expect(videos).to.have.lengthOf(2) 107 expect(videos).to.have.lengthOf(2)
110 expect(videos[0].name).to.equal('normal') 108 expect(videos[0].name).to.equal('normal')
111 expect(videos[1].name).to.equal('nsfw') 109 expect(videos[1].name).to.equal('nsfw')
@@ -119,10 +117,10 @@ describe('Test video NSFW policy', function () {
119 const serverConfig = await server.configCommand.getConfig() 117 const serverConfig = await server.configCommand.getConfig()
120 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') 118 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
121 119
122 for (const res of await getVideosFunctions()) { 120 for (const body of await getVideosFunctions()) {
123 expect(res.body.total).to.equal(1) 121 expect(body.total).to.equal(1)
124 122
125 const videos = res.body.data 123 const videos = body.data
126 expect(videos).to.have.lengthOf(1) 124 expect(videos).to.have.lengthOf(1)
127 expect(videos[0].name).to.equal('normal') 125 expect(videos[0].name).to.equal('normal')
128 } 126 }
@@ -135,10 +133,10 @@ describe('Test video NSFW policy', function () {
135 const serverConfig = await server.configCommand.getConfig() 133 const serverConfig = await server.configCommand.getConfig()
136 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') 134 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
137 135
138 for (const res of await getVideosFunctions()) { 136 for (const body of await getVideosFunctions()) {
139 expect(res.body.total).to.equal(2) 137 expect(body.total).to.equal(2)
140 138
141 const videos = res.body.data 139 const videos = body.data
142 expect(videos).to.have.lengthOf(2) 140 expect(videos).to.have.lengthOf(2)
143 expect(videos[0].name).to.equal('normal') 141 expect(videos[0].name).to.equal('normal')
144 expect(videos[1].name).to.equal('nsfw') 142 expect(videos[1].name).to.equal('nsfw')
@@ -165,10 +163,10 @@ describe('Test video NSFW policy', function () {
165 customConfig.instance.defaultNSFWPolicy = 'do_not_list' 163 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
166 await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) 164 await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig })
167 165
168 for (const res of await getVideosFunctions(userAccessToken)) { 166 for (const body of await getVideosFunctions(userAccessToken)) {
169 expect(res.body.total).to.equal(2) 167 expect(body.total).to.equal(2)
170 168
171 const videos = res.body.data 169 const videos = body.data
172 expect(videos).to.have.lengthOf(2) 170 expect(videos).to.have.lengthOf(2)
173 expect(videos[0].name).to.equal('normal') 171 expect(videos[0].name).to.equal('normal')
174 expect(videos[1].name).to.equal('nsfw') 172 expect(videos[1].name).to.equal('nsfw')
@@ -182,10 +180,10 @@ describe('Test video NSFW policy', function () {
182 nsfwPolicy: 'display' 180 nsfwPolicy: 'display'
183 }) 181 })
184 182
185 for (const res of await getVideosFunctions(server.accessToken)) { 183 for (const body of await getVideosFunctions(server.accessToken)) {
186 expect(res.body.total).to.equal(2) 184 expect(body.total).to.equal(2)
187 185
188 const videos = res.body.data 186 const videos = body.data
189 expect(videos).to.have.lengthOf(2) 187 expect(videos).to.have.lengthOf(2)
190 expect(videos[0].name).to.equal('normal') 188 expect(videos[0].name).to.equal('normal')
191 expect(videos[1].name).to.equal('nsfw') 189 expect(videos[1].name).to.equal('nsfw')
@@ -199,10 +197,10 @@ describe('Test video NSFW policy', function () {
199 nsfwPolicy: 'do_not_list' 197 nsfwPolicy: 'do_not_list'
200 }) 198 })
201 199
202 for (const res of await getVideosFunctions(server.accessToken)) { 200 for (const body of await getVideosFunctions(server.accessToken)) {
203 expect(res.body.total).to.equal(1) 201 expect(body.total).to.equal(1)
204 202
205 const videos = res.body.data 203 const videos = body.data
206 expect(videos).to.have.lengthOf(1) 204 expect(videos).to.have.lengthOf(1)
207 expect(videos[0].name).to.equal('normal') 205 expect(videos[0].name).to.equal('normal')
208 } 206 }
@@ -219,30 +217,30 @@ describe('Test video NSFW policy', function () {
219 }) 217 })
220 218
221 it('Should display NSFW videos when the nsfw param === true', async function () { 219 it('Should display NSFW videos when the nsfw param === true', async function () {
222 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { 220 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) {
223 expect(res.body.total).to.equal(1) 221 expect(body.total).to.equal(1)
224 222
225 const videos = res.body.data 223 const videos = body.data
226 expect(videos).to.have.lengthOf(1) 224 expect(videos).to.have.lengthOf(1)
227 expect(videos[0].name).to.equal('nsfw') 225 expect(videos[0].name).to.equal('nsfw')
228 } 226 }
229 }) 227 })
230 228
231 it('Should hide NSFW videos when the nsfw param === true', async function () { 229 it('Should hide NSFW videos when the nsfw param === true', async function () {
232 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { 230 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) {
233 expect(res.body.total).to.equal(1) 231 expect(body.total).to.equal(1)
234 232
235 const videos = res.body.data 233 const videos = body.data
236 expect(videos).to.have.lengthOf(1) 234 expect(videos).to.have.lengthOf(1)
237 expect(videos[0].name).to.equal('normal') 235 expect(videos[0].name).to.equal('normal')
238 } 236 }
239 }) 237 })
240 238
241 it('Should display both videos when the nsfw param === both', async function () { 239 it('Should display both videos when the nsfw param === both', async function () {
242 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) { 240 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
243 expect(res.body.total).to.equal(2) 241 expect(body.total).to.equal(2)
244 242
245 const videos = res.body.data 243 const videos = body.data
246 expect(videos).to.have.lengthOf(2) 244 expect(videos).to.have.lengthOf(2)
247 expect(videos[0].name).to.equal('normal') 245 expect(videos[0].name).to.equal('normal')
248 expect(videos[1].name).to.equal('nsfw') 246 expect(videos[1].name).to.equal('nsfw')