1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { FIXTURE_URLS } from '@server/tests/shared'
5 import { areHttpImportTestsDisabled } from '@shared/core-utils'
6 import { HttpStatusCode } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel
14 } from '@shared/server-commands'
16 describe('Test videos import in a channel API validator', function () {
17 let server: PeerTubeServer
20 channelName: 'fake_channel',
25 let command: ChannelsCommand
27 // ---------------------------------------------------------------
29 before(async function () {
32 server = await createSingleServer(1)
34 await setAccessTokensToServers([ server ])
35 await setDefaultVideoChannel([ server ])
39 password: 'fake_password'
43 const user = await server.users.create({ username: userCreds.username, password: userCreds.password })
45 userInfo.accessToken = await server.login.getAccessToken(userCreds)
48 command = server.channels
51 it('Should fail when HTTP upload is disabled', async function () {
52 await server.config.disableImports()
54 await command.importVideos({
55 channelName: server.store.channel.name,
56 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
57 token: server.accessToken,
58 expectedStatus: HttpStatusCode.FORBIDDEN_403
61 await server.config.enableImports()
64 it('Should fail when externalChannelUrl is not provided', async function () {
65 await command.importVideos({
66 channelName: server.store.channel.name,
67 externalChannelUrl: null,
68 token: server.accessToken,
69 expectedStatus: HttpStatusCode.BAD_REQUEST_400
73 it('Should fail when externalChannelUrl is malformed', async function () {
74 await command.importVideos({
75 channelName: server.store.channel.name,
76 externalChannelUrl: 'not-a-url',
77 token: server.accessToken,
78 expectedStatus: HttpStatusCode.BAD_REQUEST_400
82 it('Should fail with a bad sync id', async function () {
83 await command.importVideos({
84 channelName: server.store.channel.name,
85 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
86 videoChannelSyncId: 'toto' as any,
87 token: server.accessToken,
88 expectedStatus: HttpStatusCode.BAD_REQUEST_400
92 it('Should fail with a unknown sync id', async function () {
93 await command.importVideos({
94 channelName: server.store.channel.name,
95 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
96 videoChannelSyncId: 42,
97 token: server.accessToken,
98 expectedStatus: HttpStatusCode.NOT_FOUND_404
102 it('Should fail with no authentication', async function () {
103 await command.importVideos({
104 channelName: server.store.channel.name,
105 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
107 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
111 it('Should fail when sync is not owned by the user', async function () {
112 await command.importVideos({
113 channelName: server.store.channel.name,
114 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
115 token: userInfo.accessToken,
116 expectedStatus: HttpStatusCode.FORBIDDEN_403
120 it('Should fail when the user has no quota', async function () {
121 await server.users.update({
126 await command.importVideos({
127 channelName: 'fake_channel',
128 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
129 token: userInfo.accessToken,
130 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
133 await server.users.update({
135 videoQuota: userInfo.videoQuota
139 it('Should fail when the user has no daily quota', async function () {
140 await server.users.update({
145 await command.importVideos({
146 channelName: 'fake_channel',
147 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
148 token: userInfo.accessToken,
149 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
152 await server.users.update({
154 videoQuotaDaily: userInfo.videoQuotaDaily
158 it('Should succeed when sync is run by its owner', async function () {
159 if (!areHttpImportTestsDisabled()) return
161 await command.importVideos({
162 channelName: 'fake_channel',
163 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
164 token: userInfo.accessToken
168 it('Should succeed when sync is run with root and for another user\'s channel', async function () {
169 if (!areHttpImportTestsDisabled()) return
171 await command.importVideos({
172 channelName: 'fake_channel',
173 externalChannelUrl: FIXTURE_URLS.youtubeChannel
177 after(async function () {
178 await cleanupTests([ server ])