]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/feeds/feeds.ts
Introduce videos command
[github/Chocobozzz/PeerTube.git] / server / tests / feeds / feeds.ts
index 17efc666d24ca612862123d0236ce2cb88495017..c66cdde1bfbad8feee052d05d9c02ecec8de9af5 100644 (file)
@@ -5,26 +5,15 @@ import * as chai from 'chai'
 import * as xmlParser from 'fast-xml-parser'
 import { HttpStatusCode } from '@shared/core-utils'
 import {
-  addUserSubscription,
-  addVideoCommentThread,
   cleanupTests,
-  createUser,
   doubleFollow,
   flushAndRunMultipleServers,
   flushAndRunServer,
-  getMyUserInformation,
-  getUserScopedTokens,
-  listUserSubscriptionVideos,
-  renewUserScopedTokens,
   ServerInfo,
   setAccessTokensToServers,
-  uploadVideo,
-  uploadVideoAndGetId,
-  userLogin,
   waitJobs
 } from '@shared/extra-utils'
-import { User, VideoPrivacy } from '@shared/models'
-import { ScopedToken } from '@shared/models/users/user-scoped-token'
+import { VideoPrivacy } from '@shared/models'
 
 chai.use(require('chai-xml'))
 chai.use(require('chai-json-schema'))
@@ -58,50 +47,45 @@ describe('Test syndication feeds', () => {
     await doubleFollow(servers[0], servers[1])
 
     {
-      const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
-      const user: User = res.body
+      const user = await servers[0].usersCommand.getMyInfo()
       rootAccountId = user.account.id
       rootChannelId = user.videoChannels[0].id
     }
 
     {
       const attr = { username: 'john', password: 'password' }
-      await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
-      userAccessToken = await userLogin(servers[0], attr)
+      await servers[0].usersCommand.create({ username: attr.username, password: attr.password })
+      userAccessToken = await servers[0].loginCommand.getAccessToken(attr)
 
-      const res = await getMyUserInformation(servers[0].url, userAccessToken)
-      const user: User = res.body
+      const user = await servers[0].usersCommand.getMyInfo({ token: userAccessToken })
       userAccountId = user.account.id
       userChannelId = user.videoChannels[0].id
 
-      const res2 = await getUserScopedTokens(servers[0].url, userAccessToken)
-      const token: ScopedToken = res2.body
+      const token = await servers[0].usersCommand.getMyScopedTokens({ token: userAccessToken })
       userFeedToken = token.feedToken
     }
 
     {
-      await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' })
+      await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'user video' } })
     }
 
     {
-      const videoAttributes = {
+      const attributes = {
         name: 'my super name for server 1',
         description: 'my super description for server 1',
         fixture: 'video_short.webm'
       }
-      const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
-      const videoId = res.body.video.id
+      const { id } = await servers[0].videosCommand.upload({ attributes })
 
-      await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1')
-      await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
+      await servers[0].commentsCommand.createThread({ videoId: id, text: 'super comment 1' })
+      await servers[0].commentsCommand.createThread({ videoId: id, text: 'super comment 2' })
     }
 
     {
-      const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
-      const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
-      const videoId = res.body.video.id
+      const attributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
+      const { id } = await servers[0].videosCommand.upload({ attributes })
 
-      await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video')
+      await servers[0].commentsCommand.createThread({ videoId: id, text: 'comment on unlisted video' })
     }
 
     await waitJobs(servers)
@@ -230,7 +214,7 @@ describe('Test syndication feeds', () => {
     it('Should correctly have videos feed with HLS only', async function () {
       this.timeout(120000)
 
-      await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' })
+      await serverHLSOnly.videosCommand.upload({ attributes: { name: 'hls only video' } })
 
       await waitJobs([ serverHLSOnly ])
 
@@ -277,9 +261,9 @@ describe('Test syndication feeds', () => {
       await servers[1].blocklistCommand.removeFromServerBlocklist({ account: remoteHandle })
 
       {
-        const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
+        const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid
         await waitJobs(servers)
-        await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'super comment')
+        await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'super comment' })
         await waitJobs(servers)
 
         const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 3 } })
@@ -303,24 +287,22 @@ describe('Test syndication feeds', () => {
 
     it('Should list no videos for a user with no videos and no subscriptions', async function () {
       const attr = { username: 'feeduser', password: 'password' }
-      await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
-      const feeduserAccessToken = await userLogin(servers[0], attr)
+      await servers[0].usersCommand.create({ username: attr.username, password: attr.password })
+      const feeduserAccessToken = await servers[0].loginCommand.getAccessToken(attr)
 
       {
-        const res = await getMyUserInformation(servers[0].url, feeduserAccessToken)
-        const user: User = res.body
+        const user = await servers[0].usersCommand.getMyInfo({ token: feeduserAccessToken })
         feeduserAccountId = user.account.id
       }
 
       {
-        const res = await getUserScopedTokens(servers[0].url, feeduserAccessToken)
-        const token: ScopedToken = res.body
+        const token = await servers[0].usersCommand.getMyScopedTokens({ token: feeduserAccessToken })
         feeduserFeedToken = token.feedToken
       }
 
       {
-        const res = await listUserSubscriptionVideos(servers[0].url, feeduserAccessToken)
-        expect(res.body.total).to.equal(0)
+        const body = await servers[0].subscriptionsCommand.listVideos({ token: feeduserAccessToken })
+        expect(body.total).to.equal(0)
 
         const query = { accountId: feeduserAccountId, token: feeduserFeedToken }
         const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query })
@@ -340,8 +322,8 @@ describe('Test syndication feeds', () => {
     })
 
     it('Should list no videos for a user with videos but no subscriptions', async function () {
-      const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken)
-      expect(res.body.total).to.equal(0)
+      const body = await servers[0].subscriptionsCommand.listVideos({ token: userAccessToken })
+      expect(body.total).to.equal(0)
 
       const query = { accountId: userAccountId, token: userFeedToken }
       const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query })
@@ -352,13 +334,13 @@ describe('Test syndication feeds', () => {
     it('Should list self videos for a user with a subscription to themselves', async function () {
       this.timeout(30000)
 
-      await addUserSubscription(servers[0].url, userAccessToken, 'john_channel@localhost:' + servers[0].port)
+      await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'john_channel@localhost:' + servers[0].port })
       await waitJobs(servers)
 
       {
-        const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken)
-        expect(res.body.total).to.equal(1)
-        expect(res.body.data[0].name).to.equal('user video')
+        const body = await servers[0].subscriptionsCommand.listVideos({ token: userAccessToken })
+        expect(body.total).to.equal(1)
+        expect(body.data[0].name).to.equal('user video')
 
         const query = { accountId: userAccountId, token: userFeedToken, version: 1 }
         const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query })
@@ -370,12 +352,12 @@ describe('Test syndication feeds', () => {
     it('Should list videos of a user\'s subscription', async function () {
       this.timeout(30000)
 
-      await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port)
+      await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
       await waitJobs(servers)
 
       {
-        const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken)
-        expect(res.body.total).to.equal(2, "there should be 2 videos part of the subscription")
+        const body = await servers[0].subscriptionsCommand.listVideos({ token: userAccessToken })
+        expect(body.total).to.equal(2, "there should be 2 videos part of the subscription")
 
         const query = { accountId: userAccountId, token: userFeedToken, version: 2 }
         const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query })
@@ -385,15 +367,14 @@ describe('Test syndication feeds', () => {
     })
 
     it('Should renew the token, and so have an invalid old token', async function () {
-      await renewUserScopedTokens(servers[0].url, userAccessToken)
+      await servers[0].usersCommand.renewMyScopedTokens({ token: userAccessToken })
 
       const query = { accountId: userAccountId, token: userFeedToken, version: 3 }
       await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
     })
 
     it('Should succeed with the new token', async function () {
-      const res2 = await getUserScopedTokens(servers[0].url, userAccessToken)
-      const token: ScopedToken = res2.body
+      const token = await servers[0].usersCommand.getMyScopedTokens({ token: userAccessToken })
       userFeedToken = token.feedToken
 
       const query = { accountId: userAccountId, token: userFeedToken, version: 4 }