aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/config.ts28
-rw-r--r--server/tests/api/check-params/live.ts29
-rw-r--r--server/tests/api/check-params/plugins.ts7
-rw-r--r--server/tests/api/check-params/search.ts55
-rw-r--r--server/tests/api/check-params/user-notifications.ts20
-rw-r--r--server/tests/api/check-params/users.ts77
-rw-r--r--server/tests/api/check-params/video-channels.ts31
-rw-r--r--server/tests/api/check-params/video-imports.ts29
-rw-r--r--server/tests/api/check-params/video-playlists.ts5
-rw-r--r--server/tests/api/check-params/videos.ts75
10 files changed, 178 insertions, 178 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 9549070ef..291de93ea 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -1,22 +1,20 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { omit } from 'lodash'
4import 'mocha' 3import 'mocha'
5import { CustomConfig } from '../../../../shared/models/server/custom-config.model' 4import { omit } from 'lodash'
6 5import { HttpStatusCode } from '@shared/core-utils'
7import { 6import {
8 cleanupTests, 7 cleanupTests,
9 createUser, 8 createUser,
10 flushAndRunServer, 9 flushAndRunServer,
11 immutableAssign,
12 makeDeleteRequest, 10 makeDeleteRequest,
13 makeGetRequest, 11 makeGetRequest,
14 makePutBodyRequest, 12 makePutBodyRequest,
15 ServerInfo, 13 ServerInfo,
16 setAccessTokensToServers, 14 setAccessTokensToServers,
17 userLogin 15 userLogin
18} from '../../../../shared/extra-utils' 16} from '@shared/extra-utils'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 17import { CustomConfig } from '@shared/models'
20 18
21describe('Test config API validators', function () { 19describe('Test config API validators', function () {
22 const path = '/api/v1/config/custom' 20 const path = '/api/v1/config/custom'
@@ -265,11 +263,13 @@ describe('Test config API validators', function () {
265 }) 263 })
266 264
267 it('Should fail with a bad default NSFW policy', async function () { 265 it('Should fail with a bad default NSFW policy', async function () {
268 const newUpdateParams = immutableAssign(updateParams, { 266 const newUpdateParams = {
267 ...updateParams,
268
269 instance: { 269 instance: {
270 defaultNSFWPolicy: 'hello' 270 defaultNSFWPolicy: 'hello'
271 } 271 }
272 }) 272 }
273 273
274 await makePutBodyRequest({ 274 await makePutBodyRequest({
275 url: server.url, 275 url: server.url,
@@ -282,13 +282,15 @@ describe('Test config API validators', function () {
282 282
283 it('Should fail if email disabled and signup requires email verification', async function () { 283 it('Should fail if email disabled and signup requires email verification', async function () {
284 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts 284 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
285 const newUpdateParams = immutableAssign(updateParams, { 285 const newUpdateParams = {
286 ...updateParams,
287
286 signup: { 288 signup: {
287 enabled: true, 289 enabled: true,
288 limit: 5, 290 limit: 5,
289 requiresEmailVerification: true 291 requiresEmailVerification: true
290 } 292 }
291 }) 293 }
292 294
293 await makePutBodyRequest({ 295 await makePutBodyRequest({
294 url: server.url, 296 url: server.url,
@@ -300,7 +302,9 @@ describe('Test config API validators', function () {
300 }) 302 })
301 303
302 it('Should fail with a disabled webtorrent & hls transcoding', async function () { 304 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
303 const newUpdateParams = immutableAssign(updateParams, { 305 const newUpdateParams = {
306 ...updateParams,
307
304 transcoding: { 308 transcoding: {
305 hls: { 309 hls: {
306 enabled: false 310 enabled: false
@@ -309,7 +313,7 @@ describe('Test config API validators', function () {
309 enabled: false 313 enabled: false
310 } 314 }
311 } 315 }
312 }) 316 }
313 317
314 await makePutBodyRequest({ 318 await makePutBodyRequest({
315 url: server.url, 319 url: server.url,
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index d851d258d..394967285 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -10,7 +10,6 @@ import {
10 createUser, 10 createUser,
11 flushAndRunServer, 11 flushAndRunServer,
12 getMyUserInformation, 12 getMyUserInformation,
13 immutableAssign,
14 LiveCommand, 13 LiveCommand,
15 makePostBodyRequest, 14 makePostBodyRequest,
16 makeUploadRequest, 15 makeUploadRequest,
@@ -97,37 +96,37 @@ describe('Test video lives API validator', function () {
97 }) 96 })
98 97
99 it('Should fail with a long name', async function () { 98 it('Should fail with a long name', async function () {
100 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 99 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
101 100
102 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 101 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
103 }) 102 })
104 103
105 it('Should fail with a bad category', async function () { 104 it('Should fail with a bad category', async function () {
106 const fields = immutableAssign(baseCorrectParams, { category: 125 }) 105 const fields = { ...baseCorrectParams, category: 125 }
107 106
108 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
109 }) 108 })
110 109
111 it('Should fail with a bad licence', async function () { 110 it('Should fail with a bad licence', async function () {
112 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 111 const fields = { ...baseCorrectParams, licence: 125 }
113 112
114 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
115 }) 114 })
116 115
117 it('Should fail with a bad language', async function () { 116 it('Should fail with a bad language', async function () {
118 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 117 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
119 118
120 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
121 }) 120 })
122 121
123 it('Should fail with a long description', async function () { 122 it('Should fail with a long description', async function () {
124 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) 123 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
125 124
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 125 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
127 }) 126 })
128 127
129 it('Should fail with a long support text', async function () { 128 it('Should fail with a long support text', async function () {
130 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 129 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
131 130
132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 131 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
133 }) 132 })
@@ -139,7 +138,7 @@ describe('Test video lives API validator', function () {
139 }) 138 })
140 139
141 it('Should fail with a bad channel', async function () { 140 it('Should fail with a bad channel', async function () {
142 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) 141 const fields = { ...baseCorrectParams, channelId: 545454 }
143 142
144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 143 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
145 }) 144 })
@@ -155,25 +154,25 @@ describe('Test video lives API validator', function () {
155 const res = await getMyUserInformation(server.url, accessTokenUser) 154 const res = await getMyUserInformation(server.url, accessTokenUser)
156 const customChannelId = res.body.videoChannels[0].id 155 const customChannelId = res.body.videoChannels[0].id
157 156
158 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) 157 const fields = { ...baseCorrectParams, channelId: customChannelId }
159 158
160 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 159 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
161 }) 160 })
162 161
163 it('Should fail with too many tags', async function () { 162 it('Should fail with too many tags', async function () {
164 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) 163 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
165 164
166 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 165 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
167 }) 166 })
168 167
169 it('Should fail with a tag length too low', async function () { 168 it('Should fail with a tag length too low', async function () {
170 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) 169 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
171 170
172 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 171 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
173 }) 172 })
174 173
175 it('Should fail with a tag length too big', async function () { 174 it('Should fail with a tag length too big', async function () {
176 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 175 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
177 176
178 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 177 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
179 }) 178 })
@@ -215,7 +214,7 @@ describe('Test video lives API validator', function () {
215 }) 214 })
216 215
217 it('Should fail with save replay and permanent live set to true', async function () { 216 it('Should fail with save replay and permanent live set to true', async function () {
218 const fields = immutableAssign(baseCorrectParams, { saveReplay: true, permanentLive: true }) 217 const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true }
219 218
220 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 219 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
221 }) 220 })
@@ -253,7 +252,7 @@ describe('Test video lives API validator', function () {
253 }) 252 })
254 253
255 it('Should forbid to save replay if not enabled by the admin', async function () { 254 it('Should forbid to save replay if not enabled by the admin', async function () {
256 const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) 255 const fields = { ...baseCorrectParams, saveReplay: true }
257 256
258 await server.configCommand.updateCustomSubConfig({ 257 await server.configCommand.updateCustomSubConfig({
259 newConfig: { 258 newConfig: {
@@ -274,7 +273,7 @@ describe('Test video lives API validator', function () {
274 }) 273 })
275 274
276 it('Should allow to save replay if enabled by the admin', async function () { 275 it('Should allow to save replay if enabled by the admin', async function () {
277 const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) 276 const fields = { ...baseCorrectParams, saveReplay: true }
278 277
279 await server.configCommand.updateCustomSubConfig({ 278 await server.configCommand.updateCustomSubConfig({
280 newConfig: { 279 newConfig: {
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index d372221d0..8509b8ac5 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -9,7 +9,6 @@ import {
9 cleanupTests, 9 cleanupTests,
10 createUser, 10 createUser,
11 flushAndRunServer, 11 flushAndRunServer,
12 immutableAssign,
13 makeGetRequest, 12 makeGetRequest,
14 makePostBodyRequest, 13 makePostBodyRequest,
15 makePutBodyRequest, 14 makePutBodyRequest,
@@ -200,7 +199,7 @@ describe('Test server plugins API validators', function () {
200 }) 199 })
201 200
202 it('Should fail with an invalid plugin type', async function () { 201 it('Should fail with an invalid plugin type', async function () {
203 const query = immutableAssign(baseQuery, { pluginType: 5 }) 202 const query = { ...baseQuery, pluginType: 5 }
204 203
205 await makeGetRequest({ 204 await makeGetRequest({
206 url: server.url, 205 url: server.url,
@@ -211,7 +210,7 @@ describe('Test server plugins API validators', function () {
211 }) 210 })
212 211
213 it('Should fail with an invalid current peertube engine', async function () { 212 it('Should fail with an invalid current peertube engine', async function () {
214 const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' }) 213 const query = { ...baseQuery, currentPeerTubeEngine: '1.0' }
215 214
216 await makeGetRequest({ 215 await makeGetRequest({
217 url: server.url, 216 url: server.url,
@@ -271,7 +270,7 @@ describe('Test server plugins API validators', function () {
271 }) 270 })
272 271
273 it('Should fail with an invalid plugin type', async function () { 272 it('Should fail with an invalid plugin type', async function () {
274 const query = immutableAssign(baseQuery, { pluginType: 5 }) 273 const query = { ...baseQuery, pluginType: 5 }
275 274
276 await makeGetRequest({ 275 await makeGetRequest({
277 url: server.url, 276 url: server.url,
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
index 4a2fc1197..7973c112f 100644
--- a/server/tests/api/check-params/search.ts
+++ b/server/tests/api/check-params/search.ts
@@ -8,7 +8,6 @@ import {
8 checkBadStartPagination, 8 checkBadStartPagination,
9 cleanupTests, 9 cleanupTests,
10 flushAndRunServer, 10 flushAndRunServer,
11 immutableAssign,
12 makeGetRequest, 11 makeGetRequest,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers 13 setAccessTokensToServers
@@ -63,78 +62,78 @@ describe('Test videos API validator', function () {
63 }) 62 })
64 63
65 it('Should fail with an invalid category', async function () { 64 it('Should fail with an invalid category', async function () {
66 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) 65 const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] }
67 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 66 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
68 67
69 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) 68 const customQuery2 = { ...query, categoryOneOf: 'a' }
70 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 69 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
71 }) 70 })
72 71
73 it('Should succeed with a valid category', async function () { 72 it('Should succeed with a valid category', async function () {
74 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) 73 const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] }
75 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 74 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
76 75
77 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) 76 const customQuery2 = { ...query, categoryOneOf: 1 }
78 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 77 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
79 }) 78 })
80 79
81 it('Should fail with an invalid licence', async function () { 80 it('Should fail with an invalid licence', async function () {
82 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) 81 const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] }
83 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 82 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
84 83
85 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) 84 const customQuery2 = { ...query, licenceOneOf: 'a' }
86 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 85 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
87 }) 86 })
88 87
89 it('Should succeed with a valid licence', async function () { 88 it('Should succeed with a valid licence', async function () {
90 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) 89 const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] }
91 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 90 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
92 91
93 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) 92 const customQuery2 = { ...query, licenceOneOf: 1 }
94 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 93 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
95 }) 94 })
96 95
97 it('Should succeed with a valid language', async function () { 96 it('Should succeed with a valid language', async function () {
98 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) 97 const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] }
99 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 98 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
100 99
101 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) 100 const customQuery2 = { ...query, languageOneOf: 'fr' }
102 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 101 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
103 }) 102 })
104 103
105 it('Should succeed with valid tags', async function () { 104 it('Should succeed with valid tags', async function () {
106 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) 105 const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] }
107 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 106 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
108 107
109 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) 108 const customQuery2 = { ...query, tagsOneOf: 'tag1' }
110 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 109 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
111 110
112 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) 111 const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] }
113 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) 112 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
114 113
115 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) 114 const customQuery4 = { ...query, tagsAllOf: 'tag1' }
116 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) 115 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
117 }) 116 })
118 117
119 it('Should fail with invalid durations', async function () { 118 it('Should fail with invalid durations', async function () {
120 const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) 119 const customQuery1 = { ...query, durationMin: 'hello' }
121 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 120 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
122 121
123 const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) 122 const customQuery2 = { ...query, durationMax: 'hello' }
124 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 123 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
125 }) 124 })
126 125
127 it('Should fail with invalid dates', async function () { 126 it('Should fail with invalid dates', async function () {
128 const customQuery1 = immutableAssign(query, { startDate: 'hello' }) 127 const customQuery1 = { ...query, startDate: 'hello' }
129 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 128 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
130 129
131 const customQuery2 = immutableAssign(query, { endDate: 'hello' }) 130 const customQuery2 = { ...query, endDate: 'hello' }
132 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 131 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
133 132
134 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) 133 const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' }
135 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 134 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
136 135
137 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) 136 const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' }
138 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 137 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
139 }) 138 })
140 }) 139 })
@@ -201,41 +200,41 @@ describe('Test videos API validator', function () {
201 200
202 for (const path of paths) { 201 for (const path of paths) {
203 { 202 {
204 const customQuery = immutableAssign(query, { searchTarget: 'hello' }) 203 const customQuery = { ...query, searchTarget: 'hello' }
205 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 204 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
206 } 205 }
207 206
208 { 207 {
209 const customQuery = immutableAssign(query, { searchTarget: undefined }) 208 const customQuery = { ...query, searchTarget: undefined }
210 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 209 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
211 } 210 }
212 211
213 { 212 {
214 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 213 const customQuery = { ...query, searchTarget: 'local' }
215 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 214 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
216 } 215 }
217 216
218 { 217 {
219 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 218 const customQuery = { ...query, searchTarget: 'search-index' }
220 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 219 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
221 } 220 }
222 221
223 await updateSearchIndex(server, true, true) 222 await updateSearchIndex(server, true, true)
224 223
225 { 224 {
226 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 225 const customQuery = { ...query, searchTarget: 'local' }
227 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 226 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
228 } 227 }
229 228
230 { 229 {
231 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 230 const customQuery = { ...query, searchTarget: 'search-index' }
232 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 231 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
233 } 232 }
234 233
235 await updateSearchIndex(server, true, false) 234 await updateSearchIndex(server, true, false)
236 235
237 { 236 {
238 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 237 const customQuery = { ...query, searchTarget: 'local' }
239 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 238 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
240 } 239 }
241 240
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 26d4423f9..913eca366 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -2,25 +2,21 @@
2 2
3import 'mocha' 3import 'mocha'
4import { io } from 'socket.io-client' 4import { io } from 'socket.io-client'
5 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination,
7 cleanupTests, 10 cleanupTests,
8 flushAndRunServer, 11 flushAndRunServer,
9 immutableAssign,
10 makeGetRequest, 12 makeGetRequest,
11 makePostBodyRequest, 13 makePostBodyRequest,
12 makePutBodyRequest, 14 makePutBodyRequest,
13 ServerInfo, 15 ServerInfo,
14 setAccessTokensToServers, 16 setAccessTokensToServers,
15 wait 17 wait
16} from '../../../../shared/extra-utils' 18} from '@shared/extra-utils'
17import { 19import { UserNotificationSetting, UserNotificationSettingValue } from '@shared/models'
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
24 20
25describe('Test user notifications API validators', function () { 21describe('Test user notifications API validators', function () {
26 let server: ServerInfo 22 let server: ServerInfo
@@ -193,7 +189,7 @@ describe('Test user notifications API validators', function () {
193 189
194 it('Should fail with incorrect field values', async function () { 190 it('Should fail with incorrect field values', async function () {
195 { 191 {
196 const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 15 }) 192 const fields = { ...correctFields, newCommentOnMyVideo: 15 }
197 193
198 await makePutBodyRequest({ 194 await makePutBodyRequest({
199 url: server.url, 195 url: server.url,
@@ -205,7 +201,7 @@ describe('Test user notifications API validators', function () {
205 } 201 }
206 202
207 { 203 {
208 const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 'toto' }) 204 const fields = { ...correctFields, newCommentOnMyVideo: 'toto' }
209 205
210 await makePutBodyRequest({ 206 await makePutBodyRequest({
211 url: server.url, 207 url: server.url,
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index bffe29bce..fda7e9640 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -15,7 +15,6 @@ import {
15 getMyUserVideoRating, 15 getMyUserVideoRating,
16 getUserScopedTokens, 16 getUserScopedTokens,
17 getUsersList, 17 getUsersList,
18 immutableAssign,
19 killallServers, 18 killallServers,
20 makeGetRequest, 19 makeGetRequest,
21 makePostBodyRequest, 20 makePostBodyRequest,
@@ -181,25 +180,25 @@ describe('Test users API validators', function () {
181 } 180 }
182 181
183 it('Should fail with a too small username', async function () { 182 it('Should fail with a too small username', async function () {
184 const fields = immutableAssign(baseCorrectParams, { username: '' }) 183 const fields = { ...baseCorrectParams, username: '' }
185 184
186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 185 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 }) 186 })
188 187
189 it('Should fail with a too long username', async function () { 188 it('Should fail with a too long username', async function () {
190 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) 189 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
191 190
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 191 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 }) 192 })
194 193
195 it('Should fail with a not lowercase username', async function () { 194 it('Should fail with a not lowercase username', async function () {
196 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) 195 const fields = { ...baseCorrectParams, username: 'Toto' }
197 196
198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 197 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 }) 198 })
200 199
201 it('Should fail with an incorrect username', async function () { 200 it('Should fail with an incorrect username', async function () {
202 const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) 201 const fields = { ...baseCorrectParams, username: 'my username' }
203 202
204 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 203 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
205 }) 204 })
@@ -211,25 +210,25 @@ describe('Test users API validators', function () {
211 }) 210 })
212 211
213 it('Should fail with an invalid email', async function () { 212 it('Should fail with an invalid email', async function () {
214 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) 213 const fields = { ...baseCorrectParams, email: 'test_example.com' }
215 214
216 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 215 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
217 }) 216 })
218 217
219 it('Should fail with a too small password', async function () { 218 it('Should fail with a too small password', async function () {
220 const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) 219 const fields = { ...baseCorrectParams, password: 'bla' }
221 220
222 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 221 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 }) 222 })
224 223
225 it('Should fail with a too long password', async function () { 224 it('Should fail with a too long password', async function () {
226 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) 225 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
227 226
228 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 227 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
229 }) 228 })
230 229
231 it('Should fail with empty password and no smtp configured', async function () { 230 it('Should fail with empty password and no smtp configured', async function () {
232 const fields = immutableAssign(baseCorrectParams, { password: '' }) 231 const fields = { ...baseCorrectParams, password: '' }
233 232
234 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 233 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
235 }) 234 })
@@ -239,19 +238,23 @@ describe('Test users API validators', function () {
239 238
240 await killallServers([ server ]) 239 await killallServers([ server ])
241 240
242 const config = immutableAssign(overrideConfig, { 241 const config = {
242 ...overrideConfig,
243
243 smtp: { 244 smtp: {
244 hostname: 'localhost', 245 hostname: 'localhost',
245 port: emailPort 246 port: emailPort
246 } 247 }
247 }) 248 }
248 await reRunServer(server, config) 249 await reRunServer(server, config)
249 250
250 const fields = immutableAssign(baseCorrectParams, { 251 const fields = {
252 ...baseCorrectParams,
253
251 password: '', 254 password: '',
252 username: 'create_password', 255 username: 'create_password',
253 email: 'create_password@example.com' 256 email: 'create_password@example.com'
254 }) 257 }
255 258
256 await makePostBodyRequest({ 259 await makePostBodyRequest({
257 url: server.url, 260 url: server.url,
@@ -263,7 +266,7 @@ describe('Test users API validators', function () {
263 }) 266 })
264 267
265 it('Should fail with invalid admin flags', async function () { 268 it('Should fail with invalid admin flags', async function () {
266 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) 269 const fields = { ...baseCorrectParams, adminFlags: 'toto' }
267 270
268 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 271 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
269 }) 272 })
@@ -279,7 +282,7 @@ describe('Test users API validators', function () {
279 }) 282 })
280 283
281 it('Should fail if we add a user with the same username', async function () { 284 it('Should fail if we add a user with the same username', async function () {
282 const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) 285 const fields = { ...baseCorrectParams, username: 'user1' }
283 286
284 await makePostBodyRequest({ 287 await makePostBodyRequest({
285 url: server.url, 288 url: server.url,
@@ -291,7 +294,7 @@ describe('Test users API validators', function () {
291 }) 294 })
292 295
293 it('Should fail if we add a user with the same email', async function () { 296 it('Should fail if we add a user with the same email', async function () {
294 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) 297 const fields = { ...baseCorrectParams, email: 'user1@example.com' }
295 298
296 await makePostBodyRequest({ 299 await makePostBodyRequest({
297 url: server.url, 300 url: server.url,
@@ -315,13 +318,13 @@ describe('Test users API validators', function () {
315 }) 318 })
316 319
317 it('Should fail with an invalid videoQuota', async function () { 320 it('Should fail with an invalid videoQuota', async function () {
318 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) 321 const fields = { ...baseCorrectParams, videoQuota: -5 }
319 322
320 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 323 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
321 }) 324 })
322 325
323 it('Should fail with an invalid videoQuotaDaily', async function () { 326 it('Should fail with an invalid videoQuotaDaily', async function () {
324 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) 327 const fields = { ...baseCorrectParams, videoQuotaDaily: -7 }
325 328
326 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 329 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
327 }) 330 })
@@ -333,13 +336,13 @@ describe('Test users API validators', function () {
333 }) 336 })
334 337
335 it('Should fail with an invalid user role', async function () { 338 it('Should fail with an invalid user role', async function () {
336 const fields = immutableAssign(baseCorrectParams, { role: 88989 }) 339 const fields = { ...baseCorrectParams, role: 88989 }
337 340
338 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 341 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
339 }) 342 })
340 343
341 it('Should fail with a "peertube" username', async function () { 344 it('Should fail with a "peertube" username', async function () {
342 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) 345 const fields = { ...baseCorrectParams, username: 'peertube' }
343 346
344 await makePostBodyRequest({ 347 await makePostBodyRequest({
345 url: server.url, 348 url: server.url,
@@ -352,7 +355,7 @@ describe('Test users API validators', function () {
352 355
353 it('Should fail to create a moderator or an admin with a moderator', async function () { 356 it('Should fail to create a moderator or an admin with a moderator', async function () {
354 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) { 357 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
355 const fields = immutableAssign(baseCorrectParams, { role }) 358 const fields = { ...baseCorrectParams, role }
356 359
357 await makePostBodyRequest({ 360 await makePostBodyRequest({
358 url: server.url, 361 url: server.url,
@@ -365,7 +368,7 @@ describe('Test users API validators', function () {
365 }) 368 })
366 369
367 it('Should succeed to create a user with a moderator', async function () { 370 it('Should succeed to create a user with a moderator', async function () {
368 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }) 371 const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }
369 372
370 await makePostBodyRequest({ 373 await makePostBodyRequest({
371 url: server.url, 374 url: server.url,
@@ -937,19 +940,19 @@ describe('Test users API validators', function () {
937 } 940 }
938 941
939 it('Should fail with a too small username', async function () { 942 it('Should fail with a too small username', async function () {
940 const fields = immutableAssign(baseCorrectParams, { username: '' }) 943 const fields = { ...baseCorrectParams, username: '' }
941 944
942 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 945 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
943 }) 946 })
944 947
945 it('Should fail with a too long username', async function () { 948 it('Should fail with a too long username', async function () {
946 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) 949 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
947 950
948 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 951 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
949 }) 952 })
950 953
951 it('Should fail with an incorrect username', async function () { 954 it('Should fail with an incorrect username', async function () {
952 const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) 955 const fields = { ...baseCorrectParams, username: 'my username' }
953 956
954 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 957 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
955 }) 958 })
@@ -961,25 +964,25 @@ describe('Test users API validators', function () {
961 }) 964 })
962 965
963 it('Should fail with an invalid email', async function () { 966 it('Should fail with an invalid email', async function () {
964 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) 967 const fields = { ...baseCorrectParams, email: 'test_example.com' }
965 968
966 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 969 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
967 }) 970 })
968 971
969 it('Should fail with a too small password', async function () { 972 it('Should fail with a too small password', async function () {
970 const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) 973 const fields = { ...baseCorrectParams, password: 'bla' }
971 974
972 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 975 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
973 }) 976 })
974 977
975 it('Should fail with a too long password', async function () { 978 it('Should fail with a too long password', async function () {
976 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) 979 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
977 980
978 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 981 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
979 }) 982 })
980 983
981 it('Should fail if we register a user with the same username', async function () { 984 it('Should fail if we register a user with the same username', async function () {
982 const fields = immutableAssign(baseCorrectParams, { username: 'root' }) 985 const fields = { ...baseCorrectParams, username: 'root' }
983 986
984 await makePostBodyRequest({ 987 await makePostBodyRequest({
985 url: server.url, 988 url: server.url,
@@ -991,7 +994,7 @@ describe('Test users API validators', function () {
991 }) 994 })
992 995
993 it('Should fail with a "peertube" username', async function () { 996 it('Should fail with a "peertube" username', async function () {
994 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) 997 const fields = { ...baseCorrectParams, username: 'peertube' }
995 998
996 await makePostBodyRequest({ 999 await makePostBodyRequest({
997 url: server.url, 1000 url: server.url,
@@ -1003,7 +1006,7 @@ describe('Test users API validators', function () {
1003 }) 1006 })
1004 1007
1005 it('Should fail if we register a user with the same email', async function () { 1008 it('Should fail if we register a user with the same email', async function () {
1006 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) 1009 const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' }
1007 1010
1008 await makePostBodyRequest({ 1011 await makePostBodyRequest({
1009 url: server.url, 1012 url: server.url,
@@ -1015,26 +1018,26 @@ describe('Test users API validators', function () {
1015 }) 1018 })
1016 1019
1017 it('Should fail with a bad display name', async function () { 1020 it('Should fail with a bad display name', async function () {
1018 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) }) 1021 const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) }
1019 1022
1020 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1023 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1021 }) 1024 })
1022 1025
1023 it('Should fail with a bad channel name', async function () { 1026 it('Should fail with a bad channel name', async function () {
1024 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } }) 1027 const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } }
1025 1028
1026 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1029 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1027 }) 1030 })
1028 1031
1029 it('Should fail with a bad channel display name', async function () { 1032 it('Should fail with a bad channel display name', async function () {
1030 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } }) 1033 const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } }
1031 1034
1032 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1035 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1033 }) 1036 })
1034 1037
1035 it('Should fail with a channel name that is the same as username', async function () { 1038 it('Should fail with a channel name that is the same as username', async function () {
1036 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } } 1039 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1037 const fields = immutableAssign(baseCorrectParams, source) 1040 const fields = { ...baseCorrectParams, ...source }
1038 1041
1039 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1042 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1040 }) 1043 })
@@ -1043,7 +1046,7 @@ describe('Test users API validators', function () {
1043 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' } 1046 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1044 await server.channelsCommand.create({ attributes }) 1047 await server.channelsCommand.create({ attributes })
1045 1048
1046 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) 1049 const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } }
1047 1050
1048 await makePostBodyRequest({ 1051 await makePostBodyRequest({
1049 url: server.url, 1052 url: server.url,
@@ -1055,7 +1058,7 @@ describe('Test users API validators', function () {
1055 }) 1058 })
1056 1059
1057 it('Should succeed with the correct params', async function () { 1060 it('Should succeed with the correct params', async function () {
1058 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } }) 1061 const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } }
1059 1062
1060 await makePostBodyRequest({ 1063 await makePostBodyRequest({
1061 url: server.url, 1064 url: server.url,
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index d29346dc3..3b72d3796 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -3,14 +3,16 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 6import { HttpStatusCode } from '@shared/core-utils'
7import { 7import {
8 buildAbsoluteFixturePath, 8 buildAbsoluteFixturePath,
9 ChannelsCommand, 9 ChannelsCommand,
10 checkBadCountPagination,
11 checkBadSortPagination,
12 checkBadStartPagination,
10 cleanupTests, 13 cleanupTests,
11 createUser, 14 createUser,
12 flushAndRunServer, 15 flushAndRunServer,
13 immutableAssign,
14 makeGetRequest, 16 makeGetRequest,
15 makePostBodyRequest, 17 makePostBodyRequest,
16 makePutBodyRequest, 18 makePutBodyRequest,
@@ -18,13 +20,8 @@ import {
18 ServerInfo, 20 ServerInfo,
19 setAccessTokensToServers, 21 setAccessTokensToServers,
20 userLogin 22 userLogin
21} from '../../../../shared/extra-utils' 23} from '@shared/extra-utils'
22import { 24import { VideoChannelUpdate } from '@shared/models'
23 checkBadCountPagination,
24 checkBadSortPagination,
25 checkBadStartPagination
26} from '../../../../shared/extra-utils/requests/check-api-params'
27import { VideoChannelUpdate } from '../../../../shared/models/videos'
28 25
29const expect = chai.expect 26const expect = chai.expect
30 27
@@ -127,7 +124,7 @@ describe('Test video channels API validator', function () {
127 }) 124 })
128 125
129 it('Should fail with a bad name', async function () { 126 it('Should fail with a bad name', async function () {
130 const fields = immutableAssign(baseCorrectParams, { name: 'super name' }) 127 const fields = { ...baseCorrectParams, name: 'super name' }
131 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 128 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
132 }) 129 })
133 130
@@ -137,17 +134,17 @@ describe('Test video channels API validator', function () {
137 }) 134 })
138 135
139 it('Should fail with a long name', async function () { 136 it('Should fail with a long name', async function () {
140 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) 137 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
141 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 138 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
142 }) 139 })
143 140
144 it('Should fail with a long description', async function () { 141 it('Should fail with a long description', async function () {
145 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) 142 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
146 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 143 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
147 }) 144 })
148 145
149 it('Should fail with a long support text', async function () { 146 it('Should fail with a long support text', async function () {
150 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 147 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
151 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 148 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
152 }) 149 })
153 150
@@ -206,22 +203,22 @@ describe('Test video channels API validator', function () {
206 }) 203 })
207 204
208 it('Should fail with a long name', async function () { 205 it('Should fail with a long name', async function () {
209 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) 206 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
210 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 207 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
211 }) 208 })
212 209
213 it('Should fail with a long description', async function () { 210 it('Should fail with a long description', async function () {
214 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) 211 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
215 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 212 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
216 }) 213 })
217 214
218 it('Should fail with a long support text', async function () { 215 it('Should fail with a long support text', async function () {
219 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 216 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
220 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 217 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
221 }) 218 })
222 219
223 it('Should fail with a bad bulkVideosSupportUpdate field', async function () { 220 it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
224 const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' }) 221 const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' }
225 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 222 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
226 }) 223 })
227 224
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index ea473191e..2cc124cc1 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -12,7 +12,6 @@ import {
12 createUser, 12 createUser,
13 flushAndRunServer, 13 flushAndRunServer,
14 getMyUserInformation, 14 getMyUserInformation,
15 immutableAssign,
16 ImportsCommand, 15 ImportsCommand,
17 makeGetRequest, 16 makeGetRequest,
18 makePostBodyRequest, 17 makePostBodyRequest,
@@ -108,43 +107,43 @@ describe('Test video imports API validator', function () {
108 }) 107 })
109 108
110 it('Should fail with a bad target url', async function () { 109 it('Should fail with a bad target url', async function () {
111 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) 110 const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' }
112 111
113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 112 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
114 }) 113 })
115 114
116 it('Should fail with a long name', async function () { 115 it('Should fail with a long name', async function () {
117 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 116 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
118 117
119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 118 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 }) 119 })
121 120
122 it('Should fail with a bad category', async function () { 121 it('Should fail with a bad category', async function () {
123 const fields = immutableAssign(baseCorrectParams, { category: 125 }) 122 const fields = { ...baseCorrectParams, category: 125 }
124 123
125 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 124 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
126 }) 125 })
127 126
128 it('Should fail with a bad licence', async function () { 127 it('Should fail with a bad licence', async function () {
129 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 128 const fields = { ...baseCorrectParams, licence: 125 }
130 129
131 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 130 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
132 }) 131 })
133 132
134 it('Should fail with a bad language', async function () { 133 it('Should fail with a bad language', async function () {
135 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 134 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
136 135
137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 136 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
138 }) 137 })
139 138
140 it('Should fail with a long description', async function () { 139 it('Should fail with a long description', async function () {
141 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) 140 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
142 141
143 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 142 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
144 }) 143 })
145 144
146 it('Should fail with a long support text', async function () { 145 it('Should fail with a long support text', async function () {
147 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 146 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
148 147
149 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 148 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
150 }) 149 })
@@ -156,7 +155,7 @@ describe('Test video imports API validator', function () {
156 }) 155 })
157 156
158 it('Should fail with a bad channel', async function () { 157 it('Should fail with a bad channel', async function () {
159 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) 158 const fields = { ...baseCorrectParams, channelId: 545454 }
160 159
161 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 160 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
162 }) 161 })
@@ -172,25 +171,25 @@ describe('Test video imports API validator', function () {
172 const res = await getMyUserInformation(server.url, accessTokenUser) 171 const res = await getMyUserInformation(server.url, accessTokenUser)
173 const customChannelId = res.body.videoChannels[0].id 172 const customChannelId = res.body.videoChannels[0].id
174 173
175 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) 174 const fields = { ...baseCorrectParams, channelId: customChannelId }
176 175
177 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 176 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
178 }) 177 })
179 178
180 it('Should fail with too many tags', async function () { 179 it('Should fail with too many tags', async function () {
181 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) 180 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
182 181
183 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 182 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
184 }) 183 })
185 184
186 it('Should fail with a tag length too low', async function () { 185 it('Should fail with a tag length too low', async function () {
187 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) 186 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
188 187
189 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 188 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
190 }) 189 })
191 190
192 it('Should fail with a tag length too big', async function () { 191 it('Should fail with a tag length too big', async function () {
193 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 192 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
194 193
195 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 194 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
196 }) 195 })
@@ -242,7 +241,7 @@ describe('Test video imports API validator', function () {
242 241
243 it('Should fail with an invalid magnet URI', async function () { 242 it('Should fail with an invalid magnet URI', async function () {
244 let fields = omit(baseCorrectParams, 'targetUrl') 243 let fields = omit(baseCorrectParams, 'targetUrl')
245 fields = immutableAssign(fields, { magnetUri: 'blabla' }) 244 fields = { ...fields, magnetUri: 'blabla' }
246 245
247 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 246 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
248 }) 247 })
@@ -301,7 +300,7 @@ describe('Test video imports API validator', function () {
301 }) 300 })
302 301
303 let fields = omit(baseCorrectParams, 'targetUrl') 302 let fields = omit(baseCorrectParams, 'targetUrl')
304 fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() }) 303 fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() }
305 304
306 await makePostBodyRequest({ 305 await makePostBodyRequest({
307 url: server.url, 306 url: server.url,
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 1c507a047..3799e73b6 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -1,6 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '@shared/core-utils'
4import { 5import {
5 VideoPlaylistCreate, 6 VideoPlaylistCreate,
6 VideoPlaylistCreateResult, 7 VideoPlaylistCreateResult,
@@ -10,7 +11,6 @@ import {
10 VideoPlaylistReorder, 11 VideoPlaylistReorder,
11 VideoPlaylistType 12 VideoPlaylistType
12} from '@shared/models' 13} from '@shared/models'
13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14import { 14import {
15 checkBadCountPagination, 15 checkBadCountPagination,
16 checkBadSortPagination, 16 checkBadSortPagination,
@@ -18,7 +18,6 @@ import {
18 cleanupTests, 18 cleanupTests,
19 flushAndRunServer, 19 flushAndRunServer,
20 generateUserAccessToken, 20 generateUserAccessToken,
21 immutableAssign,
22 makeGetRequest, 21 makeGetRequest,
23 PlaylistsCommand, 22 PlaylistsCommand,
24 ServerInfo, 23 ServerInfo,
@@ -214,7 +213,7 @@ describe('Test video playlists API validator', function () {
214 } 213 }
215 } 214 }
216 const getUpdate = (params: any, playlistId: number | string) => { 215 const getUpdate = (params: any, playlistId: number | string) => {
217 return immutableAssign(params, { playlistId: playlistId }) 216 return { ...params, playlistId: playlistId }
218 } 217 }
219 218
220 it('Should fail with an unauthenticated user', async function () { 219 it('Should fail with an unauthenticated user', async function () {
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 4d7a9a23b..6549063b1 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -15,7 +15,6 @@ import {
15 getMyUserInformation, 15 getMyUserInformation,
16 getVideo, 16 getVideo,
17 getVideosList, 17 getVideosList,
18 immutableAssign,
19 makeDeleteRequest, 18 makeDeleteRequest,
20 makeGetRequest, 19 makeGetRequest,
21 makePutBodyRequest, 20 makePutBodyRequest,
@@ -225,42 +224,42 @@ describe('Test videos API validator', function () {
225 }) 224 })
226 225
227 it('Should fail with a long name', async function () { 226 it('Should fail with a long name', async function () {
228 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 227 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
229 const attaches = baseCorrectAttaches 228 const attaches = baseCorrectAttaches
230 229
231 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 230 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
232 }) 231 })
233 232
234 it('Should fail with a bad category', async function () { 233 it('Should fail with a bad category', async function () {
235 const fields = immutableAssign(baseCorrectParams, { category: 125 }) 234 const fields = { ...baseCorrectParams, category: 125 }
236 const attaches = baseCorrectAttaches 235 const attaches = baseCorrectAttaches
237 236
238 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 237 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
239 }) 238 })
240 239
241 it('Should fail with a bad licence', async function () { 240 it('Should fail with a bad licence', async function () {
242 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 241 const fields = { ...baseCorrectParams, licence: 125 }
243 const attaches = baseCorrectAttaches 242 const attaches = baseCorrectAttaches
244 243
245 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 244 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
246 }) 245 })
247 246
248 it('Should fail with a bad language', async function () { 247 it('Should fail with a bad language', async function () {
249 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 248 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
250 const attaches = baseCorrectAttaches 249 const attaches = baseCorrectAttaches
251 250
252 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 251 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
253 }) 252 })
254 253
255 it('Should fail with a long description', async function () { 254 it('Should fail with a long description', async function () {
256 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) 255 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
257 const attaches = baseCorrectAttaches 256 const attaches = baseCorrectAttaches
258 257
259 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 258 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
260 }) 259 })
261 260
262 it('Should fail with a long support text', async function () { 261 it('Should fail with a long support text', async function () {
263 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 262 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
264 const attaches = baseCorrectAttaches 263 const attaches = baseCorrectAttaches
265 264
266 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 265 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
@@ -274,7 +273,7 @@ describe('Test videos API validator', function () {
274 }) 273 })
275 274
276 it('Should fail with a bad channel', async function () { 275 it('Should fail with a bad channel', async function () {
277 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) 276 const fields = { ...baseCorrectParams, channelId: 545454 }
278 const attaches = baseCorrectAttaches 277 const attaches = baseCorrectAttaches
279 278
280 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 279 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
@@ -291,54 +290,56 @@ describe('Test videos API validator', function () {
291 const res = await getMyUserInformation(server.url, accessTokenUser) 290 const res = await getMyUserInformation(server.url, accessTokenUser)
292 const customChannelId = res.body.videoChannels[0].id 291 const customChannelId = res.body.videoChannels[0].id
293 292
294 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) 293 const fields = { ...baseCorrectParams, channelId: customChannelId }
295 const attaches = baseCorrectAttaches 294 const attaches = baseCorrectAttaches
296 295
297 await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 296 await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
298 }) 297 })
299 298
300 it('Should fail with too many tags', async function () { 299 it('Should fail with too many tags', async function () {
301 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) 300 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
302 const attaches = baseCorrectAttaches 301 const attaches = baseCorrectAttaches
303 302
304 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 303 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
305 }) 304 })
306 305
307 it('Should fail with a tag length too low', async function () { 306 it('Should fail with a tag length too low', async function () {
308 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) 307 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
309 const attaches = baseCorrectAttaches 308 const attaches = baseCorrectAttaches
310 309
311 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 310 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
312 }) 311 })
313 312
314 it('Should fail with a tag length too big', async function () { 313 it('Should fail with a tag length too big', async function () {
315 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 314 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
316 const attaches = baseCorrectAttaches 315 const attaches = baseCorrectAttaches
317 316
318 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 317 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
319 }) 318 })
320 319
321 it('Should fail with a bad schedule update (miss updateAt)', async function () { 320 it('Should fail with a bad schedule update (miss updateAt)', async function () {
322 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) 321 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
323 const attaches = baseCorrectAttaches 322 const attaches = baseCorrectAttaches
324 323
325 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 324 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
326 }) 325 })
327 326
328 it('Should fail with a bad schedule update (wrong updateAt)', async function () { 327 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
329 const fields = immutableAssign(baseCorrectParams, { 328 const fields = {
329 ...baseCorrectParams,
330
330 scheduleUpdate: { 331 scheduleUpdate: {
331 privacy: VideoPrivacy.PUBLIC, 332 privacy: VideoPrivacy.PUBLIC,
332 updateAt: 'toto' 333 updateAt: 'toto'
333 } 334 }
334 }) 335 }
335 const attaches = baseCorrectAttaches 336 const attaches = baseCorrectAttaches
336 337
337 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 338 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
338 }) 339 })
339 340
340 it('Should fail with a bad originally published at attribute', async function () { 341 it('Should fail with a bad originally published at attribute', async function () {
341 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) 342 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
342 const attaches = baseCorrectAttaches 343 const attaches = baseCorrectAttaches
343 344
344 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 345 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
@@ -413,7 +414,7 @@ describe('Test videos API validator', function () {
413 }) 414 })
414 415
415 it('Should report the appropriate error', async function () { 416 it('Should report the appropriate error', async function () {
416 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 417 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
417 const attaches = baseCorrectAttaches 418 const attaches = baseCorrectAttaches
418 419
419 const attributes = { ...fields, ...attaches } 420 const attributes = { ...fields, ...attaches }
@@ -448,17 +449,21 @@ describe('Test videos API validator', function () {
448 } 449 }
449 450
450 { 451 {
451 const attaches = immutableAssign(baseCorrectAttaches, { 452 const attaches = {
453 ...baseCorrectAttaches,
454
452 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 455 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
453 }) 456 }
454 457
455 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 458 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
456 } 459 }
457 460
458 { 461 {
459 const attaches = immutableAssign(baseCorrectAttaches, { 462 const attaches = {
463 ...baseCorrectAttaches,
464
460 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') 465 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
461 }) 466 }
462 467
463 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 468 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
464 } 469 }
@@ -516,79 +521,79 @@ describe('Test videos API validator', function () {
516 }) 521 })
517 522
518 it('Should fail with a long name', async function () { 523 it('Should fail with a long name', async function () {
519 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 524 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
520 525
521 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 526 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
522 }) 527 })
523 528
524 it('Should fail with a bad category', async function () { 529 it('Should fail with a bad category', async function () {
525 const fields = immutableAssign(baseCorrectParams, { category: 125 }) 530 const fields = { ...baseCorrectParams, category: 125 }
526 531
527 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 532 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
528 }) 533 })
529 534
530 it('Should fail with a bad licence', async function () { 535 it('Should fail with a bad licence', async function () {
531 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 536 const fields = { ...baseCorrectParams, licence: 125 }
532 537
533 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 538 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
534 }) 539 })
535 540
536 it('Should fail with a bad language', async function () { 541 it('Should fail with a bad language', async function () {
537 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 542 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
538 543
539 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 544 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
540 }) 545 })
541 546
542 it('Should fail with a long description', async function () { 547 it('Should fail with a long description', async function () {
543 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) 548 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
544 549
545 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 550 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
546 }) 551 })
547 552
548 it('Should fail with a long support text', async function () { 553 it('Should fail with a long support text', async function () {
549 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 554 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
550 555
551 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 556 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
552 }) 557 })
553 558
554 it('Should fail with a bad channel', async function () { 559 it('Should fail with a bad channel', async function () {
555 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) 560 const fields = { ...baseCorrectParams, channelId: 545454 }
556 561
557 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 562 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
558 }) 563 })
559 564
560 it('Should fail with too many tags', async function () { 565 it('Should fail with too many tags', async function () {
561 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) 566 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
562 567
563 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 568 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
564 }) 569 })
565 570
566 it('Should fail with a tag length too low', async function () { 571 it('Should fail with a tag length too low', async function () {
567 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) 572 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
568 573
569 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 574 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
570 }) 575 })
571 576
572 it('Should fail with a tag length too big', async function () { 577 it('Should fail with a tag length too big', async function () {
573 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 578 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
574 579
575 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 580 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
576 }) 581 })
577 582
578 it('Should fail with a bad schedule update (miss updateAt)', async function () { 583 it('Should fail with a bad schedule update (miss updateAt)', async function () {
579 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) 584 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
580 585
581 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 586 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
582 }) 587 })
583 588
584 it('Should fail with a bad schedule update (wrong updateAt)', async function () { 589 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
585 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }) 590 const fields = { ...baseCorrectParams, scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }
586 591
587 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 592 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
588 }) 593 })
589 594
590 it('Should fail with a bad originally published at param', async function () { 595 it('Should fail with a bad originally published at param', async function () {
591 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) 596 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
592 597
593 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 598 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
594 }) 599 })
@@ -672,7 +677,7 @@ describe('Test videos API validator', function () {
672 it('Should fail with a video of another server') 677 it('Should fail with a video of another server')
673 678
674 it('Shoud report the appropriate error', async function () { 679 it('Shoud report the appropriate error', async function () {
675 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 680 const fields = { ...baseCorrectParams, licence: 125 }
676 681
677 const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 682 const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
678 const error = res.body as PeerTubeProblemDocument 683 const error = res.body as PeerTubeProblemDocument