]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/activitypub/refresher.ts
Add runner server tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / refresher.ts
index 921ee874c7e9893b2f955c6cd1f561bdc7a06746..6c48b7ac8d312613520a27478e51a25cfd1ab777 100644 (file)
@@ -1,32 +1,22 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
+import { SQLCommand } from '@server/tests/shared'
+import { wait } from '@shared/core-utils'
+import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
 import {
-  cleanupTests, closeAllSequelize,
-  createVideoPlaylist,
+  cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  generateUserAccessToken,
-  getVideo,
-  getVideoPlaylist,
   killallServers,
-  reRunServer,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
-  setActorField,
   setDefaultVideoChannel,
-  setPlaylistField,
-  setVideoField,
-  uploadVideo,
-  uploadVideoAndGetId,
-  wait,
   waitJobs
-} from '../../../../shared/extra-utils'
-import { getAccount } from '../../../../shared/extra-utils/users/accounts'
-import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
+} from '@shared/server-commands'
 
 describe('Test AP refresher', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
+  let sqlCommandServer2: SQLCommand
   let videoUUID1: string
   let videoUUID2: string
   let videoUUID3: string
@@ -36,39 +26,45 @@ describe('Test AP refresher', function () {
   before(async function () {
     this.timeout(60000)
 
-    servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
+    servers = await createMultipleServers(2)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
     await setDefaultVideoChannel(servers)
 
+    for (const server of servers) {
+      await server.config.disableTranscoding()
+    }
+
     {
-      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 playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id }
-      const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs })
-      playlistUUID1 = res.body.videoPlaylist.uuid
+      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 playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id }
-      const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs })
-      playlistUUID2 = res.body.videoPlaylist.uuid
+      const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
+      const created = await servers[1].playlists.create({ attributes })
+      playlistUUID2 = created.uuid
     }
 
-    await doubleFollow(servers[ 0 ], servers[ 1 ])
+    await doubleFollow(servers[0], servers[1])
+
+    sqlCommandServer2 = new SQLCommand(servers[1])
   })
 
   describe('Videos refresher', function () {
@@ -79,38 +75,34 @@ describe('Test AP refresher', function () {
       await wait(10000)
 
       // Change UUID so the remote server returns a 404
-      await setVideoField(servers[ 1 ].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
+      await sqlCommandServer2.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, 404)
-      await getVideo(servers[ 0 ].url, videoUUID2, 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 () {
-      this.timeout(60000)
+      this.timeout(70000)
 
-      killallServers([ servers[ 1 ] ])
+      await killallServers([ servers[1] ])
 
-      await setVideoField(servers[ 1 ].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
+      await sqlCommandServer2.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 waitJobs([ servers[0] ])
 
-      await reRunServer(servers[ 1 ])
+      await servers[1].run()
 
-      // Should not refresh the video, even if the last refresh failed (to avoir a loop on dead instances)
-      await getVideo(servers[ 0 ].url, videoUUID3)
-      await waitJobs(servers)
-
-      await getVideo(servers[ 0 ].url, videoUUID3, 200)
+      await servers[0].videos.get({ id: videoUUID3 })
     })
   })
 
@@ -119,19 +111,21 @@ describe('Test AP refresher', function () {
     it('Should remove a deleted actor', async function () {
       this.timeout(60000)
 
+      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 setActorField(servers[ 1 ].internalServerNumber, to, 'preferredUsername', 'toto')
+      const to = servers[1].url + '/accounts/user2'
+      await sqlCommandServer2.setActorField(to, 'preferredUsername', 'toto')
 
-      await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port)
-      await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port)
+      await command.get({ accountName: 'user1@' + servers[1].host })
+      await command.get({ accountName: 'user2@' + servers[1].host })
 
       await waitJobs(servers)
 
-      await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port, 200)
-      await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port, 404)
+      await command.get({ accountName: 'user1@' + servers[1].host, expectedStatus: HttpStatusCode.OK_200 })
+      await command.get({ accountName: 'user2@' + servers[1].host, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
     })
   })
 
@@ -143,23 +137,23 @@ describe('Test AP refresher', function () {
       await wait(10000)
 
       // Change UUID so the remote server returns a 404
-      await setPlaylistField(servers[ 1 ].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
+      await sqlCommandServer2.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
 
-      await getVideoPlaylist(servers[ 0 ].url, playlistUUID1)
-      await getVideoPlaylist(servers[ 0 ].url, playlistUUID2)
+      await servers[0].playlists.get({ playlistId: playlistUUID1 })
+      await servers[0].playlists.get({ playlistId: playlistUUID2 })
 
       await waitJobs(servers)
 
-      await getVideoPlaylist(servers[ 0 ].url, playlistUUID1, 200)
-      await getVideoPlaylist(servers[ 0 ].url, playlistUUID2, 404)
+      await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
+      await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
     })
   })
 
   after(async function () {
     this.timeout(10000)
 
-    await cleanupTests(servers)
+    await sqlCommandServer2.cleanup()
 
-    await closeAllSequelize(servers)
+    await cleanupTests(servers)
   })
 })