]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-channel-syncs.ts
Add runner server tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-channel-syncs.ts
index 5c0663311d059dd90651dcd25738fc6d497b21ec..a31e48d1d2524e2f93e1a643dd6a69bac1ae2a72 100644 (file)
@@ -1,9 +1,9 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import { expect } from 'chai'
-import { FIXTURE_URLS } from '@server/tests/shared'
+import { FIXTURE_URLS, SQLCommand } from '@server/tests/shared'
 import { areHttpImportTestsDisabled } from '@shared/core-utils'
-import { HttpStatusCode, VideoChannelSyncState, VideoInclude, VideoPrivacy } from '@shared/models'
+import { VideoChannelSyncState, VideoInclude, VideoPrivacy } from '@shared/models'
 import {
   createMultipleServers,
   getServerImportConfig,
@@ -23,6 +23,7 @@ describe('Test channel synchronizations', function () {
 
     describe('Sync using ' + mode, function () {
       let servers: PeerTubeServer[]
+      let sqlCommands: SQLCommand[]
 
       let startTestDate: Date
 
@@ -36,13 +37,32 @@ describe('Test channel synchronizations', function () {
       }
 
       async function changeDateForSync (channelSyncId: number, newDate: string) {
-        await servers[0].sql.updateQuery(
+        await sqlCommands[0].updateQuery(
           `UPDATE "videoChannelSync" ` +
           `SET "createdAt"='${newDate}', "lastSyncAt"='${newDate}' ` +
           `WHERE id=${channelSyncId}`
         )
       }
 
+      async function listAllVideosOfChannel (channelName: string) {
+        return servers[0].videos.listByChannel({
+          handle: channelName,
+          include: VideoInclude.NOT_PUBLISHED_STATE
+        })
+      }
+
+      async function forceSyncAll (videoChannelSyncId: number, fromDate = '1970-01-01') {
+        await changeDateForSync(videoChannelSyncId, fromDate)
+
+        await servers[0].debug.sendCommand({
+          body: {
+            command: 'process-video-channel-sync-latest'
+          }
+        })
+
+        await waitJobs(servers)
+      }
+
       before(async function () {
         this.timeout(240_000)
 
@@ -63,6 +83,8 @@ describe('Test channel synchronizations', function () {
           const { videoChannels } = await servers[0].users.getMyInfo({ token: userInfo.accessToken })
           userInfo.channelId = videoChannels[0].id
         }
+
+        sqlCommands = servers.map(s => new SQLCommand(s))
       })
 
       it('Should fetch the latest channel videos of a remote channel', async function () {
@@ -80,7 +102,7 @@ describe('Test channel synchronizations', function () {
           expect(video.name).to.equal('small video - youtube')
           expect(video.waitTranscoding).to.be.true
 
-          const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', include: VideoInclude.NOT_PUBLISHED_STATE })
+          const { total } = await listAllVideosOfChannel('root_channel')
           expect(total).to.equal(1)
         }
 
@@ -88,28 +110,14 @@ describe('Test channel synchronizations', function () {
           attributes: {
             externalChannelUrl: FIXTURE_URLS.youtubeChannel,
             videoChannelId: servers[0].store.channel.id
-          },
-          token: servers[0].accessToken,
-          expectedStatus: HttpStatusCode.OK_200
+          }
         })
         rootChannelSyncId = videoChannelSync.id
 
-        // Ensure any missing video not already fetched will be considered as new
-        await changeDateForSync(videoChannelSync.id, '1970-01-01')
-
-        await servers[0].debug.sendCommand({
-          body: {
-            command: 'process-video-channel-sync-latest'
-          }
-        })
+        await forceSyncAll(rootChannelSyncId)
 
         {
-          await waitJobs(servers)
-
-          const { total, data } = await servers[0].videos.listByChannel({
-            handle: 'root_channel',
-            include: VideoInclude.NOT_PUBLISHED_STATE
-          })
+          const { total, data } = await listAllVideosOfChannel('root_channel')
           expect(total).to.equal(2)
           expect(data[0].name).to.equal('test')
           expect(data[0].waitTranscoding).to.be.true
@@ -123,16 +131,12 @@ describe('Test channel synchronizations', function () {
           attributes: {
             externalChannelUrl,
             videoChannelId: servers[0].store.channel.id
-          },
-          token: servers[0].accessToken,
-          expectedStatus: HttpStatusCode.OK_200
+          }
         })
 
         expect(videoChannelSync.externalChannelUrl).to.equal(externalChannelUrl)
-        expect(videoChannelSync.channel).to.include({
-          id: servers[0].store.channel.id,
-          name: 'root_channel'
-        })
+        expect(videoChannelSync.channel.id).to.equal(servers[0].store.channel.id)
+        expect(videoChannelSync.channel.name).to.equal('root_channel')
         expect(videoChannelSync.state.id).to.equal(VideoChannelSyncState.WAITING_FIRST_RUN)
         expect(new Date(videoChannelSync.createdAt)).to.be.above(startTestDate).and.to.be.at.most(new Date())
       })
@@ -162,20 +166,9 @@ describe('Test channel synchronizations', function () {
       it('Should only fetch the videos newer than the creation date', async function () {
         this.timeout(120_000)
 
-        await changeDateForSync(userInfo.syncId, '2019-03-01')
-
-        await servers[0].debug.sendCommand({
-          body: {
-            command: 'process-video-channel-sync-latest'
-          }
-        })
+        await forceSyncAll(userInfo.syncId, '2019-03-01')
 
-        await waitJobs(servers)
-
-        const { data, total } = await servers[0].videos.listByChannel({
-          handle: userInfo.channelName,
-          include: VideoInclude.NOT_PUBLISHED_STATE
-        })
+        const { data, total } = await listAllVideosOfChannel(userInfo.channelName)
 
         expect(total).to.equal(1)
         expect(data[0].name).to.equal('test')
@@ -230,7 +223,7 @@ describe('Test channel synchronizations', function () {
         expect(total).to.equal(0)
       })
 
-      // FIXME: youtube-dl doesn't work when speicifying a port after the hostname
+      // FIXME: youtube-dl/yt-dlp doesn't work when speicifying a port after the hostname
       // it('Should import a remote PeerTube channel', async function () {
       //   this.timeout(240_000)
 
@@ -284,12 +277,44 @@ describe('Test channel synchronizations', function () {
       //   expect(data[0].name).to.equal('remote 2')
       // })
 
+      it('Should fetch the latest videos of a youtube playlist', async function () {
+        this.timeout(120_000)
+
+        const { id: channelId } = await servers[0].channels.create({
+          attributes: {
+            name: 'channel2'
+          }
+        })
+
+        const { videoChannelSync: { id: videoChannelSyncId } } = await servers[0].channelSyncs.create({
+          attributes: {
+            externalChannelUrl: FIXTURE_URLS.youtubePlaylist,
+            videoChannelId: channelId
+          }
+        })
+
+        await forceSyncAll(videoChannelSyncId)
+
+        {
+
+          const { total, data } = await listAllVideosOfChannel('channel2')
+          expect(total).to.equal(2)
+          expect(data[0].name).to.equal('test')
+          expect(data[1].name).to.equal('small video - youtube')
+        }
+      })
+
       after(async function () {
+        for (const sqlCommand of sqlCommands) {
+          await sqlCommand.cleanup()
+        }
+
         await killallServers(servers)
       })
     })
   }
 
-  runSuite('youtube-dl')
+  // FIXME: suite is broken with youtube-dl
+  // runSuite('youtube-dl')
   runSuite('yt-dlp')
 })