From 6c5065a011b099618681a37bd77eaa7bd3db752e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 09:43:59 +0200 Subject: Introduce server commands --- server/tests/api/check-params/config.ts | 28 ++++---- server/tests/api/check-params/live.ts | 29 ++++---- server/tests/api/check-params/plugins.ts | 7 +- server/tests/api/check-params/search.ts | 55 ++++++++-------- .../tests/api/check-params/user-notifications.ts | 20 +++--- server/tests/api/check-params/users.ts | 77 +++++++++++----------- server/tests/api/check-params/video-channels.ts | 31 ++++----- server/tests/api/check-params/video-imports.ts | 29 ++++---- server/tests/api/check-params/video-playlists.ts | 5 +- server/tests/api/check-params/videos.ts | 75 +++++++++++---------- 10 files changed, 178 insertions(+), 178 deletions(-) (limited to 'server/tests/api/check-params') 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 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import { omit } from 'lodash' import 'mocha' -import { CustomConfig } from '../../../../shared/models/server/custom-config.model' - +import { omit } from 'lodash' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, createUser, flushAndRunServer, - immutableAssign, makeDeleteRequest, makeGetRequest, makePutBodyRequest, ServerInfo, setAccessTokensToServers, userLogin -} from '../../../../shared/extra-utils' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { CustomConfig } from '@shared/models' describe('Test config API validators', function () { const path = '/api/v1/config/custom' @@ -265,11 +263,13 @@ describe('Test config API validators', function () { }) it('Should fail with a bad default NSFW policy', async function () { - const newUpdateParams = immutableAssign(updateParams, { + const newUpdateParams = { + ...updateParams, + instance: { defaultNSFWPolicy: 'hello' } - }) + } await makePutBodyRequest({ url: server.url, @@ -282,13 +282,15 @@ describe('Test config API validators', function () { it('Should fail if email disabled and signup requires email verification', async function () { // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts - const newUpdateParams = immutableAssign(updateParams, { + const newUpdateParams = { + ...updateParams, + signup: { enabled: true, limit: 5, requiresEmailVerification: true } - }) + } await makePutBodyRequest({ url: server.url, @@ -300,7 +302,9 @@ describe('Test config API validators', function () { }) it('Should fail with a disabled webtorrent & hls transcoding', async function () { - const newUpdateParams = immutableAssign(updateParams, { + const newUpdateParams = { + ...updateParams, + transcoding: { hls: { enabled: false @@ -309,7 +313,7 @@ describe('Test config API validators', function () { enabled: false } } - }) + } await makePutBodyRequest({ 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 { createUser, flushAndRunServer, getMyUserInformation, - immutableAssign, LiveCommand, makePostBodyRequest, makeUploadRequest, @@ -97,37 +96,37 @@ describe('Test video lives API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -139,7 +138,7 @@ describe('Test video lives API validator', function () { }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -155,25 +154,25 @@ describe('Test video lives API validator', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id - const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) + const fields = { ...baseCorrectParams, channelId: customChannelId } await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -215,7 +214,7 @@ describe('Test video lives API validator', function () { }) it('Should fail with save replay and permanent live set to true', async function () { - const fields = immutableAssign(baseCorrectParams, { saveReplay: true, permanentLive: true }) + const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -253,7 +252,7 @@ describe('Test video lives API validator', function () { }) it('Should forbid to save replay if not enabled by the admin', async function () { - const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) + const fields = { ...baseCorrectParams, saveReplay: true } await server.configCommand.updateCustomSubConfig({ newConfig: { @@ -274,7 +273,7 @@ describe('Test video lives API validator', function () { }) it('Should allow to save replay if enabled by the admin', async function () { - const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) + const fields = { ...baseCorrectParams, saveReplay: true } await server.configCommand.updateCustomSubConfig({ 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 { cleanupTests, createUser, flushAndRunServer, - immutableAssign, makeGetRequest, makePostBodyRequest, makePutBodyRequest, @@ -200,7 +199,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid plugin type', async function () { - const query = immutableAssign(baseQuery, { pluginType: 5 }) + const query = { ...baseQuery, pluginType: 5 } await makeGetRequest({ url: server.url, @@ -211,7 +210,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid current peertube engine', async function () { - const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' }) + const query = { ...baseQuery, currentPeerTubeEngine: '1.0' } await makeGetRequest({ url: server.url, @@ -271,7 +270,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid plugin type', async function () { - const query = immutableAssign(baseQuery, { pluginType: 5 }) + const query = { ...baseQuery, pluginType: 5 } await makeGetRequest({ 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 { checkBadStartPagination, cleanupTests, flushAndRunServer, - immutableAssign, makeGetRequest, ServerInfo, setAccessTokensToServers @@ -63,78 +62,78 @@ describe('Test videos API validator', function () { }) it('Should fail with an invalid category', async function () { - const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) + const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) + const customQuery2 = { ...query, categoryOneOf: 'a' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with a valid category', async function () { - const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) + const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) + const customQuery2 = { ...query, categoryOneOf: 1 } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should fail with an invalid licence', async function () { - const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) + const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) + const customQuery2 = { ...query, licenceOneOf: 'a' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with a valid licence', async function () { - const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) + const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) + const customQuery2 = { ...query, licenceOneOf: 1 } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should succeed with a valid language', async function () { - const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) + const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) + const customQuery2 = { ...query, languageOneOf: 'fr' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should succeed with valid tags', async function () { - const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) + const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) + const customQuery2 = { ...query, tagsOneOf: 'tag1' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) + const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] } await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) + const customQuery4 = { ...query, tagsAllOf: 'tag1' } await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should fail with invalid durations', async function () { - const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) + const customQuery1 = { ...query, durationMin: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) + const customQuery2 = { ...query, durationMax: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with invalid dates', async function () { - const customQuery1 = immutableAssign(query, { startDate: 'hello' }) + const customQuery1 = { ...query, startDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery2 = immutableAssign(query, { endDate: 'hello' }) + const customQuery2 = { ...query, endDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) + const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) + const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) }) @@ -201,41 +200,41 @@ describe('Test videos API validator', function () { for (const path of paths) { { - const customQuery = immutableAssign(query, { searchTarget: 'hello' }) + const customQuery = { ...query, searchTarget: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } { - const customQuery = immutableAssign(query, { searchTarget: undefined }) + const customQuery = { ...query, searchTarget: undefined } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } { - const customQuery = immutableAssign(query, { searchTarget: 'local' }) + const customQuery = { ...query, searchTarget: 'local' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } { - const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) + const customQuery = { ...query, searchTarget: 'search-index' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } await updateSearchIndex(server, true, true) { - const customQuery = immutableAssign(query, { searchTarget: 'local' }) + const customQuery = { ...query, searchTarget: 'local' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } { - const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) + const customQuery = { ...query, searchTarget: 'search-index' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } await updateSearchIndex(server, true, false) { - const customQuery = immutableAssign(query, { searchTarget: 'local' }) + const customQuery = { ...query, searchTarget: 'local' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } 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 @@ import 'mocha' import { io } from 'socket.io-client' - +import { HttpStatusCode } from '@shared/core-utils' import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, flushAndRunServer, - immutableAssign, makeGetRequest, makePostBodyRequest, makePutBodyRequest, ServerInfo, setAccessTokensToServers, wait -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { UserNotificationSetting, UserNotificationSettingValue } from '@shared/models' describe('Test user notifications API validators', function () { let server: ServerInfo @@ -193,7 +189,7 @@ describe('Test user notifications API validators', function () { it('Should fail with incorrect field values', async function () { { - const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 15 }) + const fields = { ...correctFields, newCommentOnMyVideo: 15 } await makePutBodyRequest({ url: server.url, @@ -205,7 +201,7 @@ describe('Test user notifications API validators', function () { } { - const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 'toto' }) + const fields = { ...correctFields, newCommentOnMyVideo: 'toto' } await makePutBodyRequest({ 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 { getMyUserVideoRating, getUserScopedTokens, getUsersList, - immutableAssign, killallServers, makeGetRequest, makePostBodyRequest, @@ -181,25 +180,25 @@ describe('Test users API validators', function () { } it('Should fail with a too small username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: '' }) + const fields = { ...baseCorrectParams, username: '' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a too long username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) + const fields = { ...baseCorrectParams, username: 'super'.repeat(50) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a not lowercase username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) + const fields = { ...baseCorrectParams, username: 'Toto' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with an incorrect username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) + const fields = { ...baseCorrectParams, username: 'my username' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -211,25 +210,25 @@ describe('Test users API validators', function () { }) it('Should fail with an invalid email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) + const fields = { ...baseCorrectParams, email: 'test_example.com' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a too small password', async function () { - const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) + const fields = { ...baseCorrectParams, password: 'bla' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a too long password', async function () { - const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) + const fields = { ...baseCorrectParams, password: 'super'.repeat(61) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with empty password and no smtp configured', async function () { - const fields = immutableAssign(baseCorrectParams, { password: '' }) + const fields = { ...baseCorrectParams, password: '' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -239,19 +238,23 @@ describe('Test users API validators', function () { await killallServers([ server ]) - const config = immutableAssign(overrideConfig, { + const config = { + ...overrideConfig, + smtp: { hostname: 'localhost', port: emailPort } - }) + } await reRunServer(server, config) - const fields = immutableAssign(baseCorrectParams, { + const fields = { + ...baseCorrectParams, + password: '', username: 'create_password', email: 'create_password@example.com' - }) + } await makePostBodyRequest({ url: server.url, @@ -263,7 +266,7 @@ describe('Test users API validators', function () { }) it('Should fail with invalid admin flags', async function () { - const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) + const fields = { ...baseCorrectParams, adminFlags: 'toto' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -279,7 +282,7 @@ describe('Test users API validators', function () { }) it('Should fail if we add a user with the same username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) + const fields = { ...baseCorrectParams, username: 'user1' } await makePostBodyRequest({ url: server.url, @@ -291,7 +294,7 @@ describe('Test users API validators', function () { }) it('Should fail if we add a user with the same email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) + const fields = { ...baseCorrectParams, email: 'user1@example.com' } await makePostBodyRequest({ url: server.url, @@ -315,13 +318,13 @@ describe('Test users API validators', function () { }) it('Should fail with an invalid videoQuota', async function () { - const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) + const fields = { ...baseCorrectParams, videoQuota: -5 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with an invalid videoQuotaDaily', async function () { - const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) + const fields = { ...baseCorrectParams, videoQuotaDaily: -7 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -333,13 +336,13 @@ describe('Test users API validators', function () { }) it('Should fail with an invalid user role', async function () { - const fields = immutableAssign(baseCorrectParams, { role: 88989 }) + const fields = { ...baseCorrectParams, role: 88989 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a "peertube" username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) + const fields = { ...baseCorrectParams, username: 'peertube' } await makePostBodyRequest({ url: server.url, @@ -352,7 +355,7 @@ describe('Test users API validators', function () { it('Should fail to create a moderator or an admin with a moderator', async function () { for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) { - const fields = immutableAssign(baseCorrectParams, { role }) + const fields = { ...baseCorrectParams, role } await makePostBodyRequest({ url: server.url, @@ -365,7 +368,7 @@ describe('Test users API validators', function () { }) it('Should succeed to create a user with a moderator', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }) + const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER } await makePostBodyRequest({ url: server.url, @@ -937,19 +940,19 @@ describe('Test users API validators', function () { } it('Should fail with a too small username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: '' }) + const fields = { ...baseCorrectParams, username: '' } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a too long username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) + const fields = { ...baseCorrectParams, username: 'super'.repeat(50) } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with an incorrect username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) + const fields = { ...baseCorrectParams, username: 'my username' } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) @@ -961,25 +964,25 @@ describe('Test users API validators', function () { }) it('Should fail with an invalid email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) + const fields = { ...baseCorrectParams, email: 'test_example.com' } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a too small password', async function () { - const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) + const fields = { ...baseCorrectParams, password: 'bla' } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a too long password', async function () { - const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) + const fields = { ...baseCorrectParams, password: 'super'.repeat(61) } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail if we register a user with the same username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'root' }) + const fields = { ...baseCorrectParams, username: 'root' } await makePostBodyRequest({ url: server.url, @@ -991,7 +994,7 @@ describe('Test users API validators', function () { }) it('Should fail with a "peertube" username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) + const fields = { ...baseCorrectParams, username: 'peertube' } await makePostBodyRequest({ url: server.url, @@ -1003,7 +1006,7 @@ describe('Test users API validators', function () { }) it('Should fail if we register a user with the same email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) + const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' } await makePostBodyRequest({ url: server.url, @@ -1015,26 +1018,26 @@ describe('Test users API validators', function () { }) it('Should fail with a bad display name', async function () { - const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) }) + const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a bad channel name', async function () { - const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } }) + const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a bad channel display name', async function () { - const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } }) + const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a channel name that is the same as username', async function () { const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } } - const fields = immutableAssign(baseCorrectParams, source) + const fields = { ...baseCorrectParams, ...source } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) @@ -1043,7 +1046,7 @@ describe('Test users API validators', function () { const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' } await server.channelsCommand.create({ attributes }) - const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) + const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } } await makePostBodyRequest({ url: server.url, @@ -1055,7 +1058,7 @@ describe('Test users API validators', function () { }) it('Should succeed with the correct params', async function () { - const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } }) + const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } } await makePostBodyRequest({ 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 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, ChannelsCommand, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createUser, flushAndRunServer, - immutableAssign, makeGetRequest, makePostBodyRequest, makePutBodyRequest, @@ -18,13 +20,8 @@ import { ServerInfo, setAccessTokensToServers, userLogin -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { VideoChannelUpdate } from '../../../../shared/models/videos' +} from '@shared/extra-utils' +import { VideoChannelUpdate } from '@shared/models' const expect = chai.expect @@ -127,7 +124,7 @@ describe('Test video channels API validator', function () { }) it('Should fail with a bad name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super name' }) + const fields = { ...baseCorrectParams, name: 'super name' } await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) @@ -137,17 +134,17 @@ describe('Test video channels API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) + const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) } await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) @@ -206,22 +203,22 @@ describe('Test video channels API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) + const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) } await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(201) } await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad bulkVideosSupportUpdate field', async function () { - const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' }) + const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' } await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) 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 { createUser, flushAndRunServer, getMyUserInformation, - immutableAssign, ImportsCommand, makeGetRequest, makePostBodyRequest, @@ -108,43 +107,43 @@ describe('Test video imports API validator', function () { }) it('Should fail with a bad target url', async function () { - const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) + const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -156,7 +155,7 @@ describe('Test video imports API validator', function () { }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -172,25 +171,25 @@ describe('Test video imports API validator', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id - const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) + const fields = { ...baseCorrectParams, channelId: customChannelId } await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -242,7 +241,7 @@ describe('Test video imports API validator', function () { it('Should fail with an invalid magnet URI', async function () { let fields = omit(baseCorrectParams, 'targetUrl') - fields = immutableAssign(fields, { magnetUri: 'blabla' }) + fields = { ...fields, magnetUri: 'blabla' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -301,7 +300,7 @@ describe('Test video imports API validator', function () { }) let fields = omit(baseCorrectParams, 'targetUrl') - fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() }) + fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() } await makePostBodyRequest({ 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 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { HttpStatusCode } from '@shared/core-utils' import { VideoPlaylistCreate, VideoPlaylistCreateResult, @@ -10,7 +11,6 @@ import { VideoPlaylistReorder, VideoPlaylistType } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { checkBadCountPagination, checkBadSortPagination, @@ -18,7 +18,6 @@ import { cleanupTests, flushAndRunServer, generateUserAccessToken, - immutableAssign, makeGetRequest, PlaylistsCommand, ServerInfo, @@ -214,7 +213,7 @@ describe('Test video playlists API validator', function () { } } const getUpdate = (params: any, playlistId: number | string) => { - return immutableAssign(params, { playlistId: playlistId }) + return { ...params, playlistId: playlistId } } 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 { getMyUserInformation, getVideo, getVideosList, - immutableAssign, makeDeleteRequest, makeGetRequest, makePutBodyRequest, @@ -225,42 +224,42 @@ describe('Test videos API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) @@ -274,7 +273,7 @@ describe('Test videos API validator', function () { }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) @@ -291,54 +290,56 @@ describe('Test videos API validator', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id - const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) + const fields = { ...baseCorrectParams, channelId: customChannelId } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad schedule update (miss updateAt)', async function () { - const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) + const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad schedule update (wrong updateAt)', async function () { - const fields = immutableAssign(baseCorrectParams, { + const fields = { + ...baseCorrectParams, + scheduleUpdate: { privacy: VideoPrivacy.PUBLIC, updateAt: 'toto' } - }) + } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad originally published at attribute', async function () { - const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) + const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) @@ -413,7 +414,7 @@ describe('Test videos API validator', function () { }) it('Should report the appropriate error', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } const attaches = baseCorrectAttaches const attributes = { ...fields, ...attaches } @@ -448,17 +449,21 @@ describe('Test videos API validator', function () { } { - const attaches = immutableAssign(baseCorrectAttaches, { + const attaches = { + ...baseCorrectAttaches, + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') - }) + } await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } { - const attaches = immutableAssign(baseCorrectAttaches, { + const attaches = { + ...baseCorrectAttaches, + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') - }) + } await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } @@ -516,79 +521,79 @@ describe('Test videos API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad schedule update (miss updateAt)', async function () { - const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) + const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad schedule update (wrong updateAt)', async function () { - const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }) + const fields = { ...baseCorrectParams, scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad originally published at param', async function () { - const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) + const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) @@ -672,7 +677,7 @@ describe('Test videos API validator', function () { it('Should fail with a video of another server') it('Shoud report the appropriate error', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) const error = res.body as PeerTubeProblemDocument -- cgit v1.2.3