diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 16:40:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | 2c27e70471120c92e0bc8c8114141fbb31ff98ac (patch) | |
tree | f52d89adc0351168fd1d89cbc07652e1408caaf2 /server/tests/api/users/user-subscriptions.ts | |
parent | 5f8bd4cbb178290da7d8f81e996f19f0eccc8e4c (diff) | |
download | PeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.tar.gz PeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.tar.zst PeerTube-2c27e70471120c92e0bc8c8114141fbb31ff98ac.zip |
Introduce subscriptions command
Diffstat (limited to 'server/tests/api/users/user-subscriptions.ts')
-rw-r--r-- | server/tests/api/users/user-subscriptions.ts | 144 |
1 files changed, 61 insertions, 83 deletions
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 7e365d797..c119622ad 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts | |||
@@ -3,25 +3,19 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { |
6 | addUserSubscription, | ||
7 | areSubscriptionsExist, | ||
8 | cleanupTests, | 6 | cleanupTests, |
9 | createUser, | 7 | createUser, |
10 | doubleFollow, | 8 | doubleFollow, |
11 | flushAndRunMultipleServers, | 9 | flushAndRunMultipleServers, |
12 | getUserSubscription, | ||
13 | getVideosList, | 10 | getVideosList, |
14 | listUserSubscriptions, | ||
15 | listUserSubscriptionVideos, | ||
16 | removeUserSubscription, | ||
17 | ServerInfo, | 11 | ServerInfo, |
18 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
13 | SubscriptionsCommand, | ||
19 | updateVideo, | 14 | updateVideo, |
20 | uploadVideo, | 15 | uploadVideo, |
21 | userLogin, | 16 | userLogin, |
22 | waitJobs | 17 | waitJobs |
23 | } from '@shared/extra-utils' | 18 | } from '@shared/extra-utils' |
24 | import { Video, VideoChannel } from '@shared/models' | ||
25 | 19 | ||
26 | const expect = chai.expect | 20 | const expect = chai.expect |
27 | 21 | ||
@@ -30,6 +24,8 @@ describe('Test users subscriptions', function () { | |||
30 | const users: { accessToken: string }[] = [] | 24 | const users: { accessToken: string }[] = [] |
31 | let video3UUID: string | 25 | let video3UUID: string |
32 | 26 | ||
27 | let command: SubscriptionsCommand | ||
28 | |||
33 | before(async function () { | 29 | before(async function () { |
34 | this.timeout(120000) | 30 | this.timeout(120000) |
35 | 31 | ||
@@ -58,6 +54,8 @@ describe('Test users subscriptions', function () { | |||
58 | } | 54 | } |
59 | 55 | ||
60 | await waitJobs(servers) | 56 | await waitJobs(servers) |
57 | |||
58 | command = servers[0].subscriptionsCommand | ||
61 | }) | 59 | }) |
62 | 60 | ||
63 | it('Should display videos of server 2 on server 1', async function () { | 61 | it('Should display videos of server 2 on server 1', async function () { |
@@ -69,8 +67,8 @@ describe('Test users subscriptions', function () { | |||
69 | it('User of server 1 should follow user of server 3 and root of server 1', async function () { | 67 | it('User of server 1 should follow user of server 3 and root of server 1', async function () { |
70 | this.timeout(60000) | 68 | this.timeout(60000) |
71 | 69 | ||
72 | await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) | 70 | await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) |
73 | await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) | 71 | await command.add({ token: users[0].accessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) |
74 | 72 | ||
75 | await waitJobs(servers) | 73 | await waitJobs(servers) |
76 | 74 | ||
@@ -93,17 +91,17 @@ describe('Test users subscriptions', function () { | |||
93 | 91 | ||
94 | it('Should list subscriptions', async function () { | 92 | it('Should list subscriptions', async function () { |
95 | { | 93 | { |
96 | const res = await listUserSubscriptions({ url: servers[0].url, token: servers[0].accessToken }) | 94 | const body = await command.list() |
97 | expect(res.body.total).to.equal(0) | 95 | expect(body.total).to.equal(0) |
98 | expect(res.body.data).to.be.an('array') | 96 | expect(body.data).to.be.an('array') |
99 | expect(res.body.data).to.have.lengthOf(0) | 97 | expect(body.data).to.have.lengthOf(0) |
100 | } | 98 | } |
101 | 99 | ||
102 | { | 100 | { |
103 | const res = await listUserSubscriptions({ url: servers[0].url, token: users[0].accessToken, sort: 'createdAt' }) | 101 | const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) |
104 | expect(res.body.total).to.equal(2) | 102 | expect(body.total).to.equal(2) |
105 | 103 | ||
106 | const subscriptions: VideoChannel[] = res.body.data | 104 | const subscriptions = body.data |
107 | expect(subscriptions).to.be.an('array') | 105 | expect(subscriptions).to.be.an('array') |
108 | expect(subscriptions).to.have.lengthOf(2) | 106 | expect(subscriptions).to.have.lengthOf(2) |
109 | 107 | ||
@@ -114,8 +112,7 @@ describe('Test users subscriptions', function () { | |||
114 | 112 | ||
115 | it('Should get subscription', async function () { | 113 | it('Should get subscription', async function () { |
116 | { | 114 | { |
117 | const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) | 115 | const videoChannel = await command.get({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) |
118 | const videoChannel: VideoChannel = res.body | ||
119 | 116 | ||
120 | expect(videoChannel.name).to.equal('user3_channel') | 117 | expect(videoChannel.name).to.equal('user3_channel') |
121 | expect(videoChannel.host).to.equal('localhost:' + servers[2].port) | 118 | expect(videoChannel.host).to.equal('localhost:' + servers[2].port) |
@@ -125,8 +122,7 @@ describe('Test users subscriptions', function () { | |||
125 | } | 122 | } |
126 | 123 | ||
127 | { | 124 | { |
128 | const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) | 125 | const videoChannel = await command.get({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) |
129 | const videoChannel: VideoChannel = res.body | ||
130 | 126 | ||
131 | expect(videoChannel.name).to.equal('root_channel') | 127 | expect(videoChannel.name).to.equal('root_channel') |
132 | expect(videoChannel.host).to.equal('localhost:' + servers[0].port) | 128 | expect(videoChannel.host).to.equal('localhost:' + servers[0].port) |
@@ -144,8 +140,7 @@ describe('Test users subscriptions', function () { | |||
144 | 'user3_channel@localhost:' + servers[0].port | 140 | 'user3_channel@localhost:' + servers[0].port |
145 | ] | 141 | ] |
146 | 142 | ||
147 | const res = await areSubscriptionsExist(servers[0].url, users[0].accessToken, uris) | 143 | const body = await command.exist({ token: users[0].accessToken, uris }) |
148 | const body = res.body | ||
149 | 144 | ||
150 | expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true | 145 | expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true |
151 | expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false | 146 | expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false |
@@ -155,45 +150,31 @@ describe('Test users subscriptions', function () { | |||
155 | 150 | ||
156 | it('Should search among subscriptions', async function () { | 151 | it('Should search among subscriptions', async function () { |
157 | { | 152 | { |
158 | const res = await listUserSubscriptions({ | 153 | const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'user3_channel' }) |
159 | url: servers[0].url, | 154 | expect(body.total).to.equal(1) |
160 | token: users[0].accessToken, | 155 | expect(body.data).to.have.lengthOf(1) |
161 | sort: '-createdAt', | ||
162 | search: 'user3_channel' | ||
163 | }) | ||
164 | expect(res.body.total).to.equal(1) | ||
165 | |||
166 | const subscriptions = res.body.data | ||
167 | expect(subscriptions).to.have.lengthOf(1) | ||
168 | } | 156 | } |
169 | 157 | ||
170 | { | 158 | { |
171 | const res = await listUserSubscriptions({ | 159 | const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'toto' }) |
172 | url: servers[0].url, | 160 | expect(body.total).to.equal(0) |
173 | token: users[0].accessToken, | 161 | expect(body.data).to.have.lengthOf(0) |
174 | sort: '-createdAt', | ||
175 | search: 'toto' | ||
176 | }) | ||
177 | expect(res.body.total).to.equal(0) | ||
178 | |||
179 | const subscriptions = res.body.data | ||
180 | expect(subscriptions).to.have.lengthOf(0) | ||
181 | } | 162 | } |
182 | }) | 163 | }) |
183 | 164 | ||
184 | it('Should list subscription videos', async function () { | 165 | it('Should list subscription videos', async function () { |
185 | { | 166 | { |
186 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | 167 | const body = await command.listVideos() |
187 | expect(res.body.total).to.equal(0) | 168 | expect(body.total).to.equal(0) |
188 | expect(res.body.data).to.be.an('array') | 169 | expect(body.data).to.be.an('array') |
189 | expect(res.body.data).to.have.lengthOf(0) | 170 | expect(body.data).to.have.lengthOf(0) |
190 | } | 171 | } |
191 | 172 | ||
192 | { | 173 | { |
193 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 174 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
194 | expect(res.body.total).to.equal(3) | 175 | expect(body.total).to.equal(3) |
195 | 176 | ||
196 | const videos: Video[] = res.body.data | 177 | const videos = body.data |
197 | expect(videos).to.be.an('array') | 178 | expect(videos).to.be.an('array') |
198 | expect(videos).to.have.lengthOf(3) | 179 | expect(videos).to.have.lengthOf(3) |
199 | 180 | ||
@@ -212,17 +193,17 @@ describe('Test users subscriptions', function () { | |||
212 | await waitJobs(servers) | 193 | await waitJobs(servers) |
213 | 194 | ||
214 | { | 195 | { |
215 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | 196 | const body = await command.listVideos() |
216 | expect(res.body.total).to.equal(0) | 197 | expect(body.total).to.equal(0) |
217 | expect(res.body.data).to.be.an('array') | 198 | expect(body.data).to.be.an('array') |
218 | expect(res.body.data).to.have.lengthOf(0) | 199 | expect(body.data).to.have.lengthOf(0) |
219 | } | 200 | } |
220 | 201 | ||
221 | { | 202 | { |
222 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 203 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
223 | expect(res.body.total).to.equal(4) | 204 | expect(body.total).to.equal(4) |
224 | 205 | ||
225 | const videos: Video[] = res.body.data | 206 | const videos = body.data |
226 | expect(videos).to.be.an('array') | 207 | expect(videos).to.be.an('array') |
227 | expect(videos).to.have.lengthOf(4) | 208 | expect(videos).to.have.lengthOf(4) |
228 | 209 | ||
@@ -281,17 +262,17 @@ describe('Test users subscriptions', function () { | |||
281 | 262 | ||
282 | it('Should still list subscription videos', async function () { | 263 | it('Should still list subscription videos', async function () { |
283 | { | 264 | { |
284 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | 265 | const body = await command.listVideos() |
285 | expect(res.body.total).to.equal(0) | 266 | expect(body.total).to.equal(0) |
286 | expect(res.body.data).to.be.an('array') | 267 | expect(body.data).to.be.an('array') |
287 | expect(res.body.data).to.have.lengthOf(0) | 268 | expect(body.data).to.have.lengthOf(0) |
288 | } | 269 | } |
289 | 270 | ||
290 | { | 271 | { |
291 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 272 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
292 | expect(res.body.total).to.equal(4) | 273 | expect(body.total).to.equal(4) |
293 | 274 | ||
294 | const videos: Video[] = res.body.data | 275 | const videos = body.data |
295 | expect(videos).to.be.an('array') | 276 | expect(videos).to.be.an('array') |
296 | expect(videos).to.have.lengthOf(4) | 277 | expect(videos).to.have.lengthOf(4) |
297 | 278 | ||
@@ -309,44 +290,41 @@ describe('Test users subscriptions', function () { | |||
309 | 290 | ||
310 | await waitJobs(servers) | 291 | await waitJobs(servers) |
311 | 292 | ||
312 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 293 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
313 | const videos: Video[] = res.body.data | 294 | expect(body.data[2].name).to.equal('video server 3 added after follow updated') |
314 | expect(videos[2].name).to.equal('video server 3 added after follow updated') | ||
315 | }) | 295 | }) |
316 | 296 | ||
317 | it('Should remove user of server 3 subscription', async function () { | 297 | it('Should remove user of server 3 subscription', async function () { |
318 | this.timeout(30000) | 298 | this.timeout(30000) |
319 | 299 | ||
320 | await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) | 300 | await command.remove({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) |
321 | 301 | ||
322 | await waitJobs(servers) | 302 | await waitJobs(servers) |
323 | }) | 303 | }) |
324 | 304 | ||
325 | it('Should not display its videos anymore', async function () { | 305 | it('Should not display its videos anymore', async function () { |
326 | { | 306 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
327 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 307 | expect(body.total).to.equal(1) |
328 | expect(res.body.total).to.equal(1) | ||
329 | 308 | ||
330 | const videos: Video[] = res.body.data | 309 | const videos = body.data |
331 | expect(videos).to.be.an('array') | 310 | expect(videos).to.be.an('array') |
332 | expect(videos).to.have.lengthOf(1) | 311 | expect(videos).to.have.lengthOf(1) |
333 | 312 | ||
334 | expect(videos[0].name).to.equal('video server 1 added after follow') | 313 | expect(videos[0].name).to.equal('video server 1 added after follow') |
335 | } | ||
336 | }) | 314 | }) |
337 | 315 | ||
338 | it('Should remove the root subscription and not display the videos anymore', async function () { | 316 | it('Should remove the root subscription and not display the videos anymore', async function () { |
339 | this.timeout(30000) | 317 | this.timeout(30000) |
340 | 318 | ||
341 | await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) | 319 | await command.remove({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) |
342 | 320 | ||
343 | await waitJobs(servers) | 321 | await waitJobs(servers) |
344 | 322 | ||
345 | { | 323 | { |
346 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 324 | const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) |
347 | expect(res.body.total).to.equal(0) | 325 | expect(body.total).to.equal(0) |
348 | 326 | ||
349 | const videos: Video[] = res.body.data | 327 | const videos = body.data |
350 | expect(videos).to.be.an('array') | 328 | expect(videos).to.be.an('array') |
351 | expect(videos).to.have.lengthOf(0) | 329 | expect(videos).to.have.lengthOf(0) |
352 | } | 330 | } |
@@ -366,15 +344,15 @@ describe('Test users subscriptions', function () { | |||
366 | it('Should follow user of server 3 again', async function () { | 344 | it('Should follow user of server 3 again', async function () { |
367 | this.timeout(60000) | 345 | this.timeout(60000) |
368 | 346 | ||
369 | await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) | 347 | await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) |
370 | 348 | ||
371 | await waitJobs(servers) | 349 | await waitJobs(servers) |
372 | 350 | ||
373 | { | 351 | { |
374 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 352 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
375 | expect(res.body.total).to.equal(3) | 353 | expect(body.total).to.equal(3) |
376 | 354 | ||
377 | const videos: Video[] = res.body.data | 355 | const videos = body.data |
378 | expect(videos).to.be.an('array') | 356 | expect(videos).to.be.an('array') |
379 | expect(videos).to.have.lengthOf(3) | 357 | expect(videos).to.have.lengthOf(3) |
380 | 358 | ||