]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/plugins/filter-hooks.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / filter-hooks.ts
index 37eef6cf36385536107853cf990bde8c733bd513..a02a53c5049afafc91540bd290e5d2861e3cce71 100644 (file)
@@ -14,6 +14,7 @@ import {
   cleanupTests,
   createMultipleServers,
   doubleFollow,
+  makeActivityPubGetRequest,
   makeGetRequest,
   makeRawRequest,
   PeerTubeServer,
@@ -31,7 +32,7 @@ describe('Test plugin filter hooks', function () {
   let videoPlaylistUUID: string
 
   before(async function () {
-    this.timeout(60000)
+    this.timeout(120000)
 
     servers = await createMultipleServers(2)
     await setAccessTokensToServers(servers)
@@ -71,6 +72,9 @@ describe('Test plugin filter hooks', function () {
         }
       }
     })
+
+    // Root subscribes to itself
+    await servers[0].subscriptions.add({ targetUri: 'root_channel@' + servers[0].host })
   })
 
   describe('Videos', function () {
@@ -151,6 +155,20 @@ describe('Test plugin filter hooks', function () {
       expect(total).to.equal(14)
     })
 
+    it('Should run filter:api.user.me.subscription-videos.list.params', async function () {
+      const { data } = await servers[0].videos.listMySubscriptionVideos({ start: 0, count: 2 })
+
+      // 1 plugin do +1 to the count parameter
+      expect(data).to.have.lengthOf(3)
+    })
+
+    it('Should run filter:api.user.me.subscription-videos.list.result', async function () {
+      const { total } = await servers[0].videos.listMySubscriptionVideos({ start: 0, count: 2 })
+
+      // Plugin do +4 to the total result
+      expect(total).to.equal(14)
+    })
+
     it('Should run filter:api.video.get.result', async function () {
       const video = await servers[0].videos.get({ id: videoUUID })
       expect(video.name).to.contain('<3')
@@ -587,6 +605,27 @@ describe('Test plugin filter hooks', function () {
     })
   })
 
+  describe('Client HTML filters', function () {
+    let videoUUID: string
+
+    before(async function () {
+      this.timeout(60000)
+
+      const { uuid } = await servers[0].videos.quickUpload({ name: 'html video' })
+      videoUUID = uuid
+    })
+
+    it('Should run filter:html.client.json-ld.result', async function () {
+      const res = await makeGetRequest({ url: servers[0].url, path: '/w/' + videoUUID, expectedStatus: HttpStatusCode.OK_200 })
+      expect(res.text).to.contain('"recordedAt":"http://example.com/recordedAt"')
+    })
+
+    it('Should not run filter:html.client.json-ld.result with an account', async function () {
+      const res = await makeGetRequest({ url: servers[0].url, path: '/a/root', expectedStatus: HttpStatusCode.OK_200 })
+      expect(res.text).not.to.contain('"recordedAt":"http://example.com/recordedAt"')
+    })
+  })
+
   describe('Search filters', function () {
 
     before(async function () {
@@ -829,6 +868,24 @@ describe('Test plugin filter hooks', function () {
     })
   })
 
+  describe('Activity Pub', function () {
+
+    it('Should run filter:activity-pub.activity.context.build.result', async function () {
+      const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID)
+      expect(body.type).to.equal('Video')
+
+      expect(body['@context'].some(c => {
+        return typeof c === 'object' && c.recordedAt === 'https://schema.org/recordedAt'
+      })).to.be.true
+    })
+
+    it('Should run filter:activity-pub.video.json-ld.build.result', async function () {
+      const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID)
+      expect(body.name).to.equal('default video 0')
+      expect(body.videoName).to.equal('default video 0')
+    })
+  })
+
   after(async function () {
     await cleanupTests(servers)
   })