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/activitypub/helpers.ts | 5 +- 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 +++++++++++---------- server/tests/api/live/live.ts | 3 +- .../api/notifications/moderation-notifications.ts | 13 ++-- .../tests/api/notifications/notifications-api.ts | 11 ++-- server/tests/api/redundancy/manage-redundancy.ts | 7 +- .../tests/api/redundancy/redundancy-constraints.ts | 11 ++-- server/tests/api/redundancy/redundancy.ts | 36 +++++----- server/tests/api/search/search-index.ts | 24 +++---- server/tests/api/search/search-videos.ts | 46 +++++++------ server/tests/api/server/handle-down.ts | 9 +-- server/tests/api/server/logs.ts | 5 +- server/tests/api/server/plugins.ts | 5 +- server/tests/api/users/users-multiple-servers.ts | 2 +- server/tests/api/videos/audio-only.ts | 5 +- server/tests/api/videos/multiple-servers.ts | 4 +- server/tests/api/videos/resumable-upload.ts | 5 +- server/tests/api/videos/single-server.ts | 2 +- server/tests/api/videos/video-captions.ts | 2 +- server/tests/api/videos/video-imports.ts | 13 ++-- server/tests/api/videos/video-transcoder.ts | 22 +++---- server/tests/cli/optimize-old-videos.ts | 3 +- server/tests/cli/prune-storage.ts | 31 +++++---- server/tests/cli/regenerate-thumbnails.ts | 5 +- server/tests/plugins/action-hooks.ts | 5 +- server/tests/plugins/external-auth.ts | 7 +- server/tests/plugins/filter-hooks.ts | 39 ++++++----- server/tests/plugins/id-and-pass-auth.ts | 13 ++-- server/tests/plugins/plugin-helpers.ts | 19 +++--- server/tests/plugins/plugin-storage.ts | 17 ++--- server/tests/plugins/plugin-transcoding.ts | 3 +- 40 files changed, 343 insertions(+), 385 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts index 66d7631b7..57b1cab23 100644 --- a/server/tests/api/activitypub/helpers.ts +++ b/server/tests/api/activitypub/helpers.ts @@ -2,11 +2,10 @@ import 'mocha' import { expect } from 'chai' -import { buildRequestStub } from '../../../../shared/extra-utils/miscs/stubs' -import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' import { cloneDeep } from 'lodash' +import { buildAbsoluteFixturePath, buildRequestStub } from '@shared/extra-utils' import { buildSignedActivity } from '../../../helpers/activitypub' -import { buildAbsoluteFixturePath } from '@shared/extra-utils' +import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' describe('Test activity pub helpers', function () { describe('When checking the Linked Signature', function () { 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 diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index f9a162df6..999a49051 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -7,7 +7,6 @@ import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe- import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - buildServerDirectory, checkLiveCleanup, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, @@ -532,7 +531,7 @@ describe('Test live', function () { } const filename = `${video.uuid}-${resolution}-fragmented.mp4` - const segmentPath = buildServerDirectory(servers[0], join('streaming-playlists', 'hls', video.uuid, filename)) + const segmentPath = servers[0].serversCommand.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) const probe = await ffprobePromise(segmentPath) const videoStream = await getVideoStreamFromFile(segmentPath, probe) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 229f78811..99b434606 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -20,7 +20,6 @@ import { createUser, generateUserAccessToken, getVideoIdFromUUID, - immutableAssign, MockInstancesIndex, MockSmtpServer, prepareNotificationsTest, @@ -347,7 +346,7 @@ describe('Test moderation notifications', function () { await checkUserRegistered(baseParams, 'user_45', 'presence') const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') + await checkUserRegistered({ ...baseParams, ...userOverride }, 'user_45', 'absence') }) }) @@ -389,7 +388,7 @@ describe('Test moderation notifications', function () { await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') + await checkNewInstanceFollower({ ...baseParams, ...userOverride }, 'localhost:' + servers[2].port, 'absence') }) it('Should send a notification on auto follow back', async function () { @@ -416,7 +415,7 @@ describe('Test moderation notifications', function () { await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') + await checkAutoInstanceFollowing({ ...baseParams, ...userOverride }, followerHost, followingHost, 'absence') config.followings.instance.autoFollowBack.enabled = false await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) @@ -476,7 +475,9 @@ describe('Test moderation notifications', function () { currentCustomConfig = await servers[0].configCommand.getCustomConfig() - const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { + const autoBlacklistTestsCustomConfig = { + ...currentCustomConfig, + autoBlacklist: { videos: { ofUsers: { @@ -484,7 +485,7 @@ describe('Test moderation notifications', function () { } } } - }) + } // enable transcoding otherwise own publish notification after transcoding not expected autoBlacklistTestsCustomConfig.transcoding.enabled = true diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 447492c5f..e5864f1c2 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -8,7 +8,6 @@ import { cleanupTests, getAllNotificationsSettings, getMyUserInformation, - immutableAssign, MockSmtpServer, prepareNotificationsTest, ServerInfo, @@ -118,7 +117,7 @@ describe('Test notifications API', function () { const { name, uuid } = await uploadRandomVideo(server) const check = { web: true, mail: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') }) it('Should only have web notifications', async function () { @@ -139,12 +138,12 @@ describe('Test notifications API', function () { { const check = { mail: true, web: false } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') } { const check = { mail: false, web: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') } }) @@ -166,12 +165,12 @@ describe('Test notifications API', function () { { const check = { mail: false, web: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') } { const check = { mail: true, web: false } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') } }) diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index 363e4cbfe..03857f512 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -12,8 +12,7 @@ import { setAccessTokensToServers, uploadVideo, uploadVideoAndGetId, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' @@ -91,7 +90,7 @@ describe('Test manage videos redundancy', function () { this.timeout(120000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 10) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 10) await waitJobs(servers) const body = await commands[1].listVideos({ target: 'remote-videos' }) @@ -214,7 +213,7 @@ describe('Test manage videos redundancy', function () { await commands[0].addVideo({ videoId }) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 15) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 15) await waitJobs(servers) { diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 82d952471..a31278de7 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -11,8 +11,7 @@ import { setAccessTokensToServers, updateVideo, uploadVideo, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -97,7 +96,7 @@ describe('Test redundancy constraints', function () { this.timeout(120000) await waitJobs(servers) - await waitUntilLog(remoteServer, 'Duplicated ', 5) + await remoteServer.serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) { @@ -126,7 +125,7 @@ describe('Test redundancy constraints', function () { await uploadWrapper('video 2 server 2') - await waitUntilLog(remoteServer, 'Duplicated ', 10) + await remoteServer.serversCommand.waitUntilLog('Duplicated ', 10) await waitJobs(servers) { @@ -155,7 +154,7 @@ describe('Test redundancy constraints', function () { await uploadWrapper('video 3 server 2') - await waitUntilLog(remoteServer, 'Duplicated ', 15) + await remoteServer.serversCommand.waitUntilLog('Duplicated ', 15) await waitJobs(servers) { @@ -176,7 +175,7 @@ describe('Test redundancy constraints', function () { await waitJobs(servers) await uploadWrapper('video 4 server 2') - await waitUntilLog(remoteServer, 'Duplicated ', 20) + await remoteServer.serversCommand.waitUntilLog('Duplicated ', 20) await waitJobs(servers) { diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 56a2af395..00a5e86cc 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -14,7 +14,6 @@ import { flushAndRunMultipleServers, getVideo, getVideoWithToken, - immutableAssign, killallServers, makeGetRequest, removeVideo, @@ -26,8 +25,7 @@ import { uploadVideo, viewVideo, wait, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' @@ -53,11 +51,13 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add if (strategy !== null) { strategies.push( - immutableAssign({ + { min_lifetime: '1 hour', strategy: strategy, - size: '400KB' - }, additionalParams) + size: '400KB', + + ...additionalParams + } ) } @@ -316,7 +316,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -335,7 +335,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos', join('playlists', 'hls') ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos', join('playlists', 'hls') ]) }) after(async function () { @@ -366,7 +366,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -385,7 +385,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos' ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) }) after(async function () { @@ -438,7 +438,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -454,7 +454,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) for (const server of servers) { - await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(video1Server2UUID, server) } }) @@ -502,7 +502,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 1) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 1) await waitJobs(servers) await check1PlaylistRedundancies() @@ -517,7 +517,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) for (const server of servers) { - await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(video1Server2UUID, server) } }) @@ -547,7 +547,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -575,7 +575,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) }) after(async function () { @@ -658,7 +658,7 @@ describe('Test videos redundancy', function () { await enableRedundancyOnServer1() await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds(video1Server2UUID) @@ -715,7 +715,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ join('redundancy', 'hls') ]) }) after(async function () { diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index e4c5f5796..306f84c3a 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,16 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - flushAndRunServer, - immutableAssign, - SearchCommand, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '@shared/extra-utils' -import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' +import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' +import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect @@ -174,32 +166,32 @@ describe('Test videos search', function () { } { - const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' }) + const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' } await check(search, false) } { - const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] }) + const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] } await check(search, false) } { - const search = immutableAssign(baseSearch, { durationMin: 2000 }) + const search = { ...baseSearch, durationMin: 2000 } await check(search, false) } { - const search = immutableAssign(baseSearch, { nsfw: 'true' }) + const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery } await check(search, false) } { - const search = immutableAssign(baseSearch, { nsfw: 'false' }) + const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery } await check(search, true) } { - const search = immutableAssign(baseSearch, { nsfw: 'both' }) + const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } await check(search, true) } }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 513538917..66f5f3182 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunServer, - immutableAssign, SearchCommand, ServerInfo, setAccessTokensToServers, @@ -44,11 +43,11 @@ describe('Test videos search', function () { } await uploadVideo(server.url, server.accessToken, attributes1) - const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }) + const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } await uploadVideo(server.url, server.accessToken, attributes2) { - const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined }) + const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } const res = await uploadVideo(server.url, server.accessToken, attributes3) const videoId = res.body.video.id videoUUID = res.body.video.uuid @@ -68,26 +67,23 @@ describe('Test videos search', function () { }) } - const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true }) + const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } await uploadVideo(server.url, server.accessToken, attributes4) await wait(1000) startDate = new Date().toISOString() - const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined }) + const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } await uploadVideo(server.url, server.accessToken, attributes5) - const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }) + const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } await uploadVideo(server.url, server.accessToken, attributes6) - const attributes7 = immutableAssign(attributes1, { - name: attributes1.name + ' - 7', - originallyPublishedAt: '2019-02-12T09:58:08.286Z' - }) + const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } await uploadVideo(server.url, server.accessToken, attributes7) - const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) + const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } await uploadVideo(server.url, server.accessToken, attributes8) } @@ -101,7 +97,7 @@ describe('Test videos search', function () { } await uploadVideo(server.url, server.accessToken, attributes) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' })) + await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' }) } { @@ -122,10 +118,10 @@ describe('Test videos search', function () { category: 1 } await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) + await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] })) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] })) + await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] }) + await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] }) } { @@ -134,7 +130,7 @@ describe('Test videos search', function () { category: 1 } await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) + await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) } command = server.searchCommand @@ -414,7 +410,7 @@ describe('Test videos search', function () { } { - const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) + const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(1) @@ -422,7 +418,7 @@ describe('Test videos search', function () { } { - const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) + const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(1) @@ -430,34 +426,36 @@ describe('Test videos search', function () { } { - const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) + const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(0) } { - const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) + const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(0) } { - const query = immutableAssign(baseQuery, { + const query = { + ...baseQuery, originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' - }) + } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(0) } { - const query = immutableAssign(baseQuery, { + const query = { + ...baseQuery, originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' - }) + } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(1) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index dd06acb5e..d45c3ae8a 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -10,7 +10,6 @@ import { flushAndRunMultipleServers, getVideo, getVideosList, - immutableAssign, killallServers, reRunServer, ServerInfo, @@ -50,9 +49,7 @@ describe('Test handle downs', function () { fixture: 'video_short1.webm' } - const unlistedVideoAttributes = immutableAssign(videoAttributes, { - privacy: VideoPrivacy.UNLISTED - }) + const unlistedVideoAttributes = { ...videoAttributes, privacy: VideoPrivacy.UNLISTED } let checkAttributes: any let unlistedCheckAttributes: any @@ -97,9 +94,7 @@ describe('Test handle downs', function () { } ] } - unlistedCheckAttributes = immutableAssign(checkAttributes, { - privacy: VideoPrivacy.UNLISTED - }) + unlistedCheckAttributes = { ...checkAttributes, privacy: VideoPrivacy.UNLISTED } // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index 365f6cc2b..096d63e21 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -7,7 +7,6 @@ import { flushAndRunServer, killallServers, LogsCommand, - makePingRequest, reRunServer, ServerInfo, setAccessTokensToServers, @@ -102,7 +101,7 @@ describe('Test logs', function () { const now = new Date() - await makePingRequest(server) + await server.serversCommand.ping() const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) const logsString = JSON.stringify(body) @@ -119,7 +118,7 @@ describe('Test logs', function () { const now = new Date() - await makePingRequest(server) + await server.serversCommand.ping() const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) const logsString = JSON.stringify(body) diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index d4a43276f..a81ac961a 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -14,8 +14,7 @@ import { setAccessTokensToServers, testHelloWorldRegisteredSettings, updateMyUser, - wait, - waitUntilLog + wait } from '@shared/extra-utils' import { PluginType, User } from '@shared/models' @@ -194,7 +193,7 @@ describe('Test plugins', function () { it('Should have watched settings changes', async function () { this.timeout(10000) - await waitUntilLog(server, 'Settings changed!') + await server.serversCommand.waitUntilLog('Settings changed!') }) it('Should get a plugin and a theme', async function () { diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 47056be78..7b650cb8f 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -227,7 +227,7 @@ describe('Test users with multiple servers', function () { it('Should not have video files', async () => { for (const server of servers) { - await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(videoUUID, server) } }) diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index 7ddbd5cd9..9b516af81 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' import { - buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -81,8 +80,8 @@ describe('Test audio only video transcoding', function () { it('0p transcoded video should not have video', async function () { const paths = [ - buildServerDirectory(servers[0], join('videos', videoUUID + '-0.mp4')), - buildServerDirectory(servers[0], join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) + servers[0].serversCommand.buildDirectory(join('videos', videoUUID + '-0.mp4')), + servers[0].serversCommand.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) ] for (const path of paths) { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 1b6f0f48a..1905aac83 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -689,8 +689,8 @@ describe('Test multiple servers', function () { it('Should not have files of videos 3 and 3-2 on each server', async function () { for (const server of servers) { - await checkVideoFilesWereRemoved(toRemove[0].uuid, server.internalServerNumber) - await checkVideoFilesWereRemoved(toRemove[1].uuid, server.internalServerNumber) + await checkVideoFilesWereRemoved(toRemove[0].uuid, server) + await checkVideoFilesWereRemoved(toRemove[1].uuid, server) } }) diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 6c01c7e78..5845efc86 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -7,7 +7,6 @@ import { join } from 'path' import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, - buildServerDirectory, cleanupTests, flushAndRunServer, getMyUserInformation, @@ -82,7 +81,7 @@ describe('Test resumable upload', function () { const uploadId = uploadIdArg.replace(/^upload_id=/, '') const subPath = join('tmp', 'resumable-uploads', uploadId) - const filePath = buildServerDirectory(server, subPath) + const filePath = server.serversCommand.buildDirectory(subPath) const exists = await pathExists(filePath) if (expectedSize === null) { @@ -97,7 +96,7 @@ describe('Test resumable upload', function () { async function countResumableUploads () { const subPath = join('tmp', 'resumable-uploads') - const filePath = buildServerDirectory(server, subPath) + const filePath = server.serversCommand.buildDirectory(subPath) const files = await readdir(filePath) return files.length diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 1058a1e9c..af1703e02 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -230,7 +230,7 @@ describe('Test a single server', function () { it('Should remove the video', async function () { await removeVideo(server.url, server.accessToken, videoId) - await checkVideoFilesWereRemoved(videoUUID, 1) + await checkVideoFilesWereRemoved(videoUUID, server) }) it('Should not have videos', async function () { diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 83ee809b8..d4a5385ab 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -182,7 +182,7 @@ describe('Test video captions', function () { it('Should remove the video, and thus all video captions', async function () { await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) - await checkVideoFilesWereRemoved(videoUUID, 1) + await checkVideoFilesWereRemoved(videoUUID, servers[0]) }) after(async function () { diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 4f9ecbe8e..f6ae8cab1 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -11,7 +11,6 @@ import { getMyVideos, getVideo, getVideosList, - immutableAssign, ImportsCommand, ServerInfo, setAccessTokensToServers, @@ -119,7 +118,7 @@ describe('Test video imports', function () { } { - const attributes = immutableAssign(baseAttributes, { targetUrl: ImportsCommand.getYoutubeVideoUrl() }) + const attributes = { ...baseAttributes, targetUrl: ImportsCommand.getYoutubeVideoUrl() } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('small video - youtube') @@ -169,21 +168,23 @@ Ajouter un sous-titre est vraiment facile`) } { - const attributes = immutableAssign(baseAttributes, { + const attributes = { + ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI(), description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] - }) + } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('super peertube2 video') } { - const attributes = immutableAssign(baseAttributes, { + const attributes = { + ...baseAttributes, torrentfile: 'video-720p.torrent' as any, description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] - }) + } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('你好 世界 720p.mp4') } diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index e74fb5bef..f16b22bae 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -9,14 +9,12 @@ import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { buildAbsoluteFixturePath, - buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, getMyVideos, - getServerFileSize, getVideo, getVideoFileMetadataUrl, getVideosList, @@ -285,7 +283,7 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(4) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) if (probe.audioStream) { @@ -316,7 +314,7 @@ describe('Test video transcoding', function () { const videoDetails: VideoDetails = res2.body expect(videoDetails.files).to.have.lengthOf(4) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) expect(probe).to.not.have.property('audioStream') } @@ -344,7 +342,7 @@ describe('Test video transcoding', function () { const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const videoProbe = await getAudioStream(path) @@ -506,13 +504,13 @@ describe('Test video transcoding', function () { expect(videoDetails.files[3].fps).to.be.below(31) for (const resolution of [ '240', '360', '480' ]) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.below(31) } - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.above(58).and.below(62) @@ -547,13 +545,13 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(25) } { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(59) } @@ -590,7 +588,7 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) for (const resolution of [ '240', '360', '480', '720', '1080' ]) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) @@ -636,7 +634,7 @@ describe('Test video transcoding', function () { const resolutions = [ 240, 360, 480, 720, 1080 ] for (const r of resolutions) { const path = `videos/${videoUUID}-${r}.mp4` - const size = await getServerFileSize(servers[1], path) + const size = await servers[1].serversCommand.getServerFileSize(path) expect(size, `${path} not below ${60_000}`).to.be.below(60_000) } }) @@ -651,7 +649,7 @@ describe('Test video transcoding', function () { await waitJobs(servers) { - const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) const metadata = await getMetadataFromFile(path) // expected format properties diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts index bd15012fe..e369a3305 100644 --- a/server/tests/cli/optimize-old-videos.ts +++ b/server/tests/cli/optimize-old-videos.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { - buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -96,7 +95,7 @@ describe('Test optimize old videos', function () { expect(file.size).to.be.below(8000000) - const path = buildServerDirectory(servers[0], join('videos', video.uuid + '-' + file.resolution.id + '.mp4')) + const path = servers[0].serversCommand.buildDirectory(join('videos', video.uuid + '-' + file.resolution.id + '.mp4')) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) const resolution = await getVideoFileResolution(path) diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index d4dbee682..68a59a41d 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts @@ -7,7 +7,6 @@ import { join } from 'path' import { buildUUID } from '@server/helpers/uuid' import { HttpStatusCode } from '@shared/core-utils' import { - buildServerDirectory, cleanupTests, CLICommand, doubleFollow, @@ -26,14 +25,14 @@ import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect -async function countFiles (internalServerNumber: number, directory: string) { - const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) +async function countFiles (server: ServerInfo, directory: string) { + const files = await readdir(server.serversCommand.buildDirectory(directory)) return files.length } -async function assertNotExists (internalServerNumber: number, directory: string, substring: string) { - const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) +async function assertNotExists (server: ServerInfo, directory: string, substring: string) { + const files = await readdir(server.serversCommand.buildDirectory(directory)) for (const f of files) { expect(f).to.not.contain(substring) @@ -42,19 +41,19 @@ async function assertNotExists (internalServerNumber: number, directory: string, async function assertCountAreOkay (servers: ServerInfo[]) { for (const server of servers) { - const videosCount = await countFiles(server.internalServerNumber, 'videos') + const videosCount = await countFiles(server, 'videos') expect(videosCount).to.equal(8) - const torrentsCount = await countFiles(server.internalServerNumber, 'torrents') + const torrentsCount = await countFiles(server, 'torrents') expect(torrentsCount).to.equal(16) - const previewsCount = await countFiles(server.internalServerNumber, 'previews') + const previewsCount = await countFiles(server, 'previews') expect(previewsCount).to.equal(2) - const thumbnailsCount = await countFiles(server.internalServerNumber, 'thumbnails') + const thumbnailsCount = await countFiles(server, 'thumbnails') expect(thumbnailsCount).to.equal(6) - const avatarsCount = await countFiles(server.internalServerNumber, 'avatars') + const avatarsCount = await countFiles(server, 'avatars') expect(avatarsCount).to.equal(2) } } @@ -122,7 +121,7 @@ describe('Test prune storage scripts', function () { it('Should create some dirty files', async function () { for (let i = 0; i < 2; i++) { { - const base = buildServerDirectory(servers[0], 'videos') + const base = servers[0].serversCommand.buildDirectory('videos') const n1 = buildUUID() + '.mp4' const n2 = buildUUID() + '.webm' @@ -134,7 +133,7 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0], 'torrents') + const base = servers[0].serversCommand.buildDirectory('torrents') const n1 = buildUUID() + '-240.torrent' const n2 = buildUUID() + '-480.torrent' @@ -146,7 +145,7 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0], 'thumbnails') + const base = servers[0].serversCommand.buildDirectory('thumbnails') const n1 = buildUUID() + '.jpg' const n2 = buildUUID() + '.jpg' @@ -158,7 +157,7 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0], 'previews') + const base = servers[0].serversCommand.buildDirectory('previews') const n1 = buildUUID() + '.jpg' const n2 = buildUUID() + '.jpg' @@ -170,7 +169,7 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0], 'avatars') + const base = servers[0].serversCommand.buildDirectory('avatars') const n1 = buildUUID() + '.png' const n2 = buildUUID() + '.jpg' @@ -195,7 +194,7 @@ describe('Test prune storage scripts', function () { for (const directory of Object.keys(badNames)) { for (const name of badNames[directory]) { - await assertNotExists(servers[0].internalServerNumber, directory, name) + await assertNotExists(servers[0], directory, name) } } }) diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts index 1b460e9c0..68a4711b6 100644 --- a/server/tests/cli/regenerate-thumbnails.ts +++ b/server/tests/cli/regenerate-thumbnails.ts @@ -4,7 +4,6 @@ import { writeFile } from 'fs-extra' import { basename, join } from 'path' import { Video, VideoDetails } from '@shared/models' import { - buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -50,7 +49,7 @@ describe('Test regenerate thumbnails script', function () { const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body)) - thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath)) + thumbnail1Path = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(video1.thumbnailPath)) const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body)) @@ -62,7 +61,7 @@ describe('Test regenerate thumbnails script', function () { remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body)) - thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath)) + thumbnailRemotePath = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath)) } await writeFile(thumbnail1Path, '') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index bcf773854..cf81e44b7 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -22,8 +22,7 @@ import { flushAndRunMultipleServers, killallServers, reRunServer, - ServerInfo, - waitUntilLog + ServerInfo } from '../../../shared/extra-utils/server/servers' describe('Test plugin action hooks', function () { @@ -32,7 +31,7 @@ describe('Test plugin action hooks', function () { let threadId: number function checkHook (hook: ServerHookName) { - return waitUntilLog(servers[0], 'Run hook ' + hook) + return servers[0].serversCommand.waitUntilLog('Run hook ' + hook) } before(async function () { diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index 09a107ca2..f7cee588a 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -17,8 +17,7 @@ import { setAccessTokensToServers, updateMyUser, userLogin, - wait, - waitUntilLog + wait } from '@shared/extra-utils' import { User, UserRole } from '@shared/models' @@ -127,7 +126,7 @@ describe('Test external auth plugins', function () { await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) - await waitUntilLog(server, 'expired external auth token', 2) + await server.serversCommand.waitUntilLog('expired external auth token', 2) }) it('Should auto login Cyan, create the user and use the token', async function () { @@ -217,7 +216,7 @@ describe('Test external auth plugins', function () { }) it('Should have logged out Cyan', async function () { - await waitUntilLog(server, 'On logout cyan') + await server.serversCommand.waitUntilLog('On logout cyan') await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401) }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index c235508e8..b5e29d298 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -24,8 +24,7 @@ import { updateVideo, uploadVideo, uploadVideoAndGetId, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' @@ -475,8 +474,8 @@ describe('Test plugin filter hooks', function () { } }) - await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1) }) it('Should run filter:api.search.videos.index.list.{params,result}', async function () { @@ -487,10 +486,10 @@ describe('Test plugin filter hooks', function () { } }) - await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1) }) it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { @@ -500,8 +499,8 @@ describe('Test plugin filter hooks', function () { } }) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1) }) it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { @@ -512,10 +511,10 @@ describe('Test plugin filter hooks', function () { } }) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1) }) it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { @@ -525,8 +524,8 @@ describe('Test plugin filter hooks', function () { } }) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1) }) it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { @@ -537,10 +536,10 @@ describe('Test plugin filter hooks', function () { } }) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.params', 1) - await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1) + await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1) }) }) diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 99de28d3f..a0b31bc1f 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -15,8 +15,7 @@ import { setAccessTokensToServers, updateMyUser, userLogin, - wait, - waitUntilLog + wait } from '@shared/extra-utils' import { User, UserRole } from '@shared/models' @@ -137,7 +136,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should have logged out Crash', async function () { - await waitUntilLog(server, 'On logout for auth 1 - 2') + await server.serversCommand.waitUntilLog('On logout for auth 1 - 2') await getMyUserInformation(server.url, crashAccessToken, 401) }) @@ -164,16 +163,16 @@ describe('Test id and pass auth plugins', function () { it('Should reject an invalid username, email, role or display name', async function () { await userLogin(server, { username: 'ward', password: 'ward password' }, 400) - await waitUntilLog(server, 'valid username') + await server.serversCommand.waitUntilLog('valid username') await userLogin(server, { username: 'kiros', password: 'kiros password' }, 400) - await waitUntilLog(server, 'valid display name') + await server.serversCommand.waitUntilLog('valid display name') await userLogin(server, { username: 'raine', password: 'raine password' }, 400) - await waitUntilLog(server, 'valid role') + await server.serversCommand.waitUntilLog('valid role') await userLogin(server, { username: 'ellone', password: 'elonne password' }, 400) - await waitUntilLog(server, 'valid email') + await server.serversCommand.waitUntilLog('valid email') }) it('Should unregister spyro-auth and do not login existing Spyro', async function () { diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 0e0f61638..cbb6887eb 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -17,8 +17,7 @@ import { setAccessTokensToServers, uploadVideoAndGetId, viewVideo, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' function postCommand (server: ServerInfo, command: string, bodyArg?: object) { @@ -50,22 +49,22 @@ describe('Test plugin helpers', function () { describe('Logger', function () { it('Should have logged things', async function () { - await waitUntilLog(servers[0], 'localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false) - await waitUntilLog(servers[0], 'Hello world from plugin four', 1) + await servers[0].serversCommand.waitUntilLog('localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false) + await servers[0].serversCommand.waitUntilLog('Hello world from plugin four', 1) }) }) describe('Database', function () { it('Should have made a query', async function () { - await waitUntilLog(servers[0], `root email is admin${servers[0].internalServerNumber}@example.com`) + await servers[0].serversCommand.waitUntilLog(`root email is admin${servers[0].internalServerNumber}@example.com`) }) }) describe('Config', function () { it('Should have the correct webserver url', async function () { - await waitUntilLog(servers[0], `server url is http://localhost:${servers[0].port}`) + await servers[0].serversCommand.waitUntilLog(`server url is http://localhost:${servers[0].port}`) }) it('Should have the correct config', async function () { @@ -83,7 +82,7 @@ describe('Test plugin helpers', function () { describe('Server', function () { it('Should get the server actor', async function () { - await waitUntilLog(servers[0], 'server actor name is peertube') + await servers[0].serversCommand.waitUntilLog('server actor name is peertube') }) }) @@ -248,7 +247,7 @@ describe('Test plugin helpers', function () { // Should delete the video await viewVideo(servers[0].url, videoUUID) - await waitUntilLog(servers[0], 'Video deleted by plugin four.') + await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.') try { // Should throw because the video should have been deleted @@ -258,11 +257,11 @@ describe('Test plugin helpers', function () { if (err.message.includes('exists')) throw err } - await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber) + await checkVideoFilesWereRemoved(videoUUID, servers[0]) }) it('Should have fetched the video by URL', async function () { - await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`) + await servers[0].serversCommand.waitUntilLog(`video from DB uuid is ${videoUUID}`) }) }) diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 4c65463f2..9babfc83e 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts @@ -5,16 +5,7 @@ import { expect } from 'chai' import { pathExists, readdir, readFile } from 'fs-extra' import { join } from 'path' import { HttpStatusCode } from '@shared/core-utils' -import { - buildServerDirectory, - cleanupTests, - flushAndRunServer, - makeGetRequest, - PluginsCommand, - ServerInfo, - setAccessTokensToServers, - waitUntilLog -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' describe('Test plugin storage', function () { let server: ServerInfo @@ -31,7 +22,7 @@ describe('Test plugin storage', function () { describe('DB storage', function () { it('Should correctly store a subkey', async function () { - await waitUntilLog(server, 'superkey stored value is toto') + await server.serversCommand.waitUntilLog('superkey stored value is toto') }) }) @@ -47,12 +38,12 @@ describe('Test plugin storage', function () { } before(function () { - dataPath = buildServerDirectory(server, 'plugins/data') + dataPath = server.serversCommand.buildDirectory('plugins/data') pluginDataPath = join(dataPath, 'peertube-plugin-test-six') }) it('Should have created the directory on install', async function () { - const dataPath = buildServerDirectory(server, 'plugins/data') + const dataPath = server.serversCommand.buildDirectory('plugins/data') const pluginDataPath = join(dataPath, 'peertube-plugin-test-six') expect(await pathExists(dataPath)).to.be.true diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index ca4d9f962..4839e8792 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -5,7 +5,6 @@ import { expect } from 'chai' import { join } from 'path' import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' import { - buildServerDirectory, cleanupTests, flushAndRunServer, getVideo, @@ -247,7 +246,7 @@ describe('Test transcoding plugins', function () { const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid await waitJobs([ server ]) - const path = buildServerDirectory(server, join('videos', videoUUID + '-240.mp4')) + const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) const audioProbe = await getAudioStream(path) expect(audioProbe.audioStream.codec_name).to.equal('opus') -- cgit v1.2.3