]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/channel-import-videos.ts
Add runner server tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / channel-import-videos.ts
index f7540e1ba1d25902aca1cb63e8d3f2da08add5ed..a66f88a0ec13f3777334f63c64d89322b32a6b51 100644 (file)
@@ -1,3 +1,5 @@
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+
 import { expect } from 'chai'
 import { FIXTURE_URLS } from '@server/tests/shared'
 import { areHttpImportTestsDisabled } from '@shared/core-utils'
@@ -29,7 +31,7 @@ describe('Test videos import in a channel', function () {
         await server.config.enableChannelSync()
       })
 
-      it('Should import a whole channel', async function () {
+      it('Should import a whole channel without specifying the sync id', async function () {
         this.timeout(240_000)
 
         await server.channels.importVideos({ channelName: server.store.channel.name, externalChannelUrl: FIXTURE_URLS.youtubeChannel })
@@ -39,6 +41,113 @@ describe('Test videos import in a channel', function () {
         expect(videos.total).to.equal(2)
       })
 
+      it('These imports should not have a sync id', async function () {
+        const { total, data } = await server.imports.getMyVideoImports()
+
+        expect(total).to.equal(2)
+        expect(data).to.have.lengthOf(2)
+
+        for (const videoImport of data) {
+          expect(videoImport.videoChannelSync).to.not.exist
+        }
+      })
+
+      it('Should import a whole channel and specifying the sync id', async function () {
+        this.timeout(240_000)
+
+        {
+          server.store.channel.name = 'channel2'
+          const { id } = await server.channels.create({ attributes: { name: server.store.channel.name } })
+          server.store.channel.id = id
+        }
+
+        {
+          const attributes = {
+            externalChannelUrl: FIXTURE_URLS.youtubeChannel,
+            videoChannelId: server.store.channel.id
+          }
+
+          const { videoChannelSync } = await server.channelSyncs.create({ attributes })
+          server.store.videoChannelSync = videoChannelSync
+
+          await waitJobs(server)
+        }
+
+        await server.channels.importVideos({
+          channelName: server.store.channel.name,
+          externalChannelUrl: FIXTURE_URLS.youtubeChannel,
+          videoChannelSyncId: server.store.videoChannelSync.id
+        })
+
+        await waitJobs(server)
+      })
+
+      it('These imports should have a sync id', async function () {
+        const { total, data } = await server.imports.getMyVideoImports()
+
+        expect(total).to.equal(4)
+        expect(data).to.have.lengthOf(4)
+
+        const importsWithSyncId = data.filter(i => !!i.videoChannelSync)
+        expect(importsWithSyncId).to.have.lengthOf(2)
+
+        for (const videoImport of importsWithSyncId) {
+          expect(videoImport.videoChannelSync).to.exist
+          expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
+        }
+      })
+
+      it('Should be able to filter imports by this sync id', async function () {
+        const { total, data } = await server.imports.getMyVideoImports({ videoChannelSyncId: server.store.videoChannelSync.id })
+
+        expect(total).to.equal(2)
+        expect(data).to.have.lengthOf(2)
+
+        for (const videoImport of data) {
+          expect(videoImport.videoChannelSync).to.exist
+          expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
+        }
+      })
+
+      it('Should limit max amount of videos synced on full sync', async function () {
+        this.timeout(240_000)
+
+        await server.kill()
+        await server.run({
+          import: {
+            video_channel_synchronization: {
+              full_sync_videos_limit: 1
+            }
+          }
+        })
+
+        const { id } = await server.channels.create({ attributes: { name: 'channel3' } })
+        const channel3Id = id
+
+        const { videoChannelSync } = await server.channelSyncs.create({
+          attributes: {
+            externalChannelUrl: FIXTURE_URLS.youtubeChannel,
+            videoChannelId: channel3Id
+          }
+        })
+        const syncId = videoChannelSync.id
+
+        await waitJobs(server)
+
+        await server.channels.importVideos({
+          channelName: 'channel3',
+          externalChannelUrl: FIXTURE_URLS.youtubeChannel,
+          videoChannelSyncId: syncId
+        })
+
+        await waitJobs(server)
+
+        const { total, data } = await server.videos.listByChannel({ handle: 'channel3' })
+
+        expect(total).to.equal(1)
+        expect(data).to.have.lengthOf(1)
+      })
+
       after(async function () {
         await server?.kill()
       })
@@ -46,5 +155,7 @@ describe('Test videos import in a channel', function () {
   }
 
   runSuite('yt-dlp')
-  runSuite('youtube-dl')
+
+  // FIXME: With recent changes on youtube, youtube-dl doesn't fetch live replays which means the test suite fails
+  // runSuite('youtube-dl')
 })