aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts220
-rw-r--r--server/tests/api/index-slow.ts1
-rw-r--r--server/tests/api/users/user-subscriptions.ts312
-rw-r--r--server/tests/utils/users/user-subscriptions.ts57
5 files changed, 591 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 03fdd5c4e..777acbb0f 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -12,3 +12,4 @@ import './video-comments'
12import './videos' 12import './videos'
13import './video-imports' 13import './video-imports'
14import './search' 14import './search'
15import './user-subscriptions'
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
new file mode 100644
index 000000000..9f7d15b27
--- /dev/null
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -0,0 +1,220 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 flushTests,
8 getMyUserInformation,
9 killallServers,
10 makeDeleteRequest,
11 makeGetRequest,
12 makePostBodyRequest,
13 runServer,
14 ServerInfo,
15 setAccessTokensToServers,
16 userLogin
17} from '../../utils'
18import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
19
20describe('Test user subscriptions API validators', function () {
21 const path = '/api/v1/users/me/subscriptions'
22 let server: ServerInfo
23 let userAccessToken = ''
24 let userChannelUUID: string
25
26 // ---------------------------------------------------------------
27
28 before(async function () {
29 this.timeout(30000)
30
31 await flushTests()
32
33 server = await runServer(1)
34
35 await setAccessTokensToServers([ server ])
36
37 const user = {
38 username: 'user1',
39 password: 'my super password'
40 }
41 await createUser(server.url, server.accessToken, user.username, user.password)
42 userAccessToken = await userLogin(server, user)
43
44 {
45 const res = await getMyUserInformation(server.url, server.accessToken)
46 userChannelUUID = res.body.videoChannels[ 0 ].uuid
47 }
48 })
49
50 describe('When listing my subscriptions', function () {
51 it('Should fail with a bad start pagination', async function () {
52 await checkBadStartPagination(server.url, path, server.accessToken)
53 })
54
55 it('Should fail with a bad count pagination', async function () {
56 await checkBadCountPagination(server.url, path, server.accessToken)
57 })
58
59 it('Should fail with an incorrect sort', async function () {
60 await checkBadSortPagination(server.url, path, server.accessToken)
61 })
62
63 it('Should fail with a non authenticated user', async function () {
64 await makeGetRequest({
65 url: server.url,
66 path,
67 statusCodeExpected: 401
68 })
69 })
70
71 it('Should success with the correct parameters', async function () {
72 await await makeGetRequest({
73 url: server.url,
74 path,
75 token: userAccessToken,
76 statusCodeExpected: 200
77 })
78 })
79 })
80
81 describe('When listing my subscriptions videos', function () {
82 const path = '/api/v1/users/me/subscriptions/videos'
83
84 it('Should fail with a bad start pagination', async function () {
85 await checkBadStartPagination(server.url, path, server.accessToken)
86 })
87
88 it('Should fail with a bad count pagination', async function () {
89 await checkBadCountPagination(server.url, path, server.accessToken)
90 })
91
92 it('Should fail with an incorrect sort', async function () {
93 await checkBadSortPagination(server.url, path, server.accessToken)
94 })
95
96 it('Should fail with a non authenticated user', async function () {
97 await makeGetRequest({
98 url: server.url,
99 path,
100 statusCodeExpected: 401
101 })
102 })
103
104 it('Should success with the correct parameters', async function () {
105 await await makeGetRequest({
106 url: server.url,
107 path,
108 token: userAccessToken,
109 statusCodeExpected: 200
110 })
111 })
112 })
113
114 describe('When adding a subscription', function () {
115 it('Should fail with a non authenticated user', async function () {
116 await makePostBodyRequest({
117 url: server.url,
118 path,
119 fields: { uri: userChannelUUID + '@localhost:9001' },
120 statusCodeExpected: 401
121 })
122 })
123
124 it('Should fail with bad URIs', async function () {
125 await makePostBodyRequest({
126 url: server.url,
127 path,
128 token: server.accessToken,
129 fields: { uri: 'root' },
130 statusCodeExpected: 400
131 })
132
133 await makePostBodyRequest({
134 url: server.url,
135 path,
136 token: server.accessToken,
137 fields: { uri: 'root@' },
138 statusCodeExpected: 400
139 })
140
141 await makePostBodyRequest({
142 url: server.url,
143 path,
144 token: server.accessToken,
145 fields: { uri: 'root@hello@' },
146 statusCodeExpected: 400
147 })
148 })
149
150 it('Should success with the correct parameters', async function () {
151 await makePostBodyRequest({
152 url: server.url,
153 path,
154 token: server.accessToken,
155 fields: { uri: userChannelUUID + '@localhost:9001' },
156 statusCodeExpected: 204
157 })
158 })
159 })
160
161 describe('When removing a subscription', function () {
162 it('Should fail with a non authenticated user', async function () {
163 await makeDeleteRequest({
164 url: server.url,
165 path: path + '/' + userChannelUUID + '@localhost:9001',
166 statusCodeExpected: 401
167 })
168 })
169
170 it('Should fail with bad URIs', async function () {
171 await makeDeleteRequest({
172 url: server.url,
173 path: path + '/root',
174 token: server.accessToken,
175 statusCodeExpected: 400
176 })
177
178 await makeDeleteRequest({
179 url: server.url,
180 path: path + '/root@',
181 token: server.accessToken,
182 statusCodeExpected: 400
183 })
184
185 await makeDeleteRequest({
186 url: server.url,
187 path: path + '/root@hello@',
188 token: server.accessToken,
189 statusCodeExpected: 400
190 })
191 })
192
193 it('Should fail with an unknown subscription', async function () {
194 await makeDeleteRequest({
195 url: server.url,
196 path: path + '/root1@localhost:9001',
197 token: server.accessToken,
198 statusCodeExpected: 404
199 })
200 })
201
202 it('Should success with the correct parameters', async function () {
203 await makeDeleteRequest({
204 url: server.url,
205 path: path + '/' + userChannelUUID + '@localhost:9001',
206 token: server.accessToken,
207 statusCodeExpected: 204
208 })
209 })
210 })
211
212 after(async function () {
213 killallServers([ server ])
214
215 // Keep the logs if the test failed
216 if (this['ok']) {
217 await flushTests()
218 }
219 })
220})
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts
index 243c941cb..e24a7b664 100644
--- a/server/tests/api/index-slow.ts
+++ b/server/tests/api/index-slow.ts
@@ -6,6 +6,7 @@ import './server/follows'
6import './server/jobs' 6import './server/jobs'
7import './videos/video-comments' 7import './videos/video-comments'
8import './users/users-multiple-servers' 8import './users/users-multiple-servers'
9import './users/user-subscriptions'
9import './server/handle-down' 10import './server/handle-down'
10import './videos/video-schedule-update' 11import './videos/video-schedule-update'
11import './videos/video-imports' 12import './videos/video-imports'
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
new file mode 100644
index 000000000..2ba6cdfaf
--- /dev/null
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -0,0 +1,312 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { createUser, doubleFollow, flushAndRunMultipleServers, follow, getVideosList, unfollow, userLogin } from '../../utils'
6import { getMyUserInformation, killallServers, ServerInfo, uploadVideo } from '../../utils/index'
7import { setAccessTokensToServers } from '../../utils/users/login'
8import { Video, VideoChannel } from '../../../../shared/models/videos'
9import { waitJobs } from '../../utils/server/jobs'
10import {
11 addUserSubscription,
12 listUserSubscriptions,
13 listUserSubscriptionVideos,
14 removeUserSubscription
15} from '../../utils/users/user-subscriptions'
16
17const expect = chai.expect
18
19describe('Test users subscriptions', function () {
20 let servers: ServerInfo[] = []
21 const users: { accessToken: string, videoChannelName: string }[] = []
22 let rootChannelNameServer1: string
23
24 before(async function () {
25 this.timeout(120000)
26
27 servers = await flushAndRunMultipleServers(3)
28
29 // Get the access tokens
30 await setAccessTokensToServers(servers)
31
32 // Server 1 and server 2 follow each other
33 await doubleFollow(servers[0], servers[1])
34
35 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
36 rootChannelNameServer1 = res.body.videoChannels[0].name
37
38 {
39 for (const server of servers) {
40 const user = { username: 'user' + server.serverNumber, password: 'password' }
41 await createUser(server.url, server.accessToken, user.username, user.password)
42
43 const accessToken = await userLogin(server, user)
44 const res = await getMyUserInformation(server.url, accessToken)
45 const videoChannels: VideoChannel[] = res.body.videoChannels
46
47 users.push({ accessToken, videoChannelName: videoChannels[0].name })
48
49 const videoName1 = 'video 1-' + server.serverNumber
50 await uploadVideo(server.url, accessToken, { name: videoName1 })
51
52 const videoName2 = 'video 2-' + server.serverNumber
53 await uploadVideo(server.url, accessToken, { name: videoName2 })
54 }
55 }
56
57 await waitJobs(servers)
58 })
59
60 it('Should display videos of server 2 on server 1', async function () {
61 const res = await getVideosList(servers[0].url)
62
63 expect(res.body.total).to.equal(4)
64 })
65
66 it('User of server 1 should follow user of server 3 and root of server 1', async function () {
67 this.timeout(30000)
68
69 await addUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003')
70 await addUserSubscription(servers[0].url, users[0].accessToken, rootChannelNameServer1 + '@localhost:9001')
71
72 await waitJobs(servers)
73
74 await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' })
75
76 await waitJobs(servers)
77 })
78
79 it('Should not display videos of server 3 on server 1', async function () {
80 const res = await getVideosList(servers[0].url)
81
82 expect(res.body.total).to.equal(4)
83 for (const video of res.body.data) {
84 expect(video.name).to.not.contain('1-3')
85 expect(video.name).to.not.contain('2-3')
86 expect(video.name).to.not.contain('video server 3 added after follow')
87 }
88 })
89
90 it('Should list subscriptions', async function () {
91 {
92 const res = await listUserSubscriptions(servers[0].url, servers[0].accessToken)
93 expect(res.body.total).to.equal(0)
94 expect(res.body.data).to.be.an('array')
95 expect(res.body.data).to.have.lengthOf(0)
96 }
97
98 {
99 const res = await listUserSubscriptions(servers[0].url, users[0].accessToken)
100 expect(res.body.total).to.equal(2)
101
102 const subscriptions: VideoChannel[] = res.body.data
103 expect(subscriptions).to.be.an('array')
104 expect(subscriptions).to.have.lengthOf(2)
105
106 expect(subscriptions[0].name).to.equal(users[2].videoChannelName)
107 expect(subscriptions[1].name).to.equal(rootChannelNameServer1)
108 }
109 })
110
111 it('Should list subscription videos', async function () {
112 {
113 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken)
114 expect(res.body.total).to.equal(0)
115 expect(res.body.data).to.be.an('array')
116 expect(res.body.data).to.have.lengthOf(0)
117 }
118
119 {
120 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
121 expect(res.body.total).to.equal(3)
122
123 const videos: Video[] = res.body.data
124 expect(videos).to.be.an('array')
125 expect(videos).to.have.lengthOf(3)
126
127 expect(videos[0].name).to.equal('video 1-3')
128 expect(videos[1].name).to.equal('video 2-3')
129 expect(videos[2].name).to.equal('video server 3 added after follow')
130 }
131 })
132
133 it('Should upload a video by root on server 1 and see it in the subscription videos', async function () {
134 this.timeout(30000)
135
136 const videoName = 'video server 1 added after follow'
137 await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName })
138
139 await waitJobs(servers)
140
141 {
142 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken)
143 expect(res.body.total).to.equal(0)
144 expect(res.body.data).to.be.an('array')
145 expect(res.body.data).to.have.lengthOf(0)
146 }
147
148 {
149 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
150 expect(res.body.total).to.equal(4)
151
152 const videos: Video[] = res.body.data
153 expect(videos).to.be.an('array')
154 expect(videos).to.have.lengthOf(4)
155
156 expect(videos[0].name).to.equal('video 1-3')
157 expect(videos[1].name).to.equal('video 2-3')
158 expect(videos[2].name).to.equal('video server 3 added after follow')
159 expect(videos[3].name).to.equal('video server 1 added after follow')
160 }
161
162 {
163 const res = await getVideosList(servers[0].url)
164
165 expect(res.body.total).to.equal(5)
166 for (const video of res.body.data) {
167 expect(video.name).to.not.contain('1-3')
168 expect(video.name).to.not.contain('2-3')
169 expect(video.name).to.not.contain('video server 3 added after follow')
170 }
171 }
172 })
173
174 it('Should have server 1 follow server 3 and display server 3 videos', async function () {
175 this.timeout(30000)
176
177 await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
178
179 await waitJobs(servers)
180
181 const res = await getVideosList(servers[0].url)
182
183 expect(res.body.total).to.equal(8)
184
185 const names = [ '1-3', '2-3', 'video server 3 added after follow' ]
186 for (const name of names) {
187 const video = res.body.data.find(v => v.name.indexOf(name) === -1)
188 expect(video).to.not.be.undefined
189 }
190 })
191
192 it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () {
193 this.timeout(30000)
194
195 await unfollow(servers[0].url, servers[0].accessToken, servers[2])
196
197 await waitJobs(servers)
198
199 const res = await getVideosList(servers[0].url)
200
201 expect(res.body.total).to.equal(5)
202 for (const video of res.body.data) {
203 expect(video.name).to.not.contain('1-3')
204 expect(video.name).to.not.contain('2-3')
205 expect(video.name).to.not.contain('video server 3 added after follow')
206 }
207 })
208
209 it('Should still list subscription videos', async function () {
210 {
211 const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken)
212 expect(res.body.total).to.equal(0)
213 expect(res.body.data).to.be.an('array')
214 expect(res.body.data).to.have.lengthOf(0)
215 }
216
217 {
218 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
219 expect(res.body.total).to.equal(4)
220
221 const videos: Video[] = res.body.data
222 expect(videos).to.be.an('array')
223 expect(videos).to.have.lengthOf(4)
224
225 expect(videos[0].name).to.equal('video 1-3')
226 expect(videos[1].name).to.equal('video 2-3')
227 expect(videos[2].name).to.equal('video server 3 added after follow')
228 expect(videos[3].name).to.equal('video server 1 added after follow')
229 }
230 })
231
232 it('Should remove user of server 3 subscription', async function () {
233 await removeUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003')
234
235 await waitJobs(servers)
236 })
237
238 it('Should not display its videos anymore', async function () {
239 {
240 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
241 expect(res.body.total).to.equal(1)
242
243 const videos: Video[] = res.body.data
244 expect(videos).to.be.an('array')
245 expect(videos).to.have.lengthOf(1)
246
247 expect(videos[0].name).to.equal('video server 1 added after follow')
248 }
249 })
250
251 it('Should remove the root subscription and not display the videos anymore', async function () {
252 await removeUserSubscription(servers[0].url, users[0].accessToken, rootChannelNameServer1 + '@localhost:9001')
253
254 await waitJobs(servers)
255
256 {
257 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
258 expect(res.body.total).to.equal(0)
259
260 const videos: Video[] = res.body.data
261 expect(videos).to.be.an('array')
262 expect(videos).to.have.lengthOf(0)
263 }
264 })
265
266 it('Should correctly display public videos on server 1', async function () {
267 const res = await getVideosList(servers[0].url)
268
269 expect(res.body.total).to.equal(5)
270 for (const video of res.body.data) {
271 expect(video.name).to.not.contain('1-3')
272 expect(video.name).to.not.contain('2-3')
273 expect(video.name).to.not.contain('video server 3 added after follow')
274 }
275 })
276
277 it('Should follow user of server 3 again', async function () {
278 this.timeout(30000)
279
280 await addUserSubscription(servers[0].url, users[0].accessToken, users[2].videoChannelName + '@localhost:9003')
281
282 await waitJobs(servers)
283
284 {
285 const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt')
286 expect(res.body.total).to.equal(3)
287
288 const videos: Video[] = res.body.data
289 expect(videos).to.be.an('array')
290 expect(videos).to.have.lengthOf(3)
291
292 expect(videos[0].name).to.equal('video 1-3')
293 expect(videos[1].name).to.equal('video 2-3')
294 expect(videos[2].name).to.equal('video server 3 added after follow')
295 }
296
297 {
298 const res = await getVideosList(servers[0].url)
299
300 expect(res.body.total).to.equal(5)
301 for (const video of res.body.data) {
302 expect(video.name).to.not.contain('1-3')
303 expect(video.name).to.not.contain('2-3')
304 expect(video.name).to.not.contain('video server 3 added after follow')
305 }
306 }
307 })
308
309 after(async function () {
310 killallServers(servers)
311 })
312})
diff --git a/server/tests/utils/users/user-subscriptions.ts b/server/tests/utils/users/user-subscriptions.ts
new file mode 100644
index 000000000..323e5de58
--- /dev/null
+++ b/server/tests/utils/users/user-subscriptions.ts
@@ -0,0 +1,57 @@
1import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../'
2
3function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = 204) {
4 const path = '/api/v1/users/me/subscriptions'
5
6 return makePostBodyRequest({
7 url,
8 path,
9 token,
10 statusCodeExpected,
11 fields: { uri: targetUri }
12 })
13}
14
15function listUserSubscriptions (url: string, token: string, sort = '-createdAt', statusCodeExpected = 200) {
16 const path = '/api/v1/users/me/subscriptions'
17
18 return makeGetRequest({
19 url,
20 path,
21 token,
22 statusCodeExpected,
23 query: { sort }
24 })
25}
26
27function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = 200) {
28 const path = '/api/v1/users/me/subscriptions/videos'
29
30 return makeGetRequest({
31 url,
32 path,
33 token,
34 statusCodeExpected,
35 query: { sort }
36 })
37}
38
39function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = 204) {
40 const path = '/api/v1/users/me/subscriptions/' + uri
41
42 return makeDeleteRequest({
43 url,
44 path,
45 token,
46 statusCodeExpected
47 })
48}
49
50// ---------------------------------------------------------------------------
51
52export {
53 addUserSubscription,
54 listUserSubscriptions,
55 listUserSubscriptionVideos,
56 removeUserSubscription
57}