]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/activitypub/refresher.ts
Merge branch 'release/3.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / refresher.ts
index af919f2f35d2f78d827ef056b38da9e1ea6484e8..81fee004471c2a348884f7271ecce2385443c8c6 100644 (file)
@@ -1,27 +1,21 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
-import { HttpStatusCode } from '@shared/core-utils'
 import {
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  generateUserAccessToken,
-  getVideo,
   killallServers,
-  reRunServer,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
-  uploadVideo,
-  uploadVideoAndGetId,
   wait,
   waitJobs
 } from '@shared/extra-utils'
-import { VideoPlaylistPrivacy } from '@shared/models'
+import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
 
 describe('Test AP refresher', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   let videoUUID1: string
   let videoUUID2: string
   let videoUUID3: string
@@ -31,35 +25,35 @@ describe('Test AP refresher', function () {
   before(async function () {
     this.timeout(60000)
 
-    servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
+    servers = await createMultipleServers(2, { transcoding: { enabled: false } })
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
     await setDefaultVideoChannel(servers)
 
     {
-      videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid
-      videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid
-      videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid
+      videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
+      videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
+      videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
     }
 
     {
-      const a1 = await generateUserAccessToken(servers[1], 'user1')
-      await uploadVideo(servers[1].url, a1, { name: 'video4' })
+      const token1 = await servers[1].users.generateUserAndToken('user1')
+      await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
 
-      const a2 = await generateUserAccessToken(servers[1], 'user2')
-      await uploadVideo(servers[1].url, a2, { name: 'video5' })
+      const token2 = await servers[1].users.generateUserAndToken('user2')
+      await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
     }
 
     {
-      const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
-      const created = await servers[1].playlistsCommand.create({ attributes })
+      const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
+      const created = await servers[1].playlists.create({ attributes })
       playlistUUID1 = created.uuid
     }
 
     {
-      const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
-      const created = await servers[1].playlistsCommand.create({ attributes })
+      const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
+      const created = await servers[1].playlists.create({ attributes })
       playlistUUID2 = created.uuid
     }
 
@@ -74,15 +68,15 @@ describe('Test AP refresher', function () {
       await wait(10000)
 
       // Change UUID so the remote server returns a 404
-      await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
+      await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
 
-      await getVideo(servers[0].url, videoUUID1)
-      await getVideo(servers[0].url, videoUUID2)
+      await servers[0].videos.get({ id: videoUUID1 })
+      await servers[0].videos.get({ id: videoUUID2 })
 
       await waitJobs(servers)
 
-      await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
-      await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
+      await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
+      await servers[0].videos.get({ id: videoUUID2 })
     })
 
     it('Should not update a remote video if the remote instance is down', async function () {
@@ -90,18 +84,18 @@ describe('Test AP refresher', function () {
 
       await killallServers([ servers[1] ])
 
-      await servers[1].sqlCommand.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
+      await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
 
       // Video will need a refresh
       await wait(10000)
 
-      await getVideo(servers[0].url, videoUUID3)
+      await servers[0].videos.get({ id: videoUUID3 })
       // The refresh should fail
       await waitJobs([ servers[0] ])
 
-      await reRunServer(servers[1])
+      await servers[1].run()
 
-      await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
+      await servers[0].videos.get({ id: videoUUID3 })
     })
   })
 
@@ -110,13 +104,13 @@ describe('Test AP refresher', function () {
     it('Should remove a deleted actor', async function () {
       this.timeout(60000)
 
-      const command = servers[0].accountsCommand
+      const command = servers[0].accounts
 
       await wait(10000)
 
       // Change actor name so the remote server returns a 404
       const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
-      await servers[1].sqlCommand.setActorField(to, 'preferredUsername', 'toto')
+      await servers[1].sql.setActorField(to, 'preferredUsername', 'toto')
 
       await command.get({ accountName: 'user1@localhost:' + servers[1].port })
       await command.get({ accountName: 'user2@localhost:' + servers[1].port })
@@ -136,15 +130,15 @@ describe('Test AP refresher', function () {
       await wait(10000)
 
       // Change UUID so the remote server returns a 404
-      await servers[1].sqlCommand.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
+      await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
 
-      await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 })
-      await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 })
+      await servers[0].playlists.get({ playlistId: playlistUUID1 })
+      await servers[0].playlists.get({ playlistId: playlistUUID2 })
 
       await waitJobs(servers)
 
-      await servers[0].playlistsCommand.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
-      await servers[0].playlistsCommand.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
+      await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
+      await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
     })
   })