]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
5d08a6a7 C |
2 | |
3 | import { omit } from 'lodash' | |
4 | import 'mocha' | |
5 | import { join } from 'path' | |
6 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | |
7 | import { | |
7c3b7976 | 8 | cleanupTests, |
5d08a6a7 | 9 | createUser, |
7c3b7976 | 10 | flushAndRunServer, |
5d08a6a7 C |
11 | getMyUserInformation, |
12 | immutableAssign, | |
5d08a6a7 C |
13 | makeGetRequest, |
14 | makePostBodyRequest, | |
15 | makeUploadRequest, | |
5d08a6a7 C |
16 | ServerInfo, |
17 | setAccessTokensToServers, | |
590fb506 | 18 | updateCustomSubConfig, |
5d08a6a7 | 19 | userLogin |
94565d52 | 20 | } from '../../../../shared/extra-utils' |
9639bd17 | 21 | import { |
22 | checkBadCountPagination, | |
23 | checkBadSortPagination, | |
24 | checkBadStartPagination | |
94565d52 C |
25 | } from '../../../../shared/extra-utils/requests/check-api-params' |
26 | import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/extra-utils/videos/video-imports' | |
5d08a6a7 C |
27 | |
28 | describe('Test video imports API validator', function () { | |
29 | const path = '/api/v1/videos/imports' | |
30 | let server: ServerInfo | |
31 | let userAccessToken = '' | |
a1587156 | 32 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
5d08a6a7 C |
33 | let accountName: string |
34 | let channelId: number | |
5d08a6a7 C |
35 | |
36 | // --------------------------------------------------------------- | |
37 | ||
38 | before(async function () { | |
39 | this.timeout(30000) | |
40 | ||
210feb6c | 41 | server = await flushAndRunServer(1) |
5d08a6a7 C |
42 | |
43 | await setAccessTokensToServers([ server ]) | |
44 | ||
45 | const username = 'user1' | |
46 | const password = 'my super password' | |
1eddc9a7 | 47 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
5d08a6a7 C |
48 | userAccessToken = await userLogin(server, { username, password }) |
49 | ||
50 | { | |
51 | const res = await getMyUserInformation(server.url, server.accessToken) | |
a1587156 | 52 | channelId = res.body.videoChannels[0].id |
5d08a6a7 C |
53 | accountName = res.body.account.name + '@' + res.body.account.host |
54 | } | |
55 | }) | |
56 | ||
57 | describe('When listing my video imports', function () { | |
58 | const myPath = '/api/v1/users/me/videos/imports' | |
59 | ||
60 | it('Should fail with a bad start pagination', async function () { | |
61 | await checkBadStartPagination(server.url, myPath, server.accessToken) | |
62 | }) | |
63 | ||
64 | it('Should fail with a bad count pagination', async function () { | |
65 | await checkBadCountPagination(server.url, myPath, server.accessToken) | |
66 | }) | |
67 | ||
68 | it('Should fail with an incorrect sort', async function () { | |
69 | await checkBadSortPagination(server.url, myPath, server.accessToken) | |
70 | }) | |
71 | ||
72 | it('Should success with the correct parameters', async function () { | |
73 | await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken }) | |
74 | }) | |
75 | }) | |
76 | ||
77 | describe('When adding a video import', function () { | |
78 | let baseCorrectParams | |
79 | ||
80 | before(function () { | |
81 | baseCorrectParams = { | |
590fb506 | 82 | targetUrl: getYoutubeVideoUrl(), |
5d08a6a7 C |
83 | name: 'my super name', |
84 | category: 5, | |
85 | licence: 1, | |
86 | language: 'pt', | |
87 | nsfw: false, | |
88 | commentsEnabled: true, | |
7f2cfe3a | 89 | downloadEnabled: true, |
5d08a6a7 C |
90 | waitTranscoding: true, |
91 | description: 'my super description', | |
92 | support: 'my super support text', | |
93 | tags: [ 'tag1', 'tag2' ], | |
94 | privacy: VideoPrivacy.PUBLIC, | |
c8861d5d | 95 | channelId |
5d08a6a7 C |
96 | } |
97 | }) | |
98 | ||
99 | it('Should fail with nothing', async function () { | |
100 | const fields = {} | |
101 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
102 | }) | |
103 | ||
590fb506 C |
104 | it('Should fail without a target url', async function () { |
105 | const fields = omit(baseCorrectParams, 'targetUrl') | |
106 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 }) | |
107 | }) | |
108 | ||
109 | it('Should fail with a bad target url', async function () { | |
110 | const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) | |
111 | ||
112 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
113 | }) | |
114 | ||
5d08a6a7 C |
115 | it('Should fail with a long name', async function () { |
116 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) | |
117 | ||
118 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
119 | }) | |
120 | ||
121 | it('Should fail with a bad category', async function () { | |
122 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) | |
123 | ||
124 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
125 | }) | |
126 | ||
127 | it('Should fail with a bad licence', async function () { | |
128 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) | |
129 | ||
130 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
131 | }) | |
132 | ||
133 | it('Should fail with a bad language', async function () { | |
134 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) | |
135 | ||
136 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
137 | }) | |
138 | ||
139 | it('Should fail with a long description', async function () { | |
140 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) | |
141 | ||
142 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
143 | }) | |
144 | ||
145 | it('Should fail with a long support text', async function () { | |
d23e6a1c | 146 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) |
5d08a6a7 C |
147 | |
148 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
149 | }) | |
150 | ||
151 | it('Should fail without a channel', async function () { | |
152 | const fields = omit(baseCorrectParams, 'channelId') | |
153 | ||
154 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
155 | }) | |
156 | ||
157 | it('Should fail with a bad channel', async function () { | |
158 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | |
159 | ||
160 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
161 | }) | |
162 | ||
163 | it('Should fail with another user channel', async function () { | |
164 | const user = { | |
165 | username: 'fake', | |
166 | password: 'fake_password' | |
167 | } | |
1eddc9a7 | 168 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
5d08a6a7 C |
169 | |
170 | const accessTokenUser = await userLogin(server, user) | |
171 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
172 | const customChannelId = res.body.videoChannels[0].id | |
173 | ||
174 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) | |
175 | ||
176 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | |
177 | }) | |
178 | ||
179 | it('Should fail with too many tags', async function () { | |
180 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) | |
181 | ||
182 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
183 | }) | |
184 | ||
185 | it('Should fail with a tag length too low', async function () { | |
186 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) | |
187 | ||
188 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
189 | }) | |
190 | ||
191 | it('Should fail with a tag length too big', async function () { | |
192 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) | |
193 | ||
194 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
195 | }) | |
196 | ||
197 | it('Should fail with an incorrect thumbnail file', async function () { | |
198 | const fields = baseCorrectParams | |
199 | const attaches = { | |
a1587156 | 200 | thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
5d08a6a7 C |
201 | } |
202 | ||
203 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
204 | }) | |
205 | ||
206 | it('Should fail with a big thumbnail file', async function () { | |
207 | const fields = baseCorrectParams | |
208 | const attaches = { | |
a1587156 | 209 | thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
5d08a6a7 C |
210 | } |
211 | ||
212 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
213 | }) | |
214 | ||
215 | it('Should fail with an incorrect preview file', async function () { | |
216 | const fields = baseCorrectParams | |
217 | const attaches = { | |
a1587156 | 218 | previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
5d08a6a7 C |
219 | } |
220 | ||
221 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
222 | }) | |
223 | ||
224 | it('Should fail with a big preview file', async function () { | |
225 | const fields = baseCorrectParams | |
226 | const attaches = { | |
a1587156 | 227 | previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
5d08a6a7 C |
228 | } |
229 | ||
230 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
231 | }) | |
232 | ||
187501f8 C |
233 | it('Should fail with an invalid torrent file', async function () { |
234 | const fields = omit(baseCorrectParams, 'targetUrl') | |
235 | const attaches = { | |
a1587156 | 236 | torrentfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
187501f8 C |
237 | } |
238 | ||
239 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
240 | }) | |
241 | ||
242 | it('Should fail with an invalid magnet URI', async function () { | |
243 | let fields = omit(baseCorrectParams, 'targetUrl') | |
244 | fields = immutableAssign(fields, { magnetUri: 'blabla' }) | |
245 | ||
246 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
247 | }) | |
248 | ||
5d08a6a7 | 249 | it('Should succeed with the correct parameters', async function () { |
13b6dc1f | 250 | this.timeout(30000) |
5d08a6a7 | 251 | |
5d08a6a7 C |
252 | { |
253 | await makePostBodyRequest({ | |
254 | url: server.url, | |
255 | path, | |
256 | token: server.accessToken, | |
590fb506 | 257 | fields: baseCorrectParams, |
5d08a6a7 C |
258 | statusCodeExpected: 200 |
259 | }) | |
260 | } | |
261 | }) | |
262 | ||
187501f8 | 263 | it('Should forbid to import http videos', async function () { |
590fb506 C |
264 | await updateCustomSubConfig(server.url, server.accessToken, { |
265 | import: { | |
266 | videos: { | |
267 | http: { | |
268 | enabled: false | |
187501f8 C |
269 | }, |
270 | torrent: { | |
271 | enabled: true | |
590fb506 C |
272 | } |
273 | } | |
274 | } | |
275 | }) | |
276 | ||
277 | await makePostBodyRequest({ | |
278 | url: server.url, | |
279 | path, | |
280 | token: server.accessToken, | |
281 | fields: baseCorrectParams, | |
282 | statusCodeExpected: 409 | |
283 | }) | |
284 | }) | |
187501f8 C |
285 | |
286 | it('Should forbid to import torrent videos', async function () { | |
287 | await updateCustomSubConfig(server.url, server.accessToken, { | |
288 | import: { | |
289 | videos: { | |
290 | http: { | |
291 | enabled: true | |
292 | }, | |
293 | torrent: { | |
294 | enabled: false | |
295 | } | |
296 | } | |
297 | } | |
298 | }) | |
299 | ||
300 | let fields = omit(baseCorrectParams, 'targetUrl') | |
301 | fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) | |
302 | ||
303 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
304 | ||
305 | fields = omit(fields, 'magnetUri') | |
306 | const attaches = { | |
a1587156 | 307 | torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent') |
187501f8 C |
308 | } |
309 | ||
310 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 }) | |
311 | }) | |
5d08a6a7 C |
312 | }) |
313 | ||
7c3b7976 C |
314 | after(async function () { |
315 | await cleanupTests([ server ]) | |
5d08a6a7 C |
316 | }) |
317 | }) |