]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/channel-import-videos.ts
Improve wait transcoding help
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / channel-import-videos.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { FIXTURE_URLS } from '@server/tests/shared'
5 import { areHttpImportTestsDisabled } from '@shared/core-utils'
6 import { HttpStatusCode } from '@shared/models'
7 import {
8 ChannelsCommand,
9 cleanupTests,
10 createSingleServer,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 setDefaultVideoChannel
14 } from '@shared/server-commands'
15
16 describe('Test videos import in a channel API validator', function () {
17 let server: PeerTubeServer
18 const userInfo = {
19 accessToken: '',
20 channelName: 'fake_channel',
21 id: -1,
22 videoQuota: -1,
23 videoQuotaDaily: -1
24 }
25 let command: ChannelsCommand
26
27 // ---------------------------------------------------------------
28
29 before(async function () {
30 this.timeout(30000)
31
32 server = await createSingleServer(1)
33
34 await setAccessTokensToServers([ server ])
35 await setDefaultVideoChannel([ server ])
36
37 const userCreds = {
38 username: 'fake',
39 password: 'fake_password'
40 }
41
42 {
43 const user = await server.users.create({ username: userCreds.username, password: userCreds.password })
44 userInfo.id = user.id
45 userInfo.accessToken = await server.login.getAccessToken(userCreds)
46 }
47
48 command = server.channels
49 })
50
51 it('Should fail when HTTP upload is disabled', async function () {
52 await server.config.disableImports()
53
54 await command.importVideos({
55 channelName: server.store.channel.name,
56 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
57 token: server.accessToken,
58 expectedStatus: HttpStatusCode.FORBIDDEN_403
59 })
60
61 await server.config.enableImports()
62 })
63
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
70 })
71 })
72
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
79 })
80 })
81
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
89 })
90 })
91
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
99 })
100 })
101
102 it('Should fail with no authentication', async function () {
103 await command.importVideos({
104 channelName: server.store.channel.name,
105 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
106 token: null,
107 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
108 })
109 })
110
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
117 })
118 })
119
120 it('Should fail when the user has no quota', async function () {
121 await server.users.update({
122 userId: userInfo.id,
123 videoQuota: 0
124 })
125
126 await command.importVideos({
127 channelName: 'fake_channel',
128 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
129 token: userInfo.accessToken,
130 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
131 })
132
133 await server.users.update({
134 userId: userInfo.id,
135 videoQuota: userInfo.videoQuota
136 })
137 })
138
139 it('Should fail when the user has no daily quota', async function () {
140 await server.users.update({
141 userId: userInfo.id,
142 videoQuotaDaily: 0
143 })
144
145 await command.importVideos({
146 channelName: 'fake_channel',
147 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
148 token: userInfo.accessToken,
149 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
150 })
151
152 await server.users.update({
153 userId: userInfo.id,
154 videoQuotaDaily: userInfo.videoQuotaDaily
155 })
156 })
157
158 it('Should succeed when sync is run by its owner', async function () {
159 if (!areHttpImportTestsDisabled()) return
160
161 await command.importVideos({
162 channelName: 'fake_channel',
163 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
164 token: userInfo.accessToken
165 })
166 })
167
168 it('Should succeed when sync is run with root and for another user\'s channel', async function () {
169 if (!areHttpImportTestsDisabled()) return
170
171 await command.importVideos({
172 channelName: 'fake_channel',
173 externalChannelUrl: FIXTURE_URLS.youtubeChannel
174 })
175 })
176
177 after(async function () {
178 await cleanupTests([ server ])
179 })
180 })