aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-imports.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-imports.ts')
-rw-r--r--server/tests/api/check-params/video-imports.ts246
1 files changed, 246 insertions, 0 deletions
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
new file mode 100644
index 000000000..7f58efb74
--- /dev/null
+++ b/server/tests/api/check-params/video-imports.ts
@@ -0,0 +1,246 @@
1/* tslint:disable:no-unused-expression */
2
3import { omit } from 'lodash'
4import 'mocha'
5import { join } from 'path'
6import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
7import {
8 createUser,
9 flushTests,
10 getMyUserInformation,
11 immutableAssign,
12 killallServers,
13 makeGetRequest,
14 makePostBodyRequest,
15 makeUploadRequest,
16 runServer,
17 ServerInfo,
18 setAccessTokensToServers,
19 userLogin
20} from '../../utils'
21import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
22
23describe('Test video imports API validator', function () {
24 const path = '/api/v1/videos/imports'
25 let server: ServerInfo
26 let userAccessToken = ''
27 let accountName: string
28 let channelId: number
29 let channelUUID: string
30
31 // ---------------------------------------------------------------
32
33 before(async function () {
34 this.timeout(30000)
35
36 await flushTests()
37
38 server = await runServer(1)
39
40 await setAccessTokensToServers([ server ])
41
42 const username = 'user1'
43 const password = 'my super password'
44 await createUser(server.url, server.accessToken, username, password)
45 userAccessToken = await userLogin(server, { username, password })
46
47 {
48 const res = await getMyUserInformation(server.url, server.accessToken)
49 channelId = res.body.videoChannels[ 0 ].id
50 channelUUID = res.body.videoChannels[ 0 ].uuid
51 accountName = res.body.account.name + '@' + res.body.account.host
52 }
53 })
54
55 describe('When listing my video imports', function () {
56 const myPath = '/api/v1/users/me/videos/imports'
57
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, myPath, server.accessToken)
60 })
61
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, myPath, server.accessToken)
64 })
65
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, myPath, server.accessToken)
68 })
69
70 it('Should success with the correct parameters', async function () {
71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken })
72 })
73 })
74
75 describe('When adding a video import', function () {
76 let baseCorrectParams
77
78 before(function () {
79 baseCorrectParams = {
80 targetUrl: 'https://youtu.be/msX3jv1XdvM',
81 name: 'my super name',
82 category: 5,
83 licence: 1,
84 language: 'pt',
85 nsfw: false,
86 commentsEnabled: true,
87 waitTranscoding: true,
88 description: 'my super description',
89 support: 'my super support text',
90 tags: [ 'tag1', 'tag2' ],
91 privacy: VideoPrivacy.PUBLIC,
92 channelId: channelId
93 }
94 })
95
96 it('Should fail with nothing', async function () {
97 const fields = {}
98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
99 })
100
101 it('Should fail with a long name', async function () {
102 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
103
104 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
105 })
106
107 it('Should fail with a bad category', async function () {
108 const fields = immutableAssign(baseCorrectParams, { category: 125 })
109
110 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
111 })
112
113 it('Should fail with a bad licence', async function () {
114 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
115
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 })
118
119 it('Should fail with a bad language', async function () {
120 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
121
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
123 })
124
125 it('Should fail with a long description', async function () {
126 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
127
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 })
130
131 it('Should fail with a long support text', async function () {
132 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
133
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 })
136
137 it('Should fail without a channel', async function () {
138 const fields = omit(baseCorrectParams, 'channelId')
139
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 })
142
143 it('Should fail with a bad channel', async function () {
144 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
145
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 })
148
149 it('Should fail with another user channel', async function () {
150 const user = {
151 username: 'fake',
152 password: 'fake_password'
153 }
154 await createUser(server.url, server.accessToken, user.username, user.password)
155
156 const accessTokenUser = await userLogin(server, user)
157 const res = await getMyUserInformation(server.url, accessTokenUser)
158 const customChannelId = res.body.videoChannels[0].id
159
160 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
161
162 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
163 })
164
165 it('Should fail with too many tags', async function () {
166 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
167
168 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
169 })
170
171 it('Should fail with a tag length too low', async function () {
172 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
173
174 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
175 })
176
177 it('Should fail with a tag length too big', async function () {
178 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
179
180 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
181 })
182
183 it('Should fail with an incorrect thumbnail file', async function () {
184 const fields = baseCorrectParams
185 const attaches = {
186 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
187 }
188
189 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
190 })
191
192 it('Should fail with a big thumbnail file', async function () {
193 const fields = baseCorrectParams
194 const attaches = {
195 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
196 }
197
198 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
199 })
200
201 it('Should fail with an incorrect preview file', async function () {
202 const fields = baseCorrectParams
203 const attaches = {
204 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
205 }
206
207 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
208 })
209
210 it('Should fail with a big preview file', async function () {
211 const fields = baseCorrectParams
212 const attaches = {
213 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
214 }
215
216 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
217 })
218
219 it('Should succeed with the correct parameters', async function () {
220 this.timeout(10000)
221
222 const fields = baseCorrectParams
223
224 {
225 await makePostBodyRequest({
226 url: server.url,
227 path,
228 token: server.accessToken,
229 fields,
230 statusCodeExpected: 200
231 })
232 }
233 })
234
235 it('Should forbid importing')
236 })
237
238 after(async function () {
239 killallServers([ server ])
240
241 // Keep the logs if the test failed
242 if (this['ok']) {
243 await flushTests()
244 }
245 })
246})