1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { FIXTURE_URLS } from '@server/tests/shared'
4 import { areHttpImportTestsDisabled } from '@shared/core-utils'
5 import { HttpStatusCode } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel
13 } from '@shared/server-commands'
15 describe('Test videos import in a channel API validator', function () {
16 let server: PeerTubeServer
19 channelName: 'fake_channel',
26 let command: ChannelsCommand
28 // ---------------------------------------------------------------
30 before(async function () {
33 server = await createSingleServer(1)
35 await setAccessTokensToServers([ server ])
36 await setDefaultVideoChannel([ server ])
38 await server.config.enableImports()
39 await server.config.enableChannelSync()
43 password: 'fake_password'
47 const user = await server.users.create({ username: userCreds.username, password: userCreds.password })
49 userInfo.accessToken = await server.login.getAccessToken(userCreds)
51 const info = await server.users.getMyInfo({ token: userInfo.accessToken })
52 userInfo.channelId = info.videoChannels[0].id
56 const { videoChannelSync } = await server.channelSyncs.create({
57 token: userInfo.accessToken,
59 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
60 videoChannelId: userInfo.channelId
63 userInfo.channelSyncId = videoChannelSync.id
66 command = server.channels
69 it('Should fail when HTTP upload is disabled', async function () {
70 await server.config.disableChannelSync()
71 await server.config.disableImports()
73 await command.importVideos({
74 channelName: server.store.channel.name,
75 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
76 token: server.accessToken,
77 expectedStatus: HttpStatusCode.FORBIDDEN_403
80 await server.config.enableImports()
83 it('Should fail when externalChannelUrl is not provided', async function () {
84 await command.importVideos({
85 channelName: server.store.channel.name,
86 externalChannelUrl: null,
87 token: server.accessToken,
88 expectedStatus: HttpStatusCode.BAD_REQUEST_400
92 it('Should fail when externalChannelUrl is malformed', async function () {
93 await command.importVideos({
94 channelName: server.store.channel.name,
95 externalChannelUrl: 'not-a-url',
96 token: server.accessToken,
97 expectedStatus: HttpStatusCode.BAD_REQUEST_400
101 it('Should fail with a bad sync id', async function () {
102 await command.importVideos({
103 channelName: server.store.channel.name,
104 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
105 videoChannelSyncId: 'toto' as any,
106 token: server.accessToken,
107 expectedStatus: HttpStatusCode.BAD_REQUEST_400
111 it('Should fail with a unknown sync id', async function () {
112 await command.importVideos({
113 channelName: server.store.channel.name,
114 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
115 videoChannelSyncId: 42,
116 token: server.accessToken,
117 expectedStatus: HttpStatusCode.NOT_FOUND_404
121 it('Should fail with a sync id of another channel', async function () {
122 await command.importVideos({
123 channelName: server.store.channel.name,
124 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
125 videoChannelSyncId: userInfo.channelSyncId,
126 token: server.accessToken,
127 expectedStatus: HttpStatusCode.FORBIDDEN_403
131 it('Should fail with no authentication', async function () {
132 await command.importVideos({
133 channelName: server.store.channel.name,
134 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
136 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
140 it('Should fail when sync is not owned by the user', async function () {
141 await command.importVideos({
142 channelName: server.store.channel.name,
143 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
144 token: userInfo.accessToken,
145 expectedStatus: HttpStatusCode.FORBIDDEN_403
149 it('Should fail when the user has no quota', async function () {
150 await server.users.update({
155 await command.importVideos({
156 channelName: 'fake_channel',
157 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
158 token: userInfo.accessToken,
159 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
162 await server.users.update({
164 videoQuota: userInfo.videoQuota
168 it('Should fail when the user has no daily quota', async function () {
169 await server.users.update({
174 await command.importVideos({
175 channelName: 'fake_channel',
176 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
177 token: userInfo.accessToken,
178 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
181 await server.users.update({
183 videoQuotaDaily: userInfo.videoQuotaDaily
187 it('Should succeed when sync is run by its owner', async function () {
188 if (!areHttpImportTestsDisabled()) return
190 await command.importVideos({
191 channelName: 'fake_channel',
192 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
193 token: userInfo.accessToken
197 it('Should succeed when sync is run with root and for another user\'s channel', async function () {
198 if (!areHttpImportTestsDisabled()) return
200 await command.importVideos({
201 channelName: 'fake_channel',
202 externalChannelUrl: FIXTURE_URLS.youtubeChannel
206 after(async function () {
207 await cleanupTests([ server ])