]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/activitypub/refresher.ts
Introduce playlist command
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / refresher.ts
index 9be9aa495b42b8e35009410e75a3163b0008736f..f295dfab76a4e879d52e90fa5e8d93740e679971 100644 (file)
@@ -1,14 +1,15 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
+import { HttpStatusCode } from '@shared/core-utils'
 import {
-  createVideoPlaylist,
+  cleanupTests,
+  closeAllSequelize,
   doubleFollow,
   flushAndRunMultipleServers,
   generateUserAccessToken,
   getVideo,
-  getVideoPlaylist,
-  killallServers, rateVideo,
+  killallServers,
   reRunServer,
   ServerInfo,
   setAccessTokensToServers,
@@ -20,9 +21,8 @@ import {
   uploadVideoAndGetId,
   wait,
   waitJobs
-} from '../../../../shared/extra-utils'
-import { getAccount } from '../../../../shared/extra-utils/users/accounts'
-import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
+} from '@shared/extra-utils'
+import { VideoPlaylistPrivacy } from '@shared/models'
 
 describe('Test AP refresher', function () {
   let servers: ServerInfo[] = []
@@ -42,9 +42,9 @@ describe('Test AP refresher', function () {
     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 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
     }
 
     {
@@ -56,15 +56,15 @@ describe('Test AP refresher', function () {
     }
 
     {
-      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].videoChannel.id }
+      const created = await servers[1].playlistsCommand.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].videoChannel.id }
+      const created = await servers[1].playlistsCommand.create({ attributes })
+      playlistUUID2 = created.uuid
     }
 
     await doubleFollow(servers[0], servers[1])
@@ -78,38 +78,34 @@ describe('Test AP refresher', function () {
       await wait(10000)
 
       // Change UUID so the remote server returns a 404
-      await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
+      await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
 
-      await getVideo(servers[ 0 ].url, videoUUID1)
-      await getVideo(servers[ 0 ].url, videoUUID2)
+      await getVideo(servers[0].url, videoUUID1)
+      await getVideo(servers[0].url, videoUUID2)
 
       await waitJobs(servers)
 
-      await getVideo(servers[ 0 ].url, videoUUID1, 404)
-      await getVideo(servers[ 0 ].url, videoUUID2, 200)
+      await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404)
+      await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200)
     })
 
     it('Should not update a remote video if the remote instance is down', async function () {
-      this.timeout(60000)
+      this.timeout(70000)
 
-      killallServers([ servers[ 1 ] ])
+      killallServers([ servers[1] ])
 
-      await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
+      await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
 
       // Video will need a refresh
       await wait(10000)
 
-      await getVideo(servers[ 0 ].url, videoUUID3)
+      await getVideo(servers[0].url, videoUUID3)
       // The refresh should fail
-      await waitJobs([ servers[ 0 ] ])
-
-      await reRunServer(servers[ 1 ])
+      await waitJobs([ servers[0] ])
 
-      // 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 reRunServer(servers[1])
 
-      await getVideo(servers[ 0 ].url, videoUUID3, 200)
+      await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200)
     })
   })
 
@@ -118,18 +114,21 @@ describe('Test AP refresher', function () {
     it('Should remove a deleted actor', async function () {
       this.timeout(60000)
 
+      const command = servers[0].accountsCommand
+
       await wait(10000)
 
       // Change actor name so the remote server returns a 404
-      await setActorField(2, 'http://localhost:9002/accounts/user2', 'preferredUsername', 'toto')
+      const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
+      await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto')
 
-      await getAccount(servers[ 0 ].url, 'user1@localhost:9002')
-      await getAccount(servers[ 0 ].url, 'user2@localhost:9002')
+      await command.get({ accountName: 'user1@localhost:' + servers[1].port })
+      await command.get({ accountName: 'user2@localhost:' + servers[1].port })
 
       await waitJobs(servers)
 
-      await getAccount(servers[ 0 ].url, 'user1@localhost:9002', 200)
-      await getAccount(servers[ 0 ].url, 'user2@localhost:9002', 404)
+      await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
+      await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
     })
   })
 
@@ -141,19 +140,23 @@ describe('Test AP refresher', function () {
       await wait(10000)
 
       // Change UUID so the remote server returns a 404
-      await setPlaylistField(2, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
+      await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
 
-      await getVideoPlaylist(servers[ 0 ].url, playlistUUID1)
-      await getVideoPlaylist(servers[ 0 ].url, playlistUUID2)
+      await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 })
+      await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 })
 
       await waitJobs(servers)
 
-      await getVideoPlaylist(servers[ 0 ].url, playlistUUID1, 200)
-      await getVideoPlaylist(servers[ 0 ].url, playlistUUID2, 404)
+      await servers[0].playlistsCommand.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
+      await servers[0].playlistsCommand.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
     })
   })
 
-  after(function () {
-    killallServers(servers)
+  after(async function () {
+    this.timeout(10000)
+
+    await cleanupTests(servers)
+
+    await closeAllSequelize(servers)
   })
 })