]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/plugins/action-hooks.ts
Introduce live command
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / action-hooks.ts
index ca57a4b518f71f1a12fe3b78f5ab898db507f4bb..39266c62f4d5fb8bd887dabd269bdfbe404e9ea3 100644 (file)
@@ -1,25 +1,20 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
-import {
-  cleanupTests,
-  flushAndRunMultipleServers,
-  killallServers,
-  reRunServer,
-  ServerInfo,
-  waitUntilLog
-} from '../../../shared/extra-utils/server/servers'
+import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
 import {
   addVideoCommentReply,
   addVideoCommentThread,
+  addVideoInPlaylist,
   blockUser,
   createUser,
+  createVideoPlaylist,
   deleteVideoComment,
-  getPluginTestPath,
-  installPlugin,
+  PluginsCommand,
   registerUser,
   removeUser,
   setAccessTokensToServers,
+  setDefaultVideoChannel,
   unblockUser,
   updateUser,
   updateVideo,
@@ -27,13 +22,21 @@ import {
   userLogin,
   viewVideo
 } from '../../../shared/extra-utils'
+import {
+  cleanupTests,
+  flushAndRunMultipleServers,
+  killallServers,
+  reRunServer,
+  ServerInfo,
+  waitUntilLog
+} from '../../../shared/extra-utils/server/servers'
 
 describe('Test plugin action hooks', function () {
   let servers: ServerInfo[]
   let videoUUID: string
   let threadId: number
 
-  function checkHook (hook: string) {
+  function checkHook (hook: ServerHookName) {
     return waitUntilLog(servers[0], 'Run hook ' + hook)
   }
 
@@ -42,16 +45,17 @@ describe('Test plugin action hooks', function () {
 
     servers = await flushAndRunMultipleServers(2)
     await setAccessTokensToServers(servers)
+    await setDefaultVideoChannel(servers)
 
-    await installPlugin({
-      url: servers[0].url,
-      accessToken: servers[0].accessToken,
-      path: getPluginTestPath()
-    })
+    await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })
 
     killallServers([ servers[0] ])
 
-    await reRunServer(servers[0])
+    await reRunServer(servers[0], {
+      live: {
+        enabled: true
+      }
+    })
   })
 
   describe('Application hooks', function () {
@@ -61,6 +65,7 @@ describe('Test plugin action hooks', function () {
   })
 
   describe('Videos hooks', function () {
+
     it('Should run action:api.video.uploaded', async function () {
       const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
       videoUUID = res.body.video.uuid
@@ -81,6 +86,21 @@ describe('Test plugin action hooks', function () {
     })
   })
 
+  describe('Live hooks', function () {
+
+    it('Should run action:api.live-video.created', async function () {
+      const attributes = {
+        name: 'live',
+        privacy: VideoPrivacy.PUBLIC,
+        channelId: servers[0].videoChannel.id
+      }
+
+      await servers[0].liveCommand.createLive({ fields: attributes })
+
+      await checkHook('action:api.live-video.created')
+    })
+  })
+
   describe('Comments hooks', function () {
     it('Should run action:api.video-thread.created', async function () {
       const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
@@ -154,6 +174,41 @@ describe('Test plugin action hooks', function () {
     })
   })
 
+  describe('Playlist hooks', function () {
+    let playlistId: number
+    let videoId: number
+
+    before(async function () {
+      {
+        const res = await createVideoPlaylist({
+          url: servers[0].url,
+          token: servers[0].accessToken,
+          playlistAttrs: {
+            displayName: 'My playlist',
+            privacy: VideoPlaylistPrivacy.PRIVATE
+          }
+        })
+        playlistId = res.body.videoPlaylist.id
+      }
+
+      {
+        const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
+        videoId = res.body.video.id
+      }
+    })
+
+    it('Should run action:api.video-playlist-element.created', async function () {
+      await addVideoInPlaylist({
+        url: servers[0].url,
+        token: servers[0].accessToken,
+        playlistId,
+        elementAttrs: { videoId }
+      })
+
+      await checkHook('action:api.video-playlist-element.created')
+    })
+  })
+
   after(async function () {
     await cleanupTests(servers)
   })