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'
7 import { ChannelsCommand, cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
9 describe('Test videos import in a channel API validator', function () {
10 let server: PeerTubeServer
13 channelName: 'fake_channel',
18 let command: ChannelsCommand
20 // ---------------------------------------------------------------
22 before(async function () {
25 server = await createSingleServer(1)
27 await setAccessTokensToServers([ server ])
31 password: 'fake_password'
35 const user = await server.users.create({ username: userCreds.username, password: userCreds.password })
37 userInfo.accessToken = await server.login.getAccessToken(userCreds)
40 command = server.channels
43 it('Should fail when HTTP upload is disabled', async function () {
44 await server.config.disableImports()
46 await command.importVideos({
47 channelName: 'super_channel',
48 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
49 token: server.accessToken,
50 expectedStatus: HttpStatusCode.FORBIDDEN_403
53 await server.config.enableImports()
56 it('Should fail when externalChannelUrl is not provided', async function () {
57 await command.importVideos({
58 channelName: 'super_channel',
59 externalChannelUrl: null,
60 token: server.accessToken,
61 expectedStatus: HttpStatusCode.BAD_REQUEST_400
65 it('Should fail when externalChannelUrl is malformed', async function () {
66 await command.importVideos({
67 channelName: 'super_channel',
68 externalChannelUrl: 'not-a-url',
69 token: server.accessToken,
70 expectedStatus: HttpStatusCode.BAD_REQUEST_400
74 it('Should fail with a bad sync id', async function () {
75 await command.importVideos({
76 channelName: 'super_channel',
77 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
78 videoChannelSyncId: 'toto' as any,
79 token: server.accessToken,
80 expectedStatus: HttpStatusCode.BAD_REQUEST_400
84 it('Should fail with a unknown sync id', async function () {
85 await command.importVideos({
86 channelName: 'super_channel',
87 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
88 videoChannelSyncId: 42,
89 token: server.accessToken,
90 expectedStatus: HttpStatusCode.NOT_FOUND_404
94 it('Should fail with no authentication', async function () {
95 await command.importVideos({
96 channelName: 'super_channel',
97 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
99 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
103 it('Should fail when sync is not owned by the user', async function () {
104 await command.importVideos({
105 channelName: 'super_channel',
106 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
107 token: userInfo.accessToken,
108 expectedStatus: HttpStatusCode.FORBIDDEN_403
112 it('Should fail when the user has no quota', async function () {
113 await server.users.update({
118 await command.importVideos({
119 channelName: 'fake_channel',
120 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
121 token: userInfo.accessToken,
122 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
125 await server.users.update({
127 videoQuota: userInfo.videoQuota
131 it('Should fail when the user has no daily quota', async function () {
132 await server.users.update({
137 await command.importVideos({
138 channelName: 'fake_channel',
139 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
140 token: userInfo.accessToken,
141 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
144 await server.users.update({
146 videoQuotaDaily: userInfo.videoQuotaDaily
150 it('Should succeed when sync is run by its owner', async function () {
151 if (!areHttpImportTestsDisabled()) return
153 await command.importVideos({
154 channelName: 'fake_channel',
155 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
156 token: userInfo.accessToken
160 it('Should succeed when sync is run with root and for another user\'s channel', async function () {
161 if (!areHttpImportTestsDisabled()) return
163 await command.importVideos({
164 channelName: 'fake_channel',
165 externalChannelUrl: FIXTURE_URLS.youtubeChannel
169 after(async function () {
170 await cleanupTests([ server ])