aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/feeds/feeds.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-25 11:04:18 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commit18490b07650d77d7fe376970b749af5a8c672fd6 (patch)
tree89741e63e34c2659487c9afa8309755064cb0c39 /server/tests/feeds/feeds.ts
parent5beb89f223539f1e415a976ff104f772526b4d20 (diff)
downloadPeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.tar.gz
PeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.tar.zst
PeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.zip
Fix migration and test
Diffstat (limited to 'server/tests/feeds/feeds.ts')
-rw-r--r--server/tests/feeds/feeds.ts53
1 files changed, 35 insertions, 18 deletions
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 175ea9102..92a468192 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -8,28 +8,29 @@ import {
8 addAccountToServerBlocklist, 8 addAccountToServerBlocklist,
9 removeAccountFromServerBlocklist 9 removeAccountFromServerBlocklist
10} from '@shared/extra-utils/users/blocklist' 10} from '@shared/extra-utils/users/blocklist'
11import { addUserSubscription, listUserSubscriptionVideos } from '@shared/extra-utils/users/user-subscriptions'
11import { VideoPrivacy } from '@shared/models' 12import { VideoPrivacy } from '@shared/models'
13import { ScopedToken } from '@shared/models/users/user-scoped-token'
12import { 14import {
13 cleanupTests, 15 cleanupTests,
14 createUser, 16 createUser,
15 doubleFollow, 17 doubleFollow,
16 flushAndRunMultipleServers, 18 flushAndRunMultipleServers,
19 flushAndRunServer,
17 getJSONfeed, 20 getJSONfeed,
18 getMyUserInformation, 21 getMyUserInformation,
22 getUserScopedTokens,
19 getXMLfeed, 23 getXMLfeed,
24 renewUserScopedTokens,
20 ServerInfo, 25 ServerInfo,
21 setAccessTokensToServers, 26 setAccessTokensToServers,
22 uploadVideo, 27 uploadVideo,
23 uploadVideoAndGetId, 28 uploadVideoAndGetId,
24 userLogin, 29 userLogin
25 flushAndRunServer,
26 getUserScopedTokens
27} from '../../../shared/extra-utils' 30} from '../../../shared/extra-utils'
28import { waitJobs } from '../../../shared/extra-utils/server/jobs' 31import { waitJobs } from '../../../shared/extra-utils/server/jobs'
29import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' 32import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
30import { User } from '../../../shared/models/users' 33import { User } from '../../../shared/models/users'
31import { ScopedToken } from '@shared/models/users/user-scoped-token'
32import { listUserSubscriptionVideos, addUserSubscription } from '@shared/extra-utils/users/user-subscriptions'
33 34
34chai.use(require('chai-xml')) 35chai.use(require('chai-xml'))
35chai.use(require('chai-json-schema')) 36chai.use(require('chai-json-schema'))
@@ -298,14 +299,10 @@ describe('Test syndication feeds', () => {
298 }) 299 })
299 300
300 describe('Video feed from my subscriptions', function () { 301 describe('Video feed from my subscriptions', function () {
301 /** 302 let feeduserAccountId: number
302 * use the 'version' query parameter to bust cache between tests 303 let feeduserFeedToken: string
303 */
304 304
305 it('Should list no videos for a user with no videos and no subscriptions', async function () { 305 it('Should list no videos for a user with no videos and no subscriptions', async function () {
306 let feeduserAccountId: number
307 let feeduserFeedToken: string
308
309 const attr = { username: 'feeduser', password: 'password' } 306 const attr = { username: 'feeduser', password: 'password' }
310 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) 307 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
311 const feeduserAccessToken = await userLogin(servers[0], attr) 308 const feeduserAccessToken = await userLogin(servers[0], attr)
@@ -332,15 +329,21 @@ describe('Test syndication feeds', () => {
332 } 329 }
333 }) 330 })
334 331
332 it('Should fail with an invalid token', async function () {
333 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: feeduserAccountId, token: 'toto' }, 403)
334 })
335
336 it('Should fail with a token of another user', async function () {
337 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: feeduserAccountId, token: userFeedToken }, 403)
338 })
339
335 it('Should list no videos for a user with videos but no subscriptions', async function () { 340 it('Should list no videos for a user with videos but no subscriptions', async function () {
336 { 341 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken)
337 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) 342 expect(res.body.total).to.equal(0)
338 expect(res.body.total).to.equal(0)
339 343
340 const json = await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken }) 344 const json = await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken })
341 const jsonObj = JSON.parse(json.text) 345 const jsonObj = JSON.parse(json.text)
342 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos 346 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
343 }
344 }) 347 })
345 348
346 it('Should list self videos for a user with a subscription to themselves', async function () { 349 it('Should list self videos for a user with a subscription to themselves', async function () {
@@ -376,6 +379,20 @@ describe('Test syndication feeds', () => {
376 } 379 }
377 }) 380 })
378 381
382 it('Should renew the token, and so have an invalid old token', async function () {
383 await renewUserScopedTokens(servers[0].url, userAccessToken)
384
385 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken, version: 3 }, 403)
386 })
387
388 it('Should succeed with the new token', async function () {
389 const res2 = await getUserScopedTokens(servers[0].url, userAccessToken)
390 const token: ScopedToken = res2.body
391 userFeedToken = token.feedToken
392
393 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken, version: 4 })
394 })
395
379 }) 396 })
380 397
381 after(async function () { 398 after(async function () {