1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { FIXTURE_URLS } from '@server/tests/shared'
5 import { areHttpImportTestsDisabled } from '@shared/core-utils'
10 setAccessTokensToServers,
11 setDefaultVideoChannel,
13 } from '@shared/server-commands'
15 describe('Test videos import in a channel', function () {
16 if (areHttpImportTestsDisabled()) return
18 function runSuite (mode: 'youtube-dl' | 'yt-dlp') {
20 describe('Import using ' + mode, function () {
21 let server: PeerTubeServer
23 before(async function () {
26 server = await createSingleServer(1, getServerImportConfig(mode))
28 await setAccessTokensToServers([ server ])
29 await setDefaultVideoChannel([ server ])
31 await server.config.enableChannelSync()
34 it('Should import a whole channel without specifying the sync id', async function () {
37 await server.channels.importVideos({ channelName: server.store.channel.name, externalChannelUrl: FIXTURE_URLS.youtubeChannel })
38 await waitJobs(server)
40 const videos = await server.videos.listByChannel({ handle: server.store.channel.name })
41 expect(videos.total).to.equal(2)
44 it('These imports should not have a sync id', async function () {
45 const { total, data } = await server.imports.getMyVideoImports()
47 expect(total).to.equal(2)
48 expect(data).to.have.lengthOf(2)
50 for (const videoImport of data) {
51 expect(videoImport.videoChannelSync).to.not.exist
55 it('Should import a whole channel and specifying the sync id', async function () {
59 server.store.channel.name = 'channel2'
60 const { id } = await server.channels.create({ attributes: { name: server.store.channel.name } })
61 server.store.channel.id = id
66 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
67 videoChannelId: server.store.channel.id
70 const { videoChannelSync } = await server.channelSyncs.create({ attributes })
71 server.store.videoChannelSync = videoChannelSync
73 await waitJobs(server)
76 await server.channels.importVideos({
77 channelName: server.store.channel.name,
78 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
79 videoChannelSyncId: server.store.videoChannelSync.id
82 await waitJobs(server)
85 it('These imports should have a sync id', async function () {
86 const { total, data } = await server.imports.getMyVideoImports()
88 expect(total).to.equal(4)
89 expect(data).to.have.lengthOf(4)
91 const importsWithSyncId = data.filter(i => !!i.videoChannelSync)
92 expect(importsWithSyncId).to.have.lengthOf(2)
94 for (const videoImport of importsWithSyncId) {
95 expect(videoImport.videoChannelSync).to.exist
96 expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
100 it('Should be able to filter imports by this sync id', async function () {
101 const { total, data } = await server.imports.getMyVideoImports({ videoChannelSyncId: server.store.videoChannelSync.id })
103 expect(total).to.equal(2)
104 expect(data).to.have.lengthOf(2)
106 for (const videoImport of data) {
107 expect(videoImport.videoChannelSync).to.exist
108 expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
112 it('Should limit max amount of videos synced on full sync', async function () {
113 this.timeout(240_000)
118 video_channel_synchronization: {
119 full_sync_videos_limit: 1
124 const { id } = await server.channels.create({ attributes: { name: 'channel3' } })
125 const channel3Id = id
127 const { videoChannelSync } = await server.channelSyncs.create({
129 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
130 videoChannelId: channel3Id
133 const syncId = videoChannelSync.id
135 await waitJobs(server)
137 await server.channels.importVideos({
138 channelName: 'channel3',
139 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
140 videoChannelSyncId: syncId
143 await waitJobs(server)
145 const { total, data } = await server.videos.listByChannel({ handle: 'channel3' })
147 expect(total).to.equal(1)
148 expect(data).to.have.lengthOf(1)
151 after(async function () {
159 // FIXME: With recent changes on youtube, youtube-dl doesn't fetch live replays which means the test suite fails
160 // runSuite('youtube-dl')