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',
24 let command: ChannelsCommand
26 // ---------------------------------------------------------------
28 before(async function () {
31 server = await createSingleServer(1)
33 await setAccessTokensToServers([ server ])
34 await setDefaultVideoChannel([ server ])
38 password: 'fake_password'
42 const user = await server.users.create({ username: userCreds.username, password: userCreds.password })
44 userInfo.accessToken = await server.login.getAccessToken(userCreds)
47 command = server.channels
50 it('Should fail when HTTP upload is disabled', async function () {
51 await server.config.disableImports()
53 await command.importVideos({
54 channelName: server.store.channel.name,
55 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
56 token: server.accessToken,
57 expectedStatus: HttpStatusCode.FORBIDDEN_403
60 await server.config.enableImports()
63 it('Should fail when externalChannelUrl is not provided', async function () {
64 await command.importVideos({
65 channelName: server.store.channel.name,
66 externalChannelUrl: null,
67 token: server.accessToken,
68 expectedStatus: HttpStatusCode.BAD_REQUEST_400
72 it('Should fail when externalChannelUrl is malformed', async function () {
73 await command.importVideos({
74 channelName: server.store.channel.name,
75 externalChannelUrl: 'not-a-url',
76 token: server.accessToken,
77 expectedStatus: HttpStatusCode.BAD_REQUEST_400
81 it('Should fail with a bad sync id', async function () {
82 await command.importVideos({
83 channelName: server.store.channel.name,
84 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
85 videoChannelSyncId: 'toto' as any,
86 token: server.accessToken,
87 expectedStatus: HttpStatusCode.BAD_REQUEST_400
91 it('Should fail with a unknown sync id', async function () {
92 await command.importVideos({
93 channelName: server.store.channel.name,
94 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
95 videoChannelSyncId: 42,
96 token: server.accessToken,
97 expectedStatus: HttpStatusCode.NOT_FOUND_404
101 it('Should fail with no authentication', async function () {
102 await command.importVideos({
103 channelName: server.store.channel.name,
104 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
106 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
110 it('Should fail when sync is not owned by the user', async function () {
111 await command.importVideos({
112 channelName: server.store.channel.name,
113 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
114 token: userInfo.accessToken,
115 expectedStatus: HttpStatusCode.FORBIDDEN_403
119 it('Should fail when the user has no quota', async function () {
120 await server.users.update({
125 await command.importVideos({
126 channelName: 'fake_channel',
127 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
128 token: userInfo.accessToken,
129 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
132 await server.users.update({
134 videoQuota: userInfo.videoQuota
138 it('Should fail when the user has no daily quota', async function () {
139 await server.users.update({
144 await command.importVideos({
145 channelName: 'fake_channel',
146 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
147 token: userInfo.accessToken,
148 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
151 await server.users.update({
153 videoQuotaDaily: userInfo.videoQuotaDaily
157 it('Should succeed when sync is run by its owner', async function () {
158 if (!areHttpImportTestsDisabled()) return
160 await command.importVideos({
161 channelName: 'fake_channel',
162 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
163 token: userInfo.accessToken
167 it('Should succeed when sync is run with root and for another user\'s channel', async function () {
168 if (!areHttpImportTestsDisabled()) return
170 await command.importVideos({
171 channelName: 'fake_channel',
172 externalChannelUrl: FIXTURE_URLS.youtubeChannel
176 after(async function () {
177 await cleanupTests([ server ])