From af971e06c620bd46a5aa64c8833364e7022b5e3d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:22:51 +0200 Subject: Introduce search command --- server/tests/plugins/filter-hooks.ts | 62 +++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 25 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 644b41dea..e2ec5457b 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -2,17 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels' -import { ServerConfig } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { addVideoCommentReply, addVideoCommentThread, - advancedVideoPlaylistSearch, - advancedVideosSearch, + cleanupTests, createLive, createVideoPlaylist, doubleFollow, + flushAndRunMultipleServers, getAccountVideos, getConfig, getMyVideos, @@ -28,17 +26,19 @@ import { installPlugin, makeRawRequest, registerUser, + ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, updateCustomSubConfig, updateVideo, uploadVideo, uploadVideoAndGetId, - waitJobs -} from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' -import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' + waitJobs, + waitUntilLog +} from '@shared/extra-utils' +import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' import { + ServerConfig, VideoCommentThreadTree, VideoDetails, VideoImport, @@ -46,7 +46,7 @@ import { VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy -} from '../../../shared/models/videos' +} from '@shared/models' const expect = chai.expect @@ -486,8 +486,10 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.videos.local.list.{params,result}', async function () { - await advancedVideosSearch(servers[0].url, { - search: 'Sun Quan' + await servers[0].searchCommand.advancedVideoSearch({ + search: { + search: 'Sun Quan' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) @@ -495,9 +497,11 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.videos.index.list.{params,result}', async function () { - await advancedVideosSearch(servers[0].url, { - search: 'Sun Quan', - searchTarget: 'search-index' + await servers[0].searchCommand.advancedVideoSearch({ + search: { + search: 'Sun Quan', + searchTarget: 'search-index' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) @@ -507,8 +511,10 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { - await advancedVideoChannelSearch(servers[0].url, { - search: 'Sun Ce' + await servers[0].searchCommand.advancedChannelSearch({ + search: { + search: 'Sun Ce' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) @@ -516,9 +522,11 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { - await advancedVideoChannelSearch(servers[0].url, { - search: 'Sun Ce', - searchTarget: 'search-index' + await servers[0].searchCommand.advancedChannelSearch({ + search: { + search: 'Sun Ce', + searchTarget: 'search-index' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) @@ -528,8 +536,10 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { - await advancedVideoPlaylistSearch(servers[0].url, { - search: 'Sun Jian' + await servers[0].searchCommand.advancedPlaylistSearch({ + search: { + search: 'Sun Jian' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) @@ -537,9 +547,11 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { - await advancedVideoPlaylistSearch(servers[0].url, { - search: 'Sun Jian', - searchTarget: 'search-index' + await servers[0].searchCommand.advancedPlaylistSearch({ + search: { + search: 'Sun Jian', + searchTarget: 'search-index' + } }) await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) -- cgit v1.2.3 From ae2abfd3aed3e75d39a316b49b914d187faa7475 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 10:33:49 +0200 Subject: Introduce plugins command --- server/tests/plugins/action-hooks.ts | 9 ++---- server/tests/plugins/external-auth.ts | 47 +++++++++++------------------- server/tests/plugins/filter-hooks.ts | 16 ++-------- server/tests/plugins/html-injection.ts | 33 +++++++++------------ server/tests/plugins/id-and-pass-auth.ts | 36 ++++++++++------------- server/tests/plugins/plugin-helpers.ts | 24 +++++++-------- server/tests/plugins/plugin-router.ts | 27 +++++++---------- server/tests/plugins/plugin-storage.ts | 29 ++++++------------ server/tests/plugins/plugin-transcoding.ts | 26 ++++++----------- server/tests/plugins/plugin-unloading.ts | 32 ++++---------------- server/tests/plugins/translations.ts | 46 +++++++++++------------------ server/tests/plugins/video-constants.ts | 28 +++++++++--------- 12 files changed, 125 insertions(+), 228 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 0f57ef7fe..0de5b523b 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -11,8 +11,7 @@ import { createUser, createVideoPlaylist, deleteVideoComment, - getPluginTestPath, - installPlugin, + PluginsCommand, registerUser, removeUser, setAccessTokensToServers, @@ -49,11 +48,7 @@ describe('Test plugin action hooks', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await installPlugin({ - url: servers[0].url, - accessToken: servers[0].accessToken, - path: getPluginTestPath() - }) + await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) killallServers([ servers[0] ]) diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index 5addb45c7..424302786 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -2,27 +2,26 @@ import 'mocha' import { expect } from 'chai' -import { ServerConfig, User, UserRole } from '@shared/models' +import { HttpStatusCode } from '@shared/core-utils' import { + cleanupTests, + createUser, decodeQueryString, + flushAndRunServer, getConfig, - getExternalAuth, getMyUserInformation, - getPluginTestPath, - installPlugin, loginUsingExternalToken, logout, + PluginsCommand, refreshToken, + ServerInfo, setAccessTokensToServers, - uninstallPlugin, updateMyUser, - wait, userLogin, - updatePluginSettings, - createUser -} from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' + wait, + waitUntilLog +} from '@shared/extra-utils' +import { ServerConfig, User, UserRole } from '@shared/models' async function loginExternal (options: { server: ServerInfo @@ -33,13 +32,12 @@ async function loginExternal (options: { statusCodeExpected?: HttpStatusCode statusCodeExpectedStep2?: HttpStatusCode }) { - const res = await getExternalAuth({ - url: options.server.url, + const res = await options.server.pluginsCommand.getExternalAuth({ npmName: options.npmName, npmVersion: '0.0.1', authName: options.authName, query: options.query, - statusCodeExpected: options.statusCodeExpected || HttpStatusCode.FOUND_302 + expectedStatus: options.statusCodeExpected || HttpStatusCode.FOUND_302 }) if (res.status !== HttpStatusCode.FOUND_302) return @@ -75,11 +73,7 @@ describe('Test external auth plugins', function () { await setAccessTokensToServers([ server ]) for (const suffix of [ 'one', 'two', 'three' ]) { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-external-auth-' + suffix) - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-external-auth-' + suffix) }) } }) @@ -98,15 +92,14 @@ describe('Test external auth plugins', function () { }) it('Should redirect for a Cyan login', async function () { - const res = await getExternalAuth({ - url: server.url, + const res = await server.pluginsCommand.getExternalAuth({ npmName: 'test-external-auth-one', npmVersion: '0.0.1', authName: 'external-auth-1', query: { username: 'cyan' }, - statusCodeExpected: HttpStatusCode.FOUND_302 + expectedStatus: HttpStatusCode.FOUND_302 }) const location = res.header.location @@ -275,9 +268,7 @@ describe('Test external auth plugins', function () { }) it('Should unregister external-auth-2 and do not login existing Kefka', async function () { - await updatePluginSettings({ - url: server.url, - accessToken: server.accessToken, + await server.pluginsCommand.updateSettings({ npmName: 'peertube-plugin-test-external-auth-one', settings: { disableKefka: true } }) @@ -309,11 +300,7 @@ describe('Test external auth plugins', function () { }) it('Should uninstall the plugin one and do not login Cyan', async function () { - await uninstallPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-test-external-auth-one' - }) + await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-external-auth-one' }) await loginExternal({ server, diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index e2ec5457b..c51e96ab7 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -14,7 +14,6 @@ import { getAccountVideos, getConfig, getMyVideos, - getPluginTestPath, getVideo, getVideoChannelVideos, getVideoCommentThreads, @@ -23,8 +22,8 @@ import { getVideosListPagination, getVideoThreadComments, getVideoWithToken, - installPlugin, makeRawRequest, + PluginsCommand, registerUser, ServerInfo, setAccessTokensToServers, @@ -63,17 +62,8 @@ describe('Test plugin filter hooks', function () { await setDefaultVideoChannel(servers) await doubleFollow(servers[0], servers[1]) - await installPlugin({ - url: servers[0].url, - accessToken: servers[0].accessToken, - path: getPluginTestPath() - }) - - await installPlugin({ - url: servers[0].url, - accessToken: servers[0].accessToken, - path: getPluginTestPath('-filter-translations') - }) + await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) + await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) for (let i = 0; i < 10; i++) { await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts index 4fa8caa3a..80d67ae0e 100644 --- a/server/tests/plugins/html-injection.ts +++ b/server/tests/plugins/html-injection.ts @@ -5,30 +5,31 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunServer, - getPluginsCSS, - installPlugin, makeHTMLRequest, + PluginsCommand, ServerInfo, - setAccessTokensToServers, - uninstallPlugin + setAccessTokensToServers } from '../../../shared/extra-utils' const expect = chai.expect describe('Test plugins HTML injection', function () { let server: ServerInfo = null + let command: PluginsCommand before(async function () { this.timeout(30000) server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) + + command = server.pluginsCommand }) it('Should not inject global css file in HTML', async function () { { - const res = await getPluginsCSS(server.url) - expect(res.text).to.be.empty + const text = await command.getCSS() + expect(text).to.be.empty } for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { @@ -40,17 +41,13 @@ describe('Test plugins HTML injection', function () { it('Should install a plugin and a theme', async function () { this.timeout(30000) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) + await command.install({ npmName: 'peertube-plugin-hello-world' }) }) it('Should have the correct global css', async function () { { - const res = await getPluginsCSS(server.url) - expect(res.text).to.contain('background-color: red') + const text = await command.getCSS() + expect(text).to.contain('background-color: red') } for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { @@ -60,15 +57,11 @@ describe('Test plugins HTML injection', function () { }) it('Should have an empty global css on uninstall', async function () { - await uninstallPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) + await command.uninstall({ npmName: 'peertube-plugin-hello-world' }) { - const res = await getPluginsCSS(server.url) - expect(res.text).to.be.empty + const text = await command.getCSS() + expect(text).to.be.empty } for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index cbba638c2..545968040 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -1,21 +1,25 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' +import { expect } from 'chai' import { + cleanupTests, + flushAndRunServer, + getConfig, getMyUserInformation, - getPluginTestPath, - installPlugin, + getUsersList, + login, logout, + PluginsCommand, + refreshToken, + ServerInfo, setAccessTokensToServers, - uninstallPlugin, updateMyUser, userLogin, wait, - login, refreshToken, getConfig, updatePluginSettings, getUsersList -} from '../../../shared/extra-utils' -import { User, UserRole, ServerConfig } from '@shared/models' -import { expect } from 'chai' + waitUntilLog +} from '@shared/extra-utils' +import { ServerConfig, User, UserRole } from '@shared/models' describe('Test id and pass auth plugins', function () { let server: ServerInfo @@ -33,11 +37,7 @@ describe('Test id and pass auth plugins', function () { await setAccessTokensToServers([ server ]) for (const suffix of [ 'one', 'two', 'three' ]) { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-id-pass-auth-' + suffix) - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-id-pass-auth-' + suffix) }) } }) @@ -180,9 +180,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should unregister spyro-auth and do not login existing Spyro', async function () { - await updatePluginSettings({ - url: server.url, - accessToken: server.accessToken, + await server.pluginsCommand.updateSettings({ npmName: 'peertube-plugin-test-id-pass-auth-one', settings: { disableSpyro: true } }) @@ -204,11 +202,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should uninstall the plugin one and do not login existing Crash', async function () { - await uninstallPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-test-id-pass-auth-one' - }) + await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' }) await userLogin(server, { username: 'crash', password: 'crash password' }, 400) }) diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 0296d6eb7..0e0f61638 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -1,23 +1,25 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { expect } from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { checkVideoFilesWereRemoved, + cleanupTests, doubleFollow, - getPluginTestPath, + flushAndRunMultipleServers, getVideo, - installPlugin, + getVideosList, + makeGetRequest, makePostBodyRequest, + PluginsCommand, + ServerInfo, setAccessTokensToServers, uploadVideoAndGetId, viewVideo, - getVideosList, waitJobs, - makeGetRequest -} from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' -import { expect } from 'chai' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' + waitUntilLog +} from '@shared/extra-utils' function postCommand (server: ServerInfo, command: string, bodyArg?: object) { const body = { command } @@ -42,11 +44,7 @@ describe('Test plugin helpers', function () { await doubleFollow(servers[0], servers[1]) - await installPlugin({ - url: servers[0].url, - accessToken: servers[0].accessToken, - path: getPluginTestPath('-four') - }) + await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-four') }) }) describe('Logger', function () { diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts index 24e6a1e83..81e18dabd 100644 --- a/server/tests/plugins/plugin-router.ts +++ b/server/tests/plugins/plugin-router.ts @@ -1,16 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' +import { expect } from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { - getPluginTestPath, - installPlugin, + cleanupTests, + flushAndRunServer, makeGetRequest, makePostBodyRequest, - setAccessTokensToServers, uninstallPlugin -} from '../../../shared/extra-utils' -import { expect } from 'chai' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' + PluginsCommand, + ServerInfo, + setAccessTokensToServers +} from '@shared/extra-utils' describe('Test plugin helpers', function () { let server: ServerInfo @@ -25,11 +26,7 @@ describe('Test plugin helpers', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-five') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-five') }) }) it('Should answer "pong"', async function () { @@ -85,11 +82,7 @@ describe('Test plugin helpers', function () { }) it('Should remove the plugin and remove the routes', async function () { - await uninstallPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-test-five' - }) + await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-five' }) for (const path of basePaths) { await makeGetRequest({ diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 3c46b2585..4c65463f2 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts @@ -7,13 +7,14 @@ import { join } from 'path' import { HttpStatusCode } from '@shared/core-utils' import { buildServerDirectory, - getPluginTestPath, - installPlugin, + cleanupTests, + flushAndRunServer, makeGetRequest, + PluginsCommand, + ServerInfo, setAccessTokensToServers, - uninstallPlugin -} from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' + waitUntilLog +} from '@shared/extra-utils' describe('Test plugin storage', function () { let server: ServerInfo @@ -24,11 +25,7 @@ describe('Test plugin storage', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-six') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') }) }) describe('DB storage', function () { @@ -76,22 +73,14 @@ describe('Test plugin storage', function () { }) it('Should still have the file after an uninstallation', async function () { - await uninstallPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-test-six' - }) + await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-six' }) const content = await getFileContent() expect(content).to.equal('Prince Ali') }) it('Should still have the file after the reinstallation', async function () { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-six') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') }) const content = await getFileContent() expect(content).to.equal('Prince Ali') diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index eefb2294d..f1ff91077 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -4,25 +4,25 @@ import 'mocha' import { expect } from 'chai' import { join } from 'path' import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' -import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models' import { buildServerDirectory, + cleanupTests, createLive, + flushAndRunServer, getConfig, - getPluginTestPath, getVideo, - installPlugin, + PluginsCommand, sendRTMPStreamInVideo, + ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, testFfmpegStreamError, - uninstallPlugin, updateCustomSubConfig, uploadVideoAndGetId, waitJobs, waitUntilLivePublished -} from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' +} from '@shared/extra-utils' +import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models' async function createLiveWrapper (server: ServerInfo) { const liveAttributes = { @@ -109,11 +109,7 @@ describe('Test transcoding plugins', function () { } before(async function () { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-transcoding-one') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') }) }) it('Should have the appropriate available profiles', async function () { @@ -225,7 +221,7 @@ describe('Test transcoding plugins', function () { it('Should default to the default profile if the specified profile does not exist', async function () { this.timeout(240000) - await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' }) + await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) const res = await getConfig(server.url) const config = res.body as ServerConfig @@ -244,11 +240,7 @@ describe('Test transcoding plugins', function () { describe('When using a plugin adding new encoders', function () { before(async function () { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-transcoding-two') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') }) await updateConf(server, 'test-vod-profile', 'test-live-profile') }) diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts index 74ca82e2f..f430f82b8 100644 --- a/server/tests/plugins/plugin-unloading.ts +++ b/server/tests/plugins/plugin-unloading.ts @@ -1,18 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { - cleanupTests, - flushAndRunServer, - getPluginTestPath, - makeGetRequest, - installPlugin, - uninstallPlugin, - ServerInfo, - setAccessTokensToServers -} from '../../../shared/extra-utils' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { expect } from 'chai' +import { HttpStatusCode } from '@shared/core-utils' +import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' describe('Test plugins module unloading', function () { let server: ServerInfo = null @@ -25,11 +16,7 @@ describe('Test plugins module unloading', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-unloading') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) }) it('Should return a numeric value', async function () { @@ -54,11 +41,7 @@ describe('Test plugins module unloading', function () { }) it('Should uninstall the plugin and free the route', async function () { - await uninstallPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-test-unloading' - }) + await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-unloading' }) await makeGetRequest({ url: server.url, @@ -68,11 +51,8 @@ describe('Test plugins module unloading', function () { }) it('Should return a different numeric value', async function () { - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-unloading') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) + const res = await makeGetRequest({ url: server.url, path: requestPath, diff --git a/server/tests/plugins/translations.ts b/server/tests/plugins/translations.ts index 9fd2ba1c5..0e11a0b53 100644 --- a/server/tests/plugins/translations.ts +++ b/server/tests/plugins/translations.ts @@ -1,20 +1,15 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { PluginsCommand, setAccessTokensToServers } from '../../../shared/extra-utils' import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' -import { - getPluginTestPath, - getPluginTranslations, - installPlugin, - setAccessTokensToServers, - uninstallPlugin -} from '../../../shared/extra-utils' const expect = chai.expect describe('Test plugin translations', function () { let server: ServerInfo + let command: PluginsCommand before(async function () { this.timeout(30000) @@ -22,29 +17,22 @@ describe('Test plugin translations', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath() - }) + command = server.pluginsCommand - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-filter-translations') - }) + await command.install({ path: PluginsCommand.getPluginTestPath() }) + await command.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) }) it('Should not have translations for locale pt', async function () { - const res = await getPluginTranslations({ url: server.url, locale: 'pt' }) + const body = await command.getTranslations({ locale: 'pt' }) - expect(res.body).to.deep.equal({}) + expect(body).to.deep.equal({}) }) it('Should have translations for locale fr', async function () { - const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' }) + const body = await command.getTranslations({ locale: 'fr-FR' }) - expect(res.body).to.deep.equal({ + expect(body).to.deep.equal({ 'peertube-plugin-test': { Hi: 'Coucou' }, @@ -55,9 +43,9 @@ describe('Test plugin translations', function () { }) it('Should have translations of locale it', async function () { - const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' }) + const body = await command.getTranslations({ locale: 'it-IT' }) - expect(res.body).to.deep.equal({ + expect(body).to.deep.equal({ 'peertube-plugin-test-filter-translations': { 'Hello world': 'Ciao, mondo!' } @@ -65,12 +53,12 @@ describe('Test plugin translations', function () { }) it('Should remove the plugin and remove the locales', async function () { - await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-filter-translations' }) + await command.uninstall({ npmName: 'peertube-plugin-test-filter-translations' }) { - const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' }) + const body = await command.getTranslations({ locale: 'fr-FR' }) - expect(res.body).to.deep.equal({ + expect(body).to.deep.equal({ 'peertube-plugin-test': { Hi: 'Coucou' } @@ -78,9 +66,9 @@ describe('Test plugin translations', function () { } { - const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' }) + const body = await command.getTranslations({ locale: 'it-IT' }) - expect(res.body).to.deep.equal({}) + expect(body).to.deep.equal({}) } }) diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index eb014c596..4124e8a52 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -1,22 +1,24 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' +import * as chai from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { + cleanupTests, createVideoPlaylist, - getPluginTestPath, + flushAndRunServer, getVideo, getVideoCategories, getVideoLanguages, - getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies, - installPlugin, + getVideoLicences, + getVideoPlaylistPrivacies, + getVideoPrivacies, + PluginsCommand, + ServerInfo, setAccessTokensToServers, - uninstallPlugin, uploadVideo -} from '../../../shared/extra-utils' -import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -29,11 +31,7 @@ describe('Test plugin altering video constants', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-video-constants') - }) + await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) }) it('Should have updated languages', async function () { @@ -117,7 +115,7 @@ describe('Test plugin altering video constants', function () { }) it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { - await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' }) + await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) { const res = await getVideoLanguages(server.url) -- cgit v1.2.3 From 65e6e2602c0d5521f3a6740f7469bb92830ecb53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:51:09 +0200 Subject: Introduce config command --- server/tests/plugins/external-auth.ts | 15 ++------ server/tests/plugins/filter-hooks.ts | 61 ++++++++++++++++-------------- server/tests/plugins/id-and-pass-auth.ts | 15 ++------ server/tests/plugins/plugin-transcoding.ts | 50 ++++++++++++------------ 4 files changed, 65 insertions(+), 76 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index 424302786..09a107ca2 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -8,7 +8,6 @@ import { createUser, decodeQueryString, flushAndRunServer, - getConfig, getMyUserInformation, loginUsingExternalToken, logout, @@ -21,7 +20,7 @@ import { wait, waitUntilLog } from '@shared/extra-utils' -import { ServerConfig, User, UserRole } from '@shared/models' +import { User, UserRole } from '@shared/models' async function loginExternal (options: { server: ServerInfo @@ -78,9 +77,7 @@ describe('Test external auth plugins', function () { }) it('Should display the correct configuration', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(8) @@ -288,9 +285,7 @@ describe('Test external auth plugins', function () { }) it('Should have disabled this auth', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(7) @@ -354,9 +349,7 @@ describe('Test external auth plugins', function () { }) it('Should display the correct configuration', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(6) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index c51e96ab7..e254046bf 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -12,7 +12,6 @@ import { doubleFollow, flushAndRunMultipleServers, getAccountVideos, - getConfig, getMyVideos, getVideo, getVideoChannelVideos, @@ -28,7 +27,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomSubConfig, updateVideo, uploadVideo, uploadVideoAndGetId, @@ -37,7 +35,6 @@ import { } from '@shared/extra-utils' import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' import { - ServerConfig, VideoCommentThreadTree, VideoDetails, VideoImport, @@ -72,13 +69,15 @@ describe('Test plugin filter hooks', function () { const res = await getVideosList(servers[0].url) videoUUID = res.body.data[0].uuid - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { enabled: true }, - signup: { enabled: true }, - import: { - videos: { - http: { enabled: true }, - torrent: { enabled: true } + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true }, + signup: { enabled: true }, + import: { + videos: { + http: { enabled: true }, + torrent: { enabled: true } + } } } }) @@ -344,8 +343,8 @@ describe('Test plugin filter hooks', function () { describe('Should run filter:api.user.signup.allowed.result', function () { it('Should run on config endpoint', async function () { - const res = await getConfig(servers[0].url) - expect((res.body as ServerConfig).signup.allowed).to.be.true + const body = await servers[0].configCommand.getConfig() + expect(body.signup.allowed).to.be.true }) it('Should allow a signup', async function () { @@ -365,13 +364,15 @@ describe('Test plugin filter hooks', function () { before(async function () { this.timeout(120000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - webtorrent: { - enabled: true - }, - hls: { - enabled: true + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + webtorrent: { + enabled: true + }, + hls: { + enabled: true + } } } }) @@ -427,9 +428,11 @@ describe('Test plugin filter hooks', function () { before(async function () { this.timeout(60000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: false + } } }) @@ -464,12 +467,14 @@ describe('Test plugin filter hooks', function () { describe('Search filters', function () { before(async function () { - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - search: { - searchIndex: { - enabled: true, - isDefaultSearch: false, - disableLocalSearch: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled: true, + isDefaultSearch: false, + disableLocalSearch: false + } } } }) diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 545968040..99de28d3f 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -5,7 +5,6 @@ import { expect } from 'chai' import { cleanupTests, flushAndRunServer, - getConfig, getMyUserInformation, getUsersList, login, @@ -19,7 +18,7 @@ import { wait, waitUntilLog } from '@shared/extra-utils' -import { ServerConfig, User, UserRole } from '@shared/models' +import { User, UserRole } from '@shared/models' describe('Test id and pass auth plugins', function () { let server: ServerInfo @@ -42,9 +41,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should display the correct configuration', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(8) @@ -190,9 +187,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should have disabled this auth', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(7) @@ -208,9 +203,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should display the correct configuration', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(6) diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index f1ff91077..71c2adc72 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -9,7 +9,6 @@ import { cleanupTests, createLive, flushAndRunServer, - getConfig, getVideo, PluginsCommand, sendRTMPStreamInVideo, @@ -17,12 +16,11 @@ import { setAccessTokensToServers, setDefaultVideoChannel, testFfmpegStreamError, - updateCustomSubConfig, uploadVideoAndGetId, waitJobs, waitUntilLivePublished } from '@shared/extra-utils' -import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoDetails, VideoPrivacy } from '@shared/models' async function createLiveWrapper (server: ServerInfo) { const liveAttributes = { @@ -36,33 +34,35 @@ async function createLiveWrapper (server: ServerInfo) { } function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { - return updateCustomSubConfig(server.url, server.accessToken, { - transcoding: { - enabled: true, - profile: vodProfile, - hls: { - enabled: true - }, - webtorrent: { - enabled: true - }, - resolutions: { - '240p': true, - '360p': false, - '480p': false, - '720p': true - } - }, - live: { + return server.configCommand.updateCustomSubConfig({ + newConfig: { transcoding: { - profile: liveProfile, enabled: true, + profile: vodProfile, + hls: { + enabled: true + }, + webtorrent: { + enabled: true + }, resolutions: { '240p': true, '360p': false, '480p': false, '720p': true } + }, + live: { + transcoding: { + profile: liveProfile, + enabled: true, + resolutions: { + '240p': true, + '360p': false, + '480p': false, + '720p': true + } + } } } }) @@ -113,8 +113,7 @@ describe('Test transcoding plugins', function () { }) it('Should have the appropriate available profiles', async function () { - const res = await getConfig(server.url) - const config = res.body as ServerConfig + const config = await server.configCommand.getConfig() expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ]) expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ]) @@ -223,8 +222,7 @@ describe('Test transcoding plugins', function () { await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) - const res = await getConfig(server.url) - const config = res.body as ServerConfig + const config = await server.configCommand.getConfig() expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) -- cgit v1.2.3 From 4f2199144e428c16460750305f737b890c1ac322 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:18:40 +0200 Subject: Introduce live command --- server/tests/plugins/action-hooks.ts | 3 +-- server/tests/plugins/filter-hooks.ts | 3 +-- server/tests/plugins/plugin-transcoding.ts | 28 +++++++++++++--------------- 3 files changed, 15 insertions(+), 19 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 0de5b523b..39266c62f 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -7,7 +7,6 @@ import { addVideoCommentThread, addVideoInPlaylist, blockUser, - createLive, createUser, createVideoPlaylist, deleteVideoComment, @@ -96,7 +95,7 @@ describe('Test plugin action hooks', function () { channelId: servers[0].videoChannel.id } - await createLive(servers[0].url, servers[0].accessToken, attributes) + await servers[0].liveCommand.createLive({ fields: attributes }) await checkHook('action:api.live-video.created') }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index e254046bf..e60bad38d 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -7,7 +7,6 @@ import { addVideoCommentReply, addVideoCommentThread, cleanupTests, - createLive, createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, @@ -156,7 +155,7 @@ describe('Test plugin filter hooks', function () { channelId: servers[0].videoChannel.id } - await createLive(servers[0].url, servers[0].accessToken, attributes, HttpStatusCode.FORBIDDEN_403) + await servers[0].liveCommand.createLive({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.video.pre-import-url.accept.result', async function () { diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index 71c2adc72..65282419e 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -7,18 +7,15 @@ import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server import { buildServerDirectory, cleanupTests, - createLive, flushAndRunServer, getVideo, PluginsCommand, - sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, testFfmpegStreamError, uploadVideoAndGetId, - waitJobs, - waitUntilLivePublished + waitJobs } from '@shared/extra-utils' import { VideoDetails, VideoPrivacy } from '@shared/models' @@ -29,8 +26,9 @@ async function createLiveWrapper (server: ServerInfo) { privacy: VideoPrivacy.PUBLIC } - const res = await createLive(server.url, server.accessToken, liveAttributes) - return res.body.video.uuid + const { uuid } = await server.liveCommand.createLive({ fields: liveAttributes }) + + return uuid } function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { @@ -171,8 +169,8 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) + await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.liveCommand.waitUntilLivePublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'above', 20) @@ -185,8 +183,8 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) + await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.liveCommand.waitUntilLivePublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'below', 12) @@ -199,8 +197,8 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) + await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.liveCommand.waitUntilLivePublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'below', 6) @@ -213,7 +211,7 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') + const command = await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) await testFfmpegStreamError(command, true) }) @@ -262,8 +260,8 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) + await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.liveCommand.waitUntilLivePublished({ videoId: liveVideoId }) await waitJobs([ server ]) const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8` -- cgit v1.2.3 From 04aed76711909507e74905bde3a7fa024d3585c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:25:50 +0200 Subject: Shorter live methods --- server/tests/plugins/action-hooks.ts | 2 +- server/tests/plugins/filter-hooks.ts | 2 +- server/tests/plugins/plugin-transcoding.ts | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 39266c62f..5e9dc3515 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -95,7 +95,7 @@ describe('Test plugin action hooks', function () { channelId: servers[0].videoChannel.id } - await servers[0].liveCommand.createLive({ fields: attributes }) + await servers[0].liveCommand.create({ fields: attributes }) await checkHook('action:api.live-video.created') }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index e60bad38d..e938663da 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -155,7 +155,7 @@ describe('Test plugin filter hooks', function () { channelId: servers[0].videoChannel.id } - await servers[0].liveCommand.createLive({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[0].liveCommand.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.video.pre-import-url.accept.result', async function () { diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index 65282419e..ca4d9f962 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -26,7 +26,7 @@ async function createLiveWrapper (server: ServerInfo) { privacy: VideoPrivacy.PUBLIC } - const { uuid } = await server.liveCommand.createLive({ fields: liveAttributes }) + const { uuid } = await server.liveCommand.create({ fields: liveAttributes }) return uuid } @@ -170,7 +170,7 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) - await server.liveCommand.waitUntilLivePublished({ videoId: liveVideoId }) + await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'above', 20) @@ -184,7 +184,7 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) - await server.liveCommand.waitUntilLivePublished({ videoId: liveVideoId }) + await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'below', 12) @@ -198,7 +198,7 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) - await server.liveCommand.waitUntilLivePublished({ videoId: liveVideoId }) + await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'below', 6) @@ -261,7 +261,7 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) - await server.liveCommand.waitUntilLivePublished({ videoId: liveVideoId }) + await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8` -- cgit v1.2.3 From e6346d59e63135cf012ed18c102d3b0179ef565f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 15:54:39 +0200 Subject: Introduce playlist command --- server/tests/plugins/action-hooks.ts | 17 ++++------------- server/tests/plugins/filter-hooks.ts | 10 ++++------ server/tests/plugins/video-constants.ts | 17 ++++------------- 3 files changed, 12 insertions(+), 32 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 5e9dc3515..fd83bf2ac 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -5,10 +5,8 @@ import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/mode import { addVideoCommentReply, addVideoCommentThread, - addVideoInPlaylist, blockUser, createUser, - createVideoPlaylist, deleteVideoComment, PluginsCommand, registerUser, @@ -180,15 +178,13 @@ describe('Test plugin action hooks', function () { before(async function () { { - const res = await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + const { id } = await servers[0].playlistsCommand.create({ + attributes: { displayName: 'My playlist', privacy: VideoPlaylistPrivacy.PRIVATE } }) - playlistId = res.body.videoPlaylist.id + playlistId = id } { @@ -198,12 +194,7 @@ describe('Test plugin action hooks', function () { }) it('Should run action:api.video-playlist-element.created', async function () { - await addVideoInPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistId, - elementAttrs: { videoId } - }) + await servers[0].playlistsCommand.addElement({ playlistId, attributes: { videoId } }) await checkHook('action:api.video-playlist-element.created') }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index e938663da..203642d8d 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -7,7 +7,6 @@ import { addVideoCommentReply, addVideoCommentThread, cleanupTests, - createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, getAccountVideos, @@ -15,7 +14,6 @@ import { getVideo, getVideoChannelVideos, getVideoCommentThreads, - getVideoPlaylist, getVideosList, getVideosListPagination, getVideoThreadComments, @@ -443,11 +441,11 @@ describe('Test plugin filter hooks', function () { } { - const playlistAttrs = { displayName: name, videoChannelId: servers[0].videoChannel.id, privacy: VideoPlaylistPrivacy.PUBLIC } - const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) + const attributes = { displayName: name, videoChannelId: servers[0].videoChannel.id, privacy: VideoPlaylistPrivacy.PUBLIC } + const { id } = await servers[0].playlistsCommand.create({ attributes }) - const resPlaylist = await getVideoPlaylist(servers[0].url, res.body.videoPlaylist.id) - embedPlaylists.push(resPlaylist.body) + const playlist = await servers[0].playlistsCommand.get({ playlistId: id }) + embedPlaylists.push(playlist) } } }) diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index 4124e8a52..4a05af042 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -5,13 +5,11 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - createVideoPlaylist, flushAndRunServer, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, - getVideoPlaylistPrivacies, getVideoPrivacies, PluginsCommand, ServerInfo, @@ -79,8 +77,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated playlist privacies', async function () { - const res = await getVideoPlaylistPrivacies(server.url) - const playlistPrivacies = res.body + const playlistPrivacies = await server.playlistsCommand.getPrivacies() expect(playlistPrivacies[1]).to.exist expect(playlistPrivacies[2]).to.exist @@ -93,13 +90,8 @@ describe('Test plugin altering video constants', function () { }) it('Should not be able to create a video with this privacy', async function () { - const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } - await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: attrs, - expectedStatus: HttpStatusCode.BAD_REQUEST_400 - }) + const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } + await server.playlistsCommand.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should be able to upload a video with these values', async function () { @@ -162,8 +154,7 @@ describe('Test plugin altering video constants', function () { } { - const res = await getVideoPlaylistPrivacies(server.url) - const playlistPrivacies = res.body + const playlistPrivacies = await server.playlistsCommand.getPrivacies() expect(playlistPrivacies[1]).to.exist expect(playlistPrivacies[2]).to.exist -- cgit v1.2.3 From 6910f20f114b5bd020258a3a9a3f2117819a60c2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:49:51 +0200 Subject: Introduce import command --- server/tests/plugins/filter-hooks.ts | 67 +++++++++++++++--------------------- 1 file changed, 28 insertions(+), 39 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 203642d8d..a3c3c0551 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -18,6 +18,7 @@ import { getVideosListPagination, getVideoThreadComments, getVideoWithToken, + ImportsCommand, makeRawRequest, PluginsCommand, registerUser, @@ -30,16 +31,7 @@ import { waitJobs, waitUntilLog } from '@shared/extra-utils' -import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' -import { - VideoCommentThreadTree, - VideoDetails, - VideoImport, - VideoImportState, - VideoPlaylist, - VideoPlaylistPrivacy, - VideoPrivacy -} from '@shared/models' +import { VideoCommentThreadTree, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -157,23 +149,23 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.video.pre-import-url.accept.result', async function () { - const baseAttributes = { + const attributes = { name: 'normal title', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id, - targetUrl: getGoodVideoUrl() + 'bad' + targetUrl: ImportsCommand.getGoodVideoUrl() + 'bad' } - await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) + await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { - const baseAttributes = { + const attributes = { name: 'bad torrent', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id, torrentfile: 'video-720p.torrent' as any } - await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) + await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.video.post-import-url.accept.result', async function () { @@ -182,21 +174,21 @@ describe('Test plugin filter hooks', function () { let videoImportId: number { - const baseAttributes = { + const attributes = { name: 'title with bad word', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id, - targetUrl: getGoodVideoUrl() + targetUrl: ImportsCommand.getGoodVideoUrl() } - const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) - videoImportId = res.body.id + const body = await servers[0].importsCommand.importVideo({ attributes }) + videoImportId = body.id } await waitJobs(servers) { - const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) - const videoImports = res.body.data as VideoImport[] + const body = await servers[0].importsCommand.getMyVideoImports() + const videoImports = body.data const videoImport = videoImports.find(i => i.id === videoImportId) @@ -211,21 +203,20 @@ describe('Test plugin filter hooks', function () { let videoImportId: number { - const baseAttributes = { + const attributes = { name: 'title with bad word', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id, torrentfile: 'video-720p.torrent' as any } - const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) - videoImportId = res.body.id + const body = await servers[0].importsCommand.importVideo({ attributes }) + videoImportId = body.id } await waitJobs(servers) { - const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) - const videoImports = res.body.data as VideoImport[] + const { data: videoImports } = await servers[0].importsCommand.getMyVideoImports() const videoImport = videoImports.find(i => i.id === videoImportId) @@ -278,17 +269,15 @@ describe('Test plugin filter hooks', function () { describe('Should run filter:video.auto-blacklist.result', function () { - async function checkIsBlacklisted (oldRes: any, value: boolean) { - const videoId = oldRes.body.video.uuid - - const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId) + async function checkIsBlacklisted (id: number | string, value: boolean) { + const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id) const video: VideoDetails = res.body expect(video.blacklisted).to.equal(value) } it('Should blacklist on upload', async function () { const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) - await checkIsBlacklisted(res, true) + await checkIsBlacklisted(res.body.video.uuid, true) }) it('Should blacklist on import', async function () { @@ -296,20 +285,20 @@ describe('Test plugin filter hooks', function () { const attributes = { name: 'video please blacklist me', - targetUrl: getGoodVideoUrl(), + targetUrl: ImportsCommand.getGoodVideoUrl(), channelId: servers[0].videoChannel.id } - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - await checkIsBlacklisted(res, true) + const body = await servers[0].importsCommand.importVideo({ attributes }) + await checkIsBlacklisted(body.video.uuid, true) }) it('Should blacklist on update', async function () { const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) const videoId = res.body.video.uuid - await checkIsBlacklisted(res, false) + await checkIsBlacklisted(videoId, false) await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) - await checkIsBlacklisted(res, true) + await checkIsBlacklisted(videoId, true) }) it('Should blacklist on remote upload', async function () { @@ -318,7 +307,7 @@ describe('Test plugin filter hooks', function () { const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) await waitJobs(servers) - await checkIsBlacklisted(res, true) + await checkIsBlacklisted(res.body.video.uuid, true) }) it('Should blacklist on remote update', async function () { @@ -328,12 +317,12 @@ describe('Test plugin filter hooks', function () { await waitJobs(servers) const videoId = res.body.video.uuid - await checkIsBlacklisted(res, false) + await checkIsBlacklisted(videoId, false) await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) await waitJobs(servers) - await checkIsBlacklisted(res, true) + await checkIsBlacklisted(videoId, true) }) }) -- cgit v1.2.3 From 12edc1495a36b2199f1bf1ba37f50c7b694be382 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 14:15:11 +0200 Subject: Introduce comments command --- server/tests/plugins/action-hooks.ts | 11 +++----- server/tests/plugins/filter-hooks.ts | 50 +++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 31 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index fd83bf2ac..6975ca4bb 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -3,11 +3,8 @@ import 'mocha' import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' import { - addVideoCommentReply, - addVideoCommentThread, blockUser, createUser, - deleteVideoComment, PluginsCommand, registerUser, removeUser, @@ -101,20 +98,20 @@ describe('Test plugin action hooks', function () { describe('Comments hooks', function () { it('Should run action:api.video-thread.created', async function () { - const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') - threadId = res.body.comment.id + const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' }) + threadId = created.id await checkHook('action:api.video-thread.created') }) it('Should run action:api.video-comment-reply.created', async function () { - await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply') + await servers[0].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' }) await checkHook('action:api.video-comment-reply.created') }) it('Should run action:api.video-comment.deleted', async function () { - await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) + await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId: threadId }) await checkHook('action:api.video-comment.deleted') }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index a3c3c0551..c235508e8 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -4,8 +4,6 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - addVideoCommentReply, - addVideoCommentThread, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -13,10 +11,8 @@ import { getMyVideos, getVideo, getVideoChannelVideos, - getVideoCommentThreads, getVideosList, getVideosListPagination, - getVideoThreadComments, getVideoWithToken, ImportsCommand, makeRawRequest, @@ -31,7 +27,7 @@ import { waitJobs, waitUntilLog } from '@shared/extra-utils' -import { VideoCommentThreadTree, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' +import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -226,44 +222,50 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.video-thread.create.accept.result', async function () { - await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', HttpStatusCode.FORBIDDEN_403) + await servers[0].commentsCommand.createThread({ + videoId: videoUUID, + text: 'comment with bad word', + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should run filter:api.video-comment-reply.create.accept.result', async function () { - const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') - threadId = res.body.comment.id - - await addVideoCommentReply( - servers[0].url, - servers[0].accessToken, - videoUUID, - threadId, - 'comment with bad word', - HttpStatusCode.FORBIDDEN_403 - ) - await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', HttpStatusCode.OK_200) + const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' }) + threadId = created.id + + await servers[0].commentsCommand.addReply({ + videoId: videoUUID, + toCommentId: threadId, + text: 'comment with bad word', + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) + await servers[0].commentsCommand.addReply({ + videoId: videoUUID, + toCommentId: threadId, + text: 'comment with good word', + expectedStatus: HttpStatusCode.OK_200 + }) }) it('Should run filter:api.video-threads.list.params', async function () { - const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) + const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 0 }) // our plugin do +1 to the count parameter - expect(res.body.data).to.have.lengthOf(1) + expect(data).to.have.lengthOf(1) }) it('Should run filter:api.video-threads.list.result', async function () { - const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) + const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 0 }) // Plugin do +1 to the total result - expect(res.body.total).to.equal(2) + expect(total).to.equal(2) }) it('Should run filter:api.video-thread-comments.list.params') it('Should run filter:api.video-thread-comments.list.result', async function () { - const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) + const thread = await servers[0].commentsCommand.getThread({ videoId: videoUUID, threadId }) - const thread = res.body as VideoCommentThreadTree expect(thread.comment.text.endsWith(' <3')).to.be.true }) -- cgit v1.2.3 From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- server/tests/plugins/action-hooks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 6975ca4bb..bcf773854 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -44,7 +44,7 @@ describe('Test plugin action hooks', function () { await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await reRunServer(servers[0], { live: { -- cgit v1.2.3 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/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 +-- 7 files changed, 44 insertions(+), 59 deletions(-) (limited to 'server/tests/plugins') 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 From 41d1d075011174e73dccb74006181a92a618d7b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 11:05:15 +0200 Subject: Introduce login command --- server/tests/plugins/action-hooks.ts | 3 +- server/tests/plugins/external-auth.ts | 57 ++++++++++++++++---------------- server/tests/plugins/id-and-pass-auth.ts | 49 ++++++++++++++------------- 3 files changed, 56 insertions(+), 53 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index cf81e44b7..84f4e8501 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -14,7 +14,6 @@ import { updateUser, updateVideo, uploadVideo, - userLogin, viewVideo } from '../../../shared/extra-utils' import { @@ -138,7 +137,7 @@ describe('Test plugin action hooks', function () { }) it('Should run action:api.user.oauth2-got-token', async function () { - await userLogin(servers[0], { username: 'created_user', password: 'super_password' }) + await servers[0].loginCommand.getAccessToken('created_user', 'super_password') await checkHook('action:api.user.oauth2-got-token') }) diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index f7cee588a..e421fd224 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -9,14 +9,10 @@ import { decodeQueryString, flushAndRunServer, getMyUserInformation, - loginUsingExternalToken, - logout, PluginsCommand, - refreshToken, ServerInfo, setAccessTokensToServers, updateMyUser, - userLogin, wait } from '@shared/extra-utils' import { User, UserRole } from '@shared/models' @@ -43,12 +39,11 @@ async function loginExternal (options: { const location = res.header.location const { externalAuthToken } = decodeQueryString(location) - const resLogin = await loginUsingExternalToken( - options.server, - options.username, - externalAuthToken as string, - options.statusCodeExpectedStep2 - ) + const resLogin = await options.server.loginCommand.loginUsingExternalToken({ + username: options.username, + externalAuthToken: externalAuthToken as string, + expectedStatus: options.statusCodeExpectedStep2 + }) return resLogin.body } @@ -110,13 +105,17 @@ describe('Test external auth plugins', function () { }) it('Should reject auto external login with a missing or invalid token', async function () { - await loginUsingExternalToken(server, 'cyan', '', HttpStatusCode.BAD_REQUEST_400) - await loginUsingExternalToken(server, 'cyan', 'blabla', HttpStatusCode.BAD_REQUEST_400) + const command = server.loginCommand + + await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should reject auto external login with a missing or invalid username', async function () { - await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) - await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) + const command = server.loginCommand + + await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should reject auto external login with an expired token', async function () { @@ -124,7 +123,11 @@ describe('Test external auth plugins', function () { await wait(5000) - await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.loginUsingExternalToken({ + username: 'cyan', + externalAuthToken, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) await server.serversCommand.waitUntilLog('expired external auth token', 2) }) @@ -182,7 +185,7 @@ describe('Test external auth plugins', function () { it('Should refresh Cyan token, but not Kefka token', async function () { { - const resRefresh = await refreshToken(server, cyanRefreshToken) + const resRefresh = await server.loginCommand.refreshToken({ refreshToken: cyanRefreshToken }) cyanAccessToken = resRefresh.body.access_token cyanRefreshToken = resRefresh.body.refresh_token @@ -192,7 +195,7 @@ describe('Test external auth plugins', function () { } { - await refreshToken(server, kefkaRefreshToken, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.refreshToken({ refreshToken: kefkaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -212,7 +215,7 @@ describe('Test external auth plugins', function () { }) it('Should logout Cyan', async function () { - await logout(server.url, cyanAccessToken) + await server.loginCommand.logout({ token: cyanAccessToken }) }) it('Should have logged out Cyan', async function () { @@ -269,7 +272,7 @@ describe('Test external auth plugins', function () { settings: { disableKefka: true } }) - await userLogin(server, { username: 'kefka', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user: { username: 'kefka', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await loginExternal({ server, @@ -307,9 +310,9 @@ describe('Test external auth plugins', function () { statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) - await userLogin(server, { username: 'cyan', password: null }, HttpStatusCode.BAD_REQUEST_400) - await userLogin(server, { username: 'cyan', password: '' }, HttpStatusCode.BAD_REQUEST_400) - await userLogin(server, { username: 'cyan', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.loginCommand.login({ user: { username: 'cyan', password: '' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.loginCommand.login({ user: { username: 'cyan', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not login kefka with another plugin', async function () { @@ -369,9 +372,8 @@ describe('Test external auth plugins', function () { username: 'cid' }) - const resLogout = await logout(server.url, resLogin.access_token) - - expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl') + const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token }) + expect(redirectUrl).to.equal('https://example.com/redirectUrl') }) it('Should call the plugin\'s onLogout method with the request', async function () { @@ -382,8 +384,7 @@ describe('Test external auth plugins', function () { username: 'cid' }) - const resLogout = await logout(server.url, resLogin.access_token) - - expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token) + const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token }) + expect(redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token) }) }) diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index a0b31bc1f..e3da64110 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -2,19 +2,16 @@ import 'mocha' import { expect } from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, getMyUserInformation, getUsersList, - login, - logout, PluginsCommand, - refreshToken, ServerInfo, setAccessTokensToServers, updateMyUser, - userLogin, wait } from '@shared/extra-utils' import { User, UserRole } from '@shared/models' @@ -52,11 +49,11 @@ describe('Test id and pass auth plugins', function () { }) it('Should not login', async function () { - await userLogin(server, { username: 'toto', password: 'password' }, 400) + await server.loginCommand.login({ user: { username: 'toto', password: 'password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should login Spyro, create the user and use the token', async function () { - const accessToken = await userLogin(server, { username: 'spyro', password: 'spyro password' }) + const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' }) const res = await getMyUserInformation(server.url, accessToken) @@ -68,9 +65,9 @@ describe('Test id and pass auth plugins', function () { it('Should login Crash, create the user and use the token', async function () { { - const res = await login(server.url, server.client, { username: 'crash', password: 'crash password' }) - crashAccessToken = res.body.access_token - crashRefreshToken = res.body.refresh_token + const body = await server.loginCommand.login({ user: { username: 'crash', password: 'crash password' } }) + crashAccessToken = body.access_token + crashRefreshToken = body.refresh_token } { @@ -85,9 +82,9 @@ describe('Test id and pass auth plugins', function () { it('Should login the first Laguna, create the user and use the token', async function () { { - const res = await login(server.url, server.client, { username: 'laguna', password: 'laguna password' }) - lagunaAccessToken = res.body.access_token - lagunaRefreshToken = res.body.refresh_token + const body = await server.loginCommand.login({ user: { username: 'laguna', password: 'laguna password' } }) + lagunaAccessToken = body.access_token + lagunaRefreshToken = body.refresh_token } { @@ -102,7 +99,7 @@ describe('Test id and pass auth plugins', function () { it('Should refresh crash token, but not laguna token', async function () { { - const resRefresh = await refreshToken(server, crashRefreshToken) + const resRefresh = await server.loginCommand.refreshToken({ refreshToken: crashRefreshToken }) crashAccessToken = resRefresh.body.access_token crashRefreshToken = resRefresh.body.refresh_token @@ -112,7 +109,7 @@ describe('Test id and pass auth plugins', function () { } { - await refreshToken(server, lagunaRefreshToken, 400) + await server.loginCommand.refreshToken({ refreshToken: lagunaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -132,7 +129,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should logout Crash', async function () { - await logout(server.url, crashAccessToken) + await server.loginCommand.logout({ token: crashAccessToken }) }) it('Should have logged out Crash', async function () { @@ -142,7 +139,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should login Crash and keep the old existing profile', async function () { - crashAccessToken = await userLogin(server, { username: 'crash', password: 'crash password' }) + crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' }) const res = await getMyUserInformation(server.url, crashAccessToken) @@ -162,16 +159,18 @@ 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) + const command = server.loginCommand + + await command.login({ user: { username: 'ward', password: 'ward password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await server.serversCommand.waitUntilLog('valid username') - await userLogin(server, { username: 'kiros', password: 'kiros password' }, 400) + await command.login({ user: { username: 'kiros', password: 'kiros password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await server.serversCommand.waitUntilLog('valid display name') - await userLogin(server, { username: 'raine', password: 'raine password' }, 400) + await command.login({ user: { username: 'raine', password: 'raine password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await server.serversCommand.waitUntilLog('valid role') - await userLogin(server, { username: 'ellone', password: 'elonne password' }, 400) + await command.login({ user: { username: 'ellone', password: 'elonne password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await server.serversCommand.waitUntilLog('valid email') }) @@ -181,8 +180,9 @@ describe('Test id and pass auth plugins', function () { settings: { disableSpyro: true } }) - await userLogin(server, { username: 'spyro', password: 'spyro password' }, 400) - await userLogin(server, { username: 'spyro', password: 'fake' }, 400) + const command = server.loginCommand + await command.login({ user: { username: 'spyro', password: 'spyro password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.login({ user: { username: 'spyro', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should have disabled this auth', async function () { @@ -198,7 +198,10 @@ describe('Test id and pass auth plugins', function () { it('Should uninstall the plugin one and do not login existing Crash', async function () { await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' }) - await userLogin(server, { username: 'crash', password: 'crash password' }, 400) + await server.loginCommand.login({ + user: { username: 'crash', password: 'crash password' }, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) }) it('Should display the correct configuration', async function () { -- cgit v1.2.3 From 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 14:23:01 +0200 Subject: Introduce user command --- server/tests/plugins/action-hooks.ts | 41 +++++++++--------------- server/tests/plugins/external-auth.ts | 49 +++++++++-------------------- server/tests/plugins/filter-hooks.ts | 9 ++++-- server/tests/plugins/id-and-pass-auth.ts | 53 ++++++++++---------------------- 4 files changed, 52 insertions(+), 100 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 84f4e8501..b156f6b60 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -1,28 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' import { - blockUser, - createUser, + cleanupTests, + flushAndRunMultipleServers, + killallServers, PluginsCommand, - registerUser, - removeUser, + reRunServer, + ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - unblockUser, - updateUser, updateVideo, uploadVideo, viewVideo -} from '../../../shared/extra-utils' -import { - cleanupTests, - flushAndRunMultipleServers, - killallServers, - reRunServer, - ServerInfo -} from '../../../shared/extra-utils/server/servers' +} from '@shared/extra-utils' +import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' describe('Test plugin action hooks', function () { let servers: ServerInfo[] @@ -119,19 +111,14 @@ describe('Test plugin action hooks', function () { let userId: number it('Should run action:api.user.registered', async function () { - await registerUser(servers[0].url, 'registered_user', 'super_password') + await servers[0].usersCommand.register({ username: 'registered_user' }) await checkHook('action:api.user.registered') }) it('Should run action:api.user.created', async function () { - const res = await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: 'created_user', - password: 'super_password' - }) - userId = res.body.user.id + const user = await servers[0].usersCommand.create({ username: 'created_user' }) + userId = user.id await checkHook('action:api.user.created') }) @@ -143,25 +130,25 @@ describe('Test plugin action hooks', function () { }) it('Should run action:api.user.blocked', async function () { - await blockUser(servers[0].url, userId, servers[0].accessToken) + await servers[0].usersCommand.banUser({ userId }) await checkHook('action:api.user.blocked') }) it('Should run action:api.user.unblocked', async function () { - await unblockUser(servers[0].url, userId, servers[0].accessToken) + await servers[0].usersCommand.unbanUser({ userId }) await checkHook('action:api.user.unblocked') }) it('Should run action:api.user.updated', async function () { - await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 }) + await servers[0].usersCommand.update({ userId, videoQuota: 50 }) await checkHook('action:api.user.updated') }) it('Should run action:api.user.deleted', async function () { - await removeUser(servers[0].url, userId, servers[0].accessToken) + await servers[0].usersCommand.remove({ userId }) await checkHook('action:api.user.deleted') }) diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index e421fd224..3e8305611 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -5,17 +5,14 @@ import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - createUser, decodeQueryString, flushAndRunServer, - getMyUserInformation, PluginsCommand, ServerInfo, setAccessTokensToServers, - updateMyUser, wait } from '@shared/extra-utils' -import { User, UserRole } from '@shared/models' +import { UserRole } from '@shared/models' async function loginExternal (options: { server: ServerInfo @@ -149,9 +146,7 @@ describe('Test external auth plugins', function () { } { - const res = await getMyUserInformation(server.url, cyanAccessToken) - - const body: User = res.body + const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) expect(body.username).to.equal('cyan') expect(body.account.displayName).to.equal('cyan') expect(body.email).to.equal('cyan@example.com') @@ -173,9 +168,7 @@ describe('Test external auth plugins', function () { } { - const res = await getMyUserInformation(server.url, kefkaAccessToken) - - const body: User = res.body + const body = await server.usersCommand.getMyInfo({ token: kefkaAccessToken }) expect(body.username).to.equal('kefka') expect(body.account.displayName).to.equal('Kefka Palazzo') expect(body.email).to.equal('kefka@example.com') @@ -189,9 +182,8 @@ describe('Test external auth plugins', function () { cyanAccessToken = resRefresh.body.access_token cyanRefreshToken = resRefresh.body.refresh_token - const res = await getMyUserInformation(server.url, cyanAccessToken) - const user: User = res.body - expect(user.username).to.equal('cyan') + const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) + expect(body.username).to.equal('cyan') } { @@ -200,16 +192,13 @@ describe('Test external auth plugins', function () { }) it('Should update Cyan profile', async function () { - await updateMyUser({ - url: server.url, - accessToken: cyanAccessToken, + await server.usersCommand.updateMe({ + token: cyanAccessToken, displayName: 'Cyan Garamonde', description: 'Retainer to the king of Doma' }) - const res = await getMyUserInformation(server.url, cyanAccessToken) - - const body: User = res.body + const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) expect(body.account.displayName).to.equal('Cyan Garamonde') expect(body.account.description).to.equal('Retainer to the king of Doma') }) @@ -221,7 +210,7 @@ describe('Test external auth plugins', function () { it('Should have logged out Cyan', async function () { await server.serversCommand.waitUntilLog('On logout cyan') - await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should login Cyan and keep the old existing profile', async function () { @@ -239,9 +228,7 @@ describe('Test external auth plugins', function () { cyanAccessToken = res.access_token } - const res = await getMyUserInformation(server.url, cyanAccessToken) - - const body: User = res.body + const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) expect(body.username).to.equal('cyan') expect(body.account.displayName).to.equal('Cyan Garamonde') expect(body.account.description).to.equal('Retainer to the king of Doma') @@ -249,12 +236,11 @@ describe('Test external auth plugins', function () { }) it('Should not update an external auth email', async function () { - await updateMyUser({ - url: server.url, - accessToken: cyanAccessToken, + await server.usersCommand.updateMe({ + token: cyanAccessToken, email: 'toto@example.com', currentPassword: 'toto', - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -263,7 +249,7 @@ describe('Test external auth plugins', function () { await wait(5000) - await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should unregister external-auth-2 and do not login existing Kefka', async function () { @@ -334,12 +320,7 @@ describe('Test external auth plugins', function () { }) it('Should not login an existing user', async function () { - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: 'existing_user', - password: 'super_password' - }) + await server.usersCommand.create({ username: 'existing_user', password: 'super_password' }) await loginExternal({ server, diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index b5e29d298..c82025f6a 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -17,7 +17,6 @@ import { ImportsCommand, makeRawRequest, PluginsCommand, - registerUser, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -335,11 +334,15 @@ describe('Test plugin filter hooks', function () { }) it('Should allow a signup', async function () { - await registerUser(servers[0].url, 'john', 'password') + await servers[0].usersCommand.register({ username: 'john', password: 'password' }) }) it('Should not allow a signup', async function () { - const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403) + const res = await servers[0].usersCommand.register({ + username: 'jma', + password: 'password', + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) expect(res.body.error).to.equal('No jma') }) diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index e3da64110..787080e7c 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -3,18 +3,8 @@ import 'mocha' import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - getMyUserInformation, - getUsersList, - PluginsCommand, - ServerInfo, - setAccessTokensToServers, - updateMyUser, - wait -} from '@shared/extra-utils' -import { User, UserRole } from '@shared/models' +import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' +import { UserRole } from '@shared/models' describe('Test id and pass auth plugins', function () { let server: ServerInfo @@ -55,9 +45,8 @@ describe('Test id and pass auth plugins', function () { it('Should login Spyro, create the user and use the token', async function () { const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' }) - const res = await getMyUserInformation(server.url, accessToken) + const body = await server.usersCommand.getMyInfo({ token: accessToken }) - const body: User = res.body expect(body.username).to.equal('spyro') expect(body.account.displayName).to.equal('Spyro the Dragon') expect(body.role).to.equal(UserRole.USER) @@ -71,9 +60,8 @@ describe('Test id and pass auth plugins', function () { } { - const res = await getMyUserInformation(server.url, crashAccessToken) + const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) - const body: User = res.body expect(body.username).to.equal('crash') expect(body.account.displayName).to.equal('Crash Bandicoot') expect(body.role).to.equal(UserRole.MODERATOR) @@ -88,9 +76,8 @@ describe('Test id and pass auth plugins', function () { } { - const res = await getMyUserInformation(server.url, lagunaAccessToken) + const body = await server.usersCommand.getMyInfo({ token: lagunaAccessToken }) - const body: User = res.body expect(body.username).to.equal('laguna') expect(body.account.displayName).to.equal('laguna') expect(body.role).to.equal(UserRole.USER) @@ -103,9 +90,8 @@ describe('Test id and pass auth plugins', function () { crashAccessToken = resRefresh.body.access_token crashRefreshToken = resRefresh.body.refresh_token - const res = await getMyUserInformation(server.url, crashAccessToken) - const user: User = res.body - expect(user.username).to.equal('crash') + const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) + expect(body.username).to.equal('crash') } { @@ -114,16 +100,14 @@ describe('Test id and pass auth plugins', function () { }) it('Should update Crash profile', async function () { - await updateMyUser({ - url: server.url, - accessToken: crashAccessToken, + await server.usersCommand.updateMe({ + token: crashAccessToken, displayName: 'Beautiful Crash', description: 'Mutant eastern barred bandicoot' }) - const res = await getMyUserInformation(server.url, crashAccessToken) + const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) - const body: User = res.body expect(body.account.displayName).to.equal('Beautiful Crash') expect(body.account.description).to.equal('Mutant eastern barred bandicoot') }) @@ -135,15 +119,14 @@ describe('Test id and pass auth plugins', function () { it('Should have logged out Crash', async function () { await server.serversCommand.waitUntilLog('On logout for auth 1 - 2') - await getMyUserInformation(server.url, crashAccessToken, 401) + await server.usersCommand.getMyInfo({ token: crashAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should login Crash and keep the old existing profile', async function () { crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' }) - const res = await getMyUserInformation(server.url, crashAccessToken) + const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) - const body: User = res.body expect(body.username).to.equal('crash') expect(body.account.displayName).to.equal('Beautiful Crash') expect(body.account.description).to.equal('Mutant eastern barred bandicoot') @@ -155,7 +138,7 @@ describe('Test id and pass auth plugins', function () { await wait(5000) - await getMyUserInformation(server.url, lagunaAccessToken, 401) + await server.usersCommand.getMyInfo({ token: lagunaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should reject an invalid username, email, role or display name', async function () { @@ -215,13 +198,11 @@ describe('Test id and pass auth plugins', function () { }) it('Should display plugin auth information in users list', async function () { - const res = await getUsersList(server.url, server.accessToken) - - const users: User[] = res.body.data + const { data } = await server.usersCommand.list() - const root = users.find(u => u.username === 'root') - const crash = users.find(u => u.username === 'crash') - const laguna = users.find(u => u.username === 'laguna') + const root = data.find(u => u.username === 'root') + const crash = data.find(u => u.username === 'crash') + const laguna = data.find(u => u.username === 'laguna') expect(root.pluginAuth).to.be.null expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one') -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/plugins/action-hooks.ts | 17 +++--- server/tests/plugins/filter-hooks.ts | 94 +++++++++++++----------------- server/tests/plugins/plugin-helpers.ts | 57 ++++++++---------- server/tests/plugins/plugin-transcoding.ts | 23 +++----- server/tests/plugins/video-constants.ts | 52 +++++------------ 5 files changed, 93 insertions(+), 150 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index b156f6b60..9e12c8aa7 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -9,10 +9,7 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - updateVideo, - uploadVideo, - viewVideo + setDefaultVideoChannel } from '@shared/extra-utils' import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' @@ -52,20 +49,20 @@ describe('Test plugin action hooks', function () { describe('Videos hooks', function () { it('Should run action:api.video.uploaded', async function () { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) + videoUUID = uuid await checkHook('action:api.video.uploaded') }) it('Should run action:api.video.updated', async function () { - await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) + await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video updated' } }) await checkHook('action:api.video.updated') }) it('Should run action:api.video.viewed', async function () { - await viewVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.view({ id: videoUUID }) await checkHook('action:api.video.viewed') }) @@ -170,8 +167,8 @@ describe('Test plugin action hooks', function () { } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' }) - videoId = res.body.video.id + const { id } = await servers[0].videosCommand.upload({ attributes: { name: 'my super name' } }) + videoId = id } }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index c82025f6a..e82aa3bfb 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -7,22 +7,12 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getAccountVideos, - getMyVideos, - getVideo, - getVideoChannelVideos, - getVideosList, - getVideosListPagination, - getVideoWithToken, ImportsCommand, makeRawRequest, PluginsCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateVideo, - uploadVideo, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' @@ -46,11 +36,11 @@ describe('Test plugin filter hooks', function () { await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) for (let i = 0; i < 10; i++) { - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) + await servers[0].videosCommand.upload({ attributes: { name: 'default video ' + i } }) } - const res = await getVideosList(servers[0].url) - videoUUID = res.body.data[0].uuid + const { data } = await servers[0].videosCommand.list() + videoUUID = data[0].uuid await servers[0].configCommand.updateCustomSubConfig({ newConfig: { @@ -67,69 +57,68 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.videos.list.params', async function () { - const res = await getVideosListPagination(servers[0].url, 0, 2) + const { data } = await servers[0].videosCommand.list({ start: 0, count: 2 }) // 2 plugins do +1 to the count parameter - expect(res.body.data).to.have.lengthOf(4) + expect(data).to.have.lengthOf(4) }) it('Should run filter:api.videos.list.result', async function () { - const res = await getVideosListPagination(servers[0].url, 0, 0) + const { total } = await servers[0].videosCommand.list({ start: 0, count: 0 }) // Plugin do +1 to the total result - expect(res.body.total).to.equal(11) + expect(total).to.equal(11) }) it('Should run filter:api.accounts.videos.list.params', async function () { - const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) + const { data } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 }) // 1 plugin do +1 to the count parameter - expect(res.body.data).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) }) it('Should run filter:api.accounts.videos.list.result', async function () { - const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) + const { total } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 }) // Plugin do +2 to the total result - expect(res.body.total).to.equal(12) + expect(total).to.equal(12) }) it('Should run filter:api.video-channels.videos.list.params', async function () { - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) + const { data } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) // 1 plugin do +3 to the count parameter - expect(res.body.data).to.have.lengthOf(5) + expect(data).to.have.lengthOf(5) }) it('Should run filter:api.video-channels.videos.list.result', async function () { - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) + const { total } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) // Plugin do +3 to the total result - expect(res.body.total).to.equal(13) + expect(total).to.equal(13) }) it('Should run filter:api.user.me.videos.list.params', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) + const { data } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 }) // 1 plugin do +4 to the count parameter - expect(res.body.data).to.have.lengthOf(6) + expect(data).to.have.lengthOf(6) }) it('Should run filter:api.user.me.videos.list.result', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) + const { total } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 }) // Plugin do +4 to the total result - expect(res.body.total).to.equal(14) + expect(total).to.equal(14) }) it('Should run filter:api.video.get.result', async function () { - const res = await getVideo(servers[0].url, videoUUID) - - expect(res.body.name).to.contain('<3') + const video = await servers[0].videosCommand.get({ id: videoUUID }) + expect(video.name).to.contain('<3') }) it('Should run filter:api.video.upload.accept.result', async function () { - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) + await servers[0].videosCommand.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.live-video.create.accept.result', async function () { @@ -270,14 +259,13 @@ describe('Test plugin filter hooks', function () { describe('Should run filter:video.auto-blacklist.result', function () { async function checkIsBlacklisted (id: number | string, value: boolean) { - const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id) - const video: VideoDetails = res.body + const video = await servers[0].videosCommand.getWithToken({ id }) expect(video.blacklisted).to.equal(value) } it('Should blacklist on upload', async function () { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) - await checkIsBlacklisted(res.body.video.uuid, true) + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video please blacklist me' } }) + await checkIsBlacklisted(uuid, true) }) it('Should blacklist on import', async function () { @@ -293,36 +281,34 @@ describe('Test plugin filter hooks', function () { }) it('Should blacklist on update', async function () { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) - const videoId = res.body.video.uuid - await checkIsBlacklisted(videoId, false) + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) + await checkIsBlacklisted(uuid, false) - await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) - await checkIsBlacklisted(videoId, true) + await servers[0].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } }) + await checkIsBlacklisted(uuid, true) }) it('Should blacklist on remote upload', async function () { this.timeout(120000) - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'remote please blacklist me' } }) await waitJobs(servers) - await checkIsBlacklisted(res.body.video.uuid, true) + await checkIsBlacklisted(uuid, true) }) it('Should blacklist on remote update', async function () { this.timeout(120000) - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video' } }) await waitJobs(servers) - const videoId = res.body.video.uuid - await checkIsBlacklisted(videoId, false) + await checkIsBlacklisted(uuid, false) - await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) + await servers[1].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } }) await waitJobs(servers) - await checkIsBlacklisted(videoId, true) + await checkIsBlacklisted(uuid, true) }) }) @@ -370,15 +356,14 @@ describe('Test plugin filter hooks', function () { const uuids: string[] = [] for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { - const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid + const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid uuids.push(uuid) } await waitJobs(servers) for (const uuid of uuids) { - const res = await getVideo(servers[0].url, uuid) - downloadVideos.push(res.body) + downloadVideos.push(await servers[0].videosCommand.get({ id: uuid })) } }) @@ -428,9 +413,8 @@ describe('Test plugin filter hooks', function () { for (const name of [ 'bad embed', 'good embed' ]) { { - const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid - const res = await getVideo(servers[0].url, uuid) - embedVideos.push(res.body) + const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid + embedVideos.push(await servers[0].videosCommand.get({ id: uuid })) } { diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index cbb6887eb..509aba13d 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -8,15 +8,11 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideosList, makeGetRequest, makePostBodyRequest, PluginsCommand, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, - viewVideo, waitJobs } from '@shared/extra-utils' @@ -144,59 +140,54 @@ describe('Test plugin helpers', function () { this.timeout(60000) { - const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) + const res = await await servers[0].videosCommand.quickUpload({ name: 'video server 1' }) videoUUIDServer1 = res.uuid } { - await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) + await await servers[1].videosCommand.quickUpload({ name: 'video server 2' }) } await waitJobs(servers) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(2) + expect(data).to.have.lengthOf(2) }) it('Should mute server 2', async function () { this.timeout(10000) await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('video server 1') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video server 1') }) it('Should unmute server 2', async function () { await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(2) + expect(data).to.have.lengthOf(2) }) it('Should mute account of server 2', async function () { await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('video server 1') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video server 1') }) it('Should unmute account of server 2', async function () { await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) - const res = await getVideosList(servers[0].url) - const videos = res.body.data + const { data } = await servers[0].videosCommand.list() - expect(videos).to.have.lengthOf(2) + expect(data).to.have.lengthOf(2) }) it('Should blacklist video', async function () { @@ -207,11 +198,10 @@ describe('Test plugin helpers', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data + const { data } = await server.videosCommand.list() - expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('video server 2') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video server 2') } }) @@ -223,10 +213,9 @@ describe('Test plugin helpers', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data + const { data } = await server.videosCommand.list() - expect(videos).to.have.lengthOf(2) + expect(data).to.have.lengthOf(2) } }) }) @@ -235,7 +224,7 @@ describe('Test plugin helpers', function () { let videoUUID: string before(async () => { - const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' }) + const res = await await servers[0].videosCommand.quickUpload({ name: 'video1' }) videoUUID = res.uuid }) @@ -243,15 +232,15 @@ describe('Test plugin helpers', function () { this.timeout(40000) // Should not throw -> video exists - await getVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.get({ id: videoUUID }) // Should delete the video - await viewVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.view({ id: videoUUID }) await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.') try { // Should throw because the video should have been deleted - await getVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.get({ id: videoUUID }) throw new Error('Video exists') } catch (err) { if (err.message.includes('exists')) throw err diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index 4839e8792..a3613293a 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -7,16 +7,14 @@ import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server import { cleanupTests, flushAndRunServer, - getVideo, PluginsCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, testFfmpegStreamError, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' -import { VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoPrivacy } from '@shared/models' async function createLiveWrapper (server: ServerInfo) { const liveAttributes = { @@ -81,8 +79,7 @@ describe('Test transcoding plugins', function () { describe('When using a plugin adding profiles to existing encoders', function () { async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) { - const res = await getVideo(server.url, uuid) - const video = res.body as VideoDetails + const video = await server.videosCommand.get({ id: uuid }) const files = video.files.concat(...video.streamingPlaylists.map(p => p.files)) for (const file of files) { @@ -119,7 +116,7 @@ describe('Test transcoding plugins', function () { it('Should not use the plugin profile if not chosen by the admin', async function () { this.timeout(240000) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'above', 20) @@ -130,7 +127,7 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'low-vod', 'default') - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'below', 12) @@ -141,7 +138,7 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'input-options-vod', 'default') - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'below', 6) @@ -152,13 +149,11 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'bad-scale-vod', 'default') - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) // Transcoding failed - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.files).to.have.lengthOf(1) expect(video.streamingPlaylists).to.have.lengthOf(0) }) @@ -224,7 +219,7 @@ describe('Test transcoding plugins', function () { expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'above', 20) @@ -243,7 +238,7 @@ describe('Test transcoding plugins', function () { it('Should use the new vod encoders', async function () { this.timeout(240000) - const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid + const videoUUID = (await server.videosCommand.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid await waitJobs([ server ]) const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index 4a05af042..641e37fbb 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -3,20 +3,8 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - getVideo, - getVideoCategories, - getVideoLanguages, - getVideoLicences, - getVideoPrivacies, - PluginsCommand, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '@shared/extra-utils' -import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models' +import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -33,8 +21,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated languages', async function () { - const res = await getVideoLanguages(server.url) - const languages = res.body + const languages = await server.videosCommand.getLanguages() expect(languages['en']).to.not.exist expect(languages['fr']).to.not.exist @@ -45,8 +32,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated categories', async function () { - const res = await getVideoCategories(server.url) - const categories = res.body + const categories = await server.videosCommand.getCategories() expect(categories[1]).to.not.exist expect(categories[2]).to.not.exist @@ -56,8 +42,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated licences', async function () { - const res = await getVideoLicences(server.url) - const licences = res.body + const licences = await server.videosCommand.getLicences() expect(licences[1]).to.not.exist expect(licences[7]).to.not.exist @@ -67,8 +52,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated video privacies', async function () { - const res = await getVideoPrivacies(server.url) - const privacies = res.body + const privacies = await server.videosCommand.getPrivacies() expect(privacies[1]).to.exist expect(privacies[2]).to.not.exist @@ -85,8 +69,8 @@ describe('Test plugin altering video constants', function () { }) it('Should not be able to create a video with this privacy', async function () { - const attrs = { name: 'video', privacy: 2 } - await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) + const attributes = { name: 'video', privacy: 2 } + await server.videosCommand.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not be able to create a video with this privacy', async function () { @@ -95,12 +79,10 @@ describe('Test plugin altering video constants', function () { }) it('Should be able to upload a video with these values', async function () { - const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } - const resUpload = await uploadVideo(server.url, server.accessToken, attrs) + const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } + const { uuid } = await server.videosCommand.upload({ attributes }) - const res = await getVideo(server.url, resUpload.body.video.uuid) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: uuid }) expect(video.language.label).to.equal('Al Bhed 2') expect(video.licence.label).to.equal('Best licence') expect(video.category.label).to.equal('Best category') @@ -110,8 +92,7 @@ describe('Test plugin altering video constants', function () { await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) { - const res = await getVideoLanguages(server.url) - const languages = res.body + const languages = await server.videosCommand.getLanguages() expect(languages['en']).to.equal('English') expect(languages['fr']).to.equal('French') @@ -122,8 +103,7 @@ describe('Test plugin altering video constants', function () { } { - const res = await getVideoCategories(server.url) - const categories = res.body + const categories = await server.videosCommand.getCategories() expect(categories[1]).to.equal('Music') expect(categories[2]).to.equal('Films') @@ -133,8 +113,7 @@ describe('Test plugin altering video constants', function () { } { - const res = await getVideoLicences(server.url) - const licences = res.body + const licences = await server.videosCommand.getLicences() expect(licences[1]).to.equal('Attribution') expect(licences[7]).to.equal('Public Domain Dedication') @@ -144,8 +123,7 @@ describe('Test plugin altering video constants', function () { } { - const res = await getVideoPrivacies(server.url) - const privacies = res.body + const privacies = await server.videosCommand.getPrivacies() expect(privacies[1]).to.exist expect(privacies[2]).to.exist -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- server/tests/plugins/action-hooks.ts | 40 ++++---- server/tests/plugins/external-auth.ts | 66 ++++++------ server/tests/plugins/filter-hooks.ts | 160 ++++++++++++++--------------- server/tests/plugins/html-injection.ts | 2 +- server/tests/plugins/id-and-pass-auth.ts | 64 ++++++------ server/tests/plugins/plugin-helpers.ts | 42 ++++---- server/tests/plugins/plugin-router.ts | 4 +- server/tests/plugins/plugin-storage.ts | 12 +-- server/tests/plugins/plugin-transcoding.ts | 52 +++++----- server/tests/plugins/plugin-unloading.ts | 6 +- server/tests/plugins/translations.ts | 2 +- server/tests/plugins/video-constants.ts | 32 +++--- 12 files changed, 241 insertions(+), 241 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 9e12c8aa7..12d5c23c5 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -19,7 +19,7 @@ describe('Test plugin action hooks', function () { let threadId: number function checkHook (hook: ServerHookName) { - return servers[0].serversCommand.waitUntilLog('Run hook ' + hook) + return servers[0].servers.waitUntilLog('Run hook ' + hook) } before(async function () { @@ -29,7 +29,7 @@ describe('Test plugin action hooks', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) + await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() }) await killallServers([ servers[0] ]) @@ -49,20 +49,20 @@ describe('Test plugin action hooks', function () { describe('Videos hooks', function () { it('Should run action:api.video.uploaded', async function () { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } }) videoUUID = uuid await checkHook('action:api.video.uploaded') }) it('Should run action:api.video.updated', async function () { - await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video updated' } }) + await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } }) await checkHook('action:api.video.updated') }) it('Should run action:api.video.viewed', async function () { - await servers[0].videosCommand.view({ id: videoUUID }) + await servers[0].videos.view({ id: videoUUID }) await checkHook('action:api.video.viewed') }) @@ -74,10 +74,10 @@ describe('Test plugin action hooks', function () { const attributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, - channelId: servers[0].videoChannel.id + channelId: servers[0].store.channel.id } - await servers[0].liveCommand.create({ fields: attributes }) + await servers[0].live.create({ fields: attributes }) await checkHook('action:api.live-video.created') }) @@ -85,20 +85,20 @@ describe('Test plugin action hooks', function () { describe('Comments hooks', function () { it('Should run action:api.video-thread.created', async function () { - const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' }) + const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' }) threadId = created.id await checkHook('action:api.video-thread.created') }) it('Should run action:api.video-comment-reply.created', async function () { - await servers[0].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' }) + await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' }) await checkHook('action:api.video-comment-reply.created') }) it('Should run action:api.video-comment.deleted', async function () { - await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId: threadId }) + await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId }) await checkHook('action:api.video-comment.deleted') }) @@ -108,44 +108,44 @@ describe('Test plugin action hooks', function () { let userId: number it('Should run action:api.user.registered', async function () { - await servers[0].usersCommand.register({ username: 'registered_user' }) + await servers[0].users.register({ username: 'registered_user' }) await checkHook('action:api.user.registered') }) it('Should run action:api.user.created', async function () { - const user = await servers[0].usersCommand.create({ username: 'created_user' }) + const user = await servers[0].users.create({ username: 'created_user' }) userId = user.id await checkHook('action:api.user.created') }) it('Should run action:api.user.oauth2-got-token', async function () { - await servers[0].loginCommand.getAccessToken('created_user', 'super_password') + await servers[0].login.getAccessToken('created_user', 'super_password') await checkHook('action:api.user.oauth2-got-token') }) it('Should run action:api.user.blocked', async function () { - await servers[0].usersCommand.banUser({ userId }) + await servers[0].users.banUser({ userId }) await checkHook('action:api.user.blocked') }) it('Should run action:api.user.unblocked', async function () { - await servers[0].usersCommand.unbanUser({ userId }) + await servers[0].users.unbanUser({ userId }) await checkHook('action:api.user.unblocked') }) it('Should run action:api.user.updated', async function () { - await servers[0].usersCommand.update({ userId, videoQuota: 50 }) + await servers[0].users.update({ userId, videoQuota: 50 }) await checkHook('action:api.user.updated') }) it('Should run action:api.user.deleted', async function () { - await servers[0].usersCommand.remove({ userId }) + await servers[0].users.remove({ userId }) await checkHook('action:api.user.deleted') }) @@ -157,7 +157,7 @@ describe('Test plugin action hooks', function () { before(async function () { { - const { id } = await servers[0].playlistsCommand.create({ + const { id } = await servers[0].playlists.create({ attributes: { displayName: 'My playlist', privacy: VideoPlaylistPrivacy.PRIVATE @@ -167,13 +167,13 @@ describe('Test plugin action hooks', function () { } { - const { id } = await servers[0].videosCommand.upload({ attributes: { name: 'my super name' } }) + const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } }) videoId = id } }) it('Should run action:api.video-playlist-element.created', async function () { - await servers[0].playlistsCommand.addElement({ playlistId, attributes: { videoId } }) + await servers[0].playlists.addElement({ playlistId, attributes: { videoId } }) await checkHook('action:api.video-playlist-element.created') }) diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index 3e8305611..48f942f7f 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -23,7 +23,7 @@ async function loginExternal (options: { statusCodeExpected?: HttpStatusCode statusCodeExpectedStep2?: HttpStatusCode }) { - const res = await options.server.pluginsCommand.getExternalAuth({ + const res = await options.server.plugins.getExternalAuth({ npmName: options.npmName, npmVersion: '0.0.1', authName: options.authName, @@ -36,7 +36,7 @@ async function loginExternal (options: { const location = res.header.location const { externalAuthToken } = decodeQueryString(location) - const resLogin = await options.server.loginCommand.loginUsingExternalToken({ + const resLogin = await options.server.login.loginUsingExternalToken({ username: options.username, externalAuthToken: externalAuthToken as string, expectedStatus: options.statusCodeExpectedStep2 @@ -63,12 +63,12 @@ describe('Test external auth plugins', function () { await setAccessTokensToServers([ server ]) for (const suffix of [ 'one', 'two', 'three' ]) { - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-external-auth-' + suffix) }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-external-auth-' + suffix) }) } }) it('Should display the correct configuration', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(8) @@ -80,7 +80,7 @@ describe('Test external auth plugins', function () { }) it('Should redirect for a Cyan login', async function () { - const res = await server.pluginsCommand.getExternalAuth({ + const res = await server.plugins.getExternalAuth({ npmName: 'test-external-auth-one', npmVersion: '0.0.1', authName: 'external-auth-1', @@ -102,14 +102,14 @@ describe('Test external auth plugins', function () { }) it('Should reject auto external login with a missing or invalid token', async function () { - const command = server.loginCommand + const command = server.login await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should reject auto external login with a missing or invalid username', async function () { - const command = server.loginCommand + const command = server.login await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) @@ -120,13 +120,13 @@ describe('Test external auth plugins', function () { await wait(5000) - await server.loginCommand.loginUsingExternalToken({ + await server.login.loginUsingExternalToken({ username: 'cyan', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await server.serversCommand.waitUntilLog('expired external auth token', 2) + await server.servers.waitUntilLog('expired external auth token', 2) }) it('Should auto login Cyan, create the user and use the token', async function () { @@ -146,7 +146,7 @@ describe('Test external auth plugins', function () { } { - const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) + const body = await server.users.getMyInfo({ token: cyanAccessToken }) expect(body.username).to.equal('cyan') expect(body.account.displayName).to.equal('cyan') expect(body.email).to.equal('cyan@example.com') @@ -168,7 +168,7 @@ describe('Test external auth plugins', function () { } { - const body = await server.usersCommand.getMyInfo({ token: kefkaAccessToken }) + const body = await server.users.getMyInfo({ token: kefkaAccessToken }) expect(body.username).to.equal('kefka') expect(body.account.displayName).to.equal('Kefka Palazzo') expect(body.email).to.equal('kefka@example.com') @@ -178,39 +178,39 @@ describe('Test external auth plugins', function () { it('Should refresh Cyan token, but not Kefka token', async function () { { - const resRefresh = await server.loginCommand.refreshToken({ refreshToken: cyanRefreshToken }) + const resRefresh = await server.login.refreshToken({ refreshToken: cyanRefreshToken }) cyanAccessToken = resRefresh.body.access_token cyanRefreshToken = resRefresh.body.refresh_token - const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) + const body = await server.users.getMyInfo({ token: cyanAccessToken }) expect(body.username).to.equal('cyan') } { - await server.loginCommand.refreshToken({ refreshToken: kefkaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.refreshToken({ refreshToken: kefkaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) it('Should update Cyan profile', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: cyanAccessToken, displayName: 'Cyan Garamonde', description: 'Retainer to the king of Doma' }) - const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) + const body = await server.users.getMyInfo({ token: cyanAccessToken }) expect(body.account.displayName).to.equal('Cyan Garamonde') expect(body.account.description).to.equal('Retainer to the king of Doma') }) it('Should logout Cyan', async function () { - await server.loginCommand.logout({ token: cyanAccessToken }) + await server.login.logout({ token: cyanAccessToken }) }) it('Should have logged out Cyan', async function () { - await server.serversCommand.waitUntilLog('On logout cyan') + await server.servers.waitUntilLog('On logout cyan') - await server.usersCommand.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should login Cyan and keep the old existing profile', async function () { @@ -228,7 +228,7 @@ describe('Test external auth plugins', function () { cyanAccessToken = res.access_token } - const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) + const body = await server.users.getMyInfo({ token: cyanAccessToken }) expect(body.username).to.equal('cyan') expect(body.account.displayName).to.equal('Cyan Garamonde') expect(body.account.description).to.equal('Retainer to the king of Doma') @@ -236,7 +236,7 @@ describe('Test external auth plugins', function () { }) it('Should not update an external auth email', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: cyanAccessToken, email: 'toto@example.com', currentPassword: 'toto', @@ -249,16 +249,16 @@ describe('Test external auth plugins', function () { await wait(5000) - await server.usersCommand.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should unregister external-auth-2 and do not login existing Kefka', async function () { - await server.pluginsCommand.updateSettings({ + await server.plugins.updateSettings({ npmName: 'peertube-plugin-test-external-auth-one', settings: { disableKefka: true } }) - await server.loginCommand.login({ user: { username: 'kefka', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user: { username: 'kefka', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await loginExternal({ server, @@ -273,7 +273,7 @@ describe('Test external auth plugins', function () { }) it('Should have disabled this auth', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(7) @@ -283,7 +283,7 @@ describe('Test external auth plugins', function () { }) it('Should uninstall the plugin one and do not login Cyan', async function () { - await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-external-auth-one' }) + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-external-auth-one' }) await loginExternal({ server, @@ -296,9 +296,9 @@ describe('Test external auth plugins', function () { statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) - await server.loginCommand.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await server.loginCommand.login({ user: { username: 'cyan', password: '' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await server.loginCommand.login({ user: { username: 'cyan', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user: { username: 'cyan', password: '' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user: { username: 'cyan', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not login kefka with another plugin', async function () { @@ -320,7 +320,7 @@ describe('Test external auth plugins', function () { }) it('Should not login an existing user', async function () { - await server.usersCommand.create({ username: 'existing_user', password: 'super_password' }) + await server.users.create({ username: 'existing_user', password: 'super_password' }) await loginExternal({ server, @@ -332,7 +332,7 @@ describe('Test external auth plugins', function () { }) it('Should display the correct configuration', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(6) @@ -353,7 +353,7 @@ describe('Test external auth plugins', function () { username: 'cid' }) - const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token }) + const { redirectUrl } = await server.login.logout({ token: resLogin.access_token }) expect(redirectUrl).to.equal('https://example.com/redirectUrl') }) @@ -365,7 +365,7 @@ describe('Test external auth plugins', function () { username: 'cid' }) - const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token }) + const { redirectUrl } = await server.login.logout({ token: resLogin.access_token }) expect(redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token) }) }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index e82aa3bfb..18479dcf5 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -32,17 +32,17 @@ describe('Test plugin filter hooks', function () { await setDefaultVideoChannel(servers) await doubleFollow(servers[0], servers[1]) - await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) - await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) + await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() }) + await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) for (let i = 0; i < 10; i++) { - await servers[0].videosCommand.upload({ attributes: { name: 'default video ' + i } }) + await servers[0].videos.upload({ attributes: { name: 'default video ' + i } }) } - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() videoUUID = data[0].uuid - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true }, signup: { enabled: true }, @@ -57,98 +57,98 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.videos.list.params', async function () { - const { data } = await servers[0].videosCommand.list({ start: 0, count: 2 }) + const { data } = await servers[0].videos.list({ start: 0, count: 2 }) // 2 plugins do +1 to the count parameter expect(data).to.have.lengthOf(4) }) it('Should run filter:api.videos.list.result', async function () { - const { total } = await servers[0].videosCommand.list({ start: 0, count: 0 }) + const { total } = await servers[0].videos.list({ start: 0, count: 0 }) // Plugin do +1 to the total result expect(total).to.equal(11) }) it('Should run filter:api.accounts.videos.list.params', async function () { - const { data } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 }) + const { data } = await servers[0].videos.listByAccount({ accountName: 'root', start: 0, count: 2 }) // 1 plugin do +1 to the count parameter expect(data).to.have.lengthOf(3) }) it('Should run filter:api.accounts.videos.list.result', async function () { - const { total } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 }) + const { total } = await servers[0].videos.listByAccount({ accountName: 'root', start: 0, count: 2 }) // Plugin do +2 to the total result expect(total).to.equal(12) }) it('Should run filter:api.video-channels.videos.list.params', async function () { - const { data } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) + const { data } = await servers[0].videos.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) // 1 plugin do +3 to the count parameter expect(data).to.have.lengthOf(5) }) it('Should run filter:api.video-channels.videos.list.result', async function () { - const { total } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) + const { total } = await servers[0].videos.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) // Plugin do +3 to the total result expect(total).to.equal(13) }) it('Should run filter:api.user.me.videos.list.params', async function () { - const { data } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 }) + const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 }) // 1 plugin do +4 to the count parameter expect(data).to.have.lengthOf(6) }) it('Should run filter:api.user.me.videos.list.result', async function () { - const { total } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 }) + const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 }) // Plugin do +4 to the total result expect(total).to.equal(14) }) it('Should run filter:api.video.get.result', async function () { - const video = await servers[0].videosCommand.get({ id: videoUUID }) + const video = await servers[0].videos.get({ id: videoUUID }) expect(video.name).to.contain('<3') }) it('Should run filter:api.video.upload.accept.result', async function () { - await servers[0].videosCommand.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.live-video.create.accept.result', async function () { const attributes = { name: 'video with bad word', privacy: VideoPrivacy.PUBLIC, - channelId: servers[0].videoChannel.id + channelId: servers[0].store.channel.id } - await servers[0].liveCommand.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.video.pre-import-url.accept.result', async function () { const attributes = { name: 'normal title', privacy: VideoPrivacy.PUBLIC, - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, targetUrl: ImportsCommand.getGoodVideoUrl() + 'bad' } - await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { const attributes = { name: 'bad torrent', privacy: VideoPrivacy.PUBLIC, - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, torrentfile: 'video-720p.torrent' as any } - await servers[0].importsCommand.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should run filter:api.video.post-import-url.accept.result', async function () { @@ -160,17 +160,17 @@ describe('Test plugin filter hooks', function () { const attributes = { name: 'title with bad word', privacy: VideoPrivacy.PUBLIC, - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, targetUrl: ImportsCommand.getGoodVideoUrl() } - const body = await servers[0].importsCommand.importVideo({ attributes }) + const body = await servers[0].imports.importVideo({ attributes }) videoImportId = body.id } await waitJobs(servers) { - const body = await servers[0].importsCommand.getMyVideoImports() + const body = await servers[0].imports.getMyVideoImports() const videoImports = body.data const videoImport = videoImports.find(i => i.id === videoImportId) @@ -189,17 +189,17 @@ describe('Test plugin filter hooks', function () { const attributes = { name: 'title with bad word', privacy: VideoPrivacy.PUBLIC, - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, torrentfile: 'video-720p.torrent' as any } - const body = await servers[0].importsCommand.importVideo({ attributes }) + const body = await servers[0].imports.importVideo({ attributes }) videoImportId = body.id } await waitJobs(servers) { - const { data: videoImports } = await servers[0].importsCommand.getMyVideoImports() + const { data: videoImports } = await servers[0].imports.getMyVideoImports() const videoImport = videoImports.find(i => i.id === videoImportId) @@ -209,7 +209,7 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.video-thread.create.accept.result', async function () { - await servers[0].commentsCommand.createThread({ + await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment with bad word', expectedStatus: HttpStatusCode.FORBIDDEN_403 @@ -217,16 +217,16 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.video-comment-reply.create.accept.result', async function () { - const created = await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'thread' }) + const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' }) threadId = created.id - await servers[0].commentsCommand.addReply({ + await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'comment with bad word', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) - await servers[0].commentsCommand.addReply({ + await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'comment with good word', @@ -235,14 +235,14 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.video-threads.list.params', async function () { - const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 0 }) + const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 }) // our plugin do +1 to the count parameter expect(data).to.have.lengthOf(1) }) it('Should run filter:api.video-threads.list.result', async function () { - const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 0 }) + const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 }) // Plugin do +1 to the total result expect(total).to.equal(2) @@ -251,7 +251,7 @@ describe('Test plugin filter hooks', function () { it('Should run filter:api.video-thread-comments.list.params') it('Should run filter:api.video-thread-comments.list.result', async function () { - const thread = await servers[0].commentsCommand.getThread({ videoId: videoUUID, threadId }) + const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId }) expect(thread.comment.text.endsWith(' <3')).to.be.true }) @@ -259,12 +259,12 @@ describe('Test plugin filter hooks', function () { describe('Should run filter:video.auto-blacklist.result', function () { async function checkIsBlacklisted (id: number | string, value: boolean) { - const video = await servers[0].videosCommand.getWithToken({ id }) + const video = await servers[0].videos.getWithToken({ id }) expect(video.blacklisted).to.equal(value) } it('Should blacklist on upload', async function () { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video please blacklist me' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video please blacklist me' } }) await checkIsBlacklisted(uuid, true) }) @@ -274,24 +274,24 @@ describe('Test plugin filter hooks', function () { const attributes = { name: 'video please blacklist me', targetUrl: ImportsCommand.getGoodVideoUrl(), - channelId: servers[0].videoChannel.id + channelId: servers[0].store.channel.id } - const body = await servers[0].importsCommand.importVideo({ attributes }) + const body = await servers[0].imports.importVideo({ attributes }) await checkIsBlacklisted(body.video.uuid, true) }) it('Should blacklist on update', async function () { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } }) await checkIsBlacklisted(uuid, false) - await servers[0].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } }) + await servers[0].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } }) await checkIsBlacklisted(uuid, true) }) it('Should blacklist on remote upload', async function () { this.timeout(120000) - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'remote please blacklist me' } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'remote please blacklist me' } }) await waitJobs(servers) await checkIsBlacklisted(uuid, true) @@ -300,12 +300,12 @@ describe('Test plugin filter hooks', function () { it('Should blacklist on remote update', async function () { this.timeout(120000) - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video' } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video' } }) await waitJobs(servers) await checkIsBlacklisted(uuid, false) - await servers[1].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } }) + await servers[1].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } }) await waitJobs(servers) await checkIsBlacklisted(uuid, true) @@ -315,16 +315,16 @@ describe('Test plugin filter hooks', function () { describe('Should run filter:api.user.signup.allowed.result', function () { it('Should run on config endpoint', async function () { - const body = await servers[0].configCommand.getConfig() + const body = await servers[0].config.getConfig() expect(body.signup.allowed).to.be.true }) it('Should allow a signup', async function () { - await servers[0].usersCommand.register({ username: 'john', password: 'password' }) + await servers[0].users.register({ username: 'john', password: 'password' }) }) it('Should not allow a signup', async function () { - const res = await servers[0].usersCommand.register({ + const res = await servers[0].users.register({ username: 'jma', password: 'password', expectedStatus: HttpStatusCode.FORBIDDEN_403 @@ -340,7 +340,7 @@ describe('Test plugin filter hooks', function () { before(async function () { this.timeout(120000) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { webtorrent: { @@ -356,14 +356,14 @@ describe('Test plugin filter hooks', function () { const uuids: string[] = [] for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { - const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid + const uuid = (await servers[0].videos.quickUpload({ name: name })).uuid uuids.push(uuid) } await waitJobs(servers) for (const uuid of uuids) { - downloadVideos.push(await servers[0].videosCommand.get({ id: uuid })) + downloadVideos.push(await servers[0].videos.get({ id: uuid })) } }) @@ -403,7 +403,7 @@ describe('Test plugin filter hooks', function () { before(async function () { this.timeout(60000) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: false @@ -413,15 +413,15 @@ describe('Test plugin filter hooks', function () { for (const name of [ 'bad embed', 'good embed' ]) { { - const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid - embedVideos.push(await servers[0].videosCommand.get({ id: uuid })) + const uuid = (await servers[0].videos.quickUpload({ name: name })).uuid + embedVideos.push(await servers[0].videos.get({ id: uuid })) } { - const attributes = { displayName: name, videoChannelId: servers[0].videoChannel.id, privacy: VideoPlaylistPrivacy.PUBLIC } - const { id } = await servers[0].playlistsCommand.create({ attributes }) + const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC } + const { id } = await servers[0].playlists.create({ attributes }) - const playlist = await servers[0].playlistsCommand.get({ playlistId: id }) + const playlist = await servers[0].playlists.get({ playlistId: id }) embedPlaylists.push(playlist) } } @@ -441,7 +441,7 @@ describe('Test plugin filter hooks', function () { describe('Search filters', function () { before(async function () { - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { search: { searchIndex: { @@ -455,78 +455,78 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.search.videos.local.list.{params,result}', async function () { - await servers[0].searchCommand.advancedVideoSearch({ + await servers[0].search.advancedVideoSearch({ search: { search: 'Sun Quan' } }) - 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].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1) }) it('Should run filter:api.search.videos.index.list.{params,result}', async function () { - await servers[0].searchCommand.advancedVideoSearch({ + await servers[0].search.advancedVideoSearch({ search: { search: 'Sun Quan', searchTarget: 'search-index' } }) - 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) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1) + await servers[0].servers.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 () { - await servers[0].searchCommand.advancedChannelSearch({ + await servers[0].search.advancedChannelSearch({ search: { search: 'Sun Ce' } }) - 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].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1) + await servers[0].servers.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 () { - await servers[0].searchCommand.advancedChannelSearch({ + await servers[0].search.advancedChannelSearch({ search: { search: 'Sun Ce', searchTarget: 'search-index' } }) - 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) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1) + await servers[0].servers.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 () { - await servers[0].searchCommand.advancedPlaylistSearch({ + await servers[0].search.advancedPlaylistSearch({ search: { search: 'Sun Jian' } }) - 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].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1) + await servers[0].servers.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 () { - await servers[0].searchCommand.advancedPlaylistSearch({ + await servers[0].search.advancedPlaylistSearch({ search: { search: 'Sun Jian', searchTarget: 'search-index' } }) - 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) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1) + await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1) }) }) diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts index 80d67ae0e..0cb89f511 100644 --- a/server/tests/plugins/html-injection.ts +++ b/server/tests/plugins/html-injection.ts @@ -23,7 +23,7 @@ describe('Test plugins HTML injection', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - command = server.pluginsCommand + command = server.plugins }) it('Should not inject global css file in HTML', async function () { diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 787080e7c..203996af8 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -22,12 +22,12 @@ describe('Test id and pass auth plugins', function () { await setAccessTokensToServers([ server ]) for (const suffix of [ 'one', 'two', 'three' ]) { - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-id-pass-auth-' + suffix) }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-id-pass-auth-' + suffix) }) } }) it('Should display the correct configuration', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(8) @@ -39,13 +39,13 @@ describe('Test id and pass auth plugins', function () { }) it('Should not login', async function () { - await server.loginCommand.login({ user: { username: 'toto', password: 'password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user: { username: 'toto', password: 'password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should login Spyro, create the user and use the token', async function () { - const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' }) + const accessToken = await server.login.getAccessToken({ username: 'spyro', password: 'spyro password' }) - const body = await server.usersCommand.getMyInfo({ token: accessToken }) + const body = await server.users.getMyInfo({ token: accessToken }) expect(body.username).to.equal('spyro') expect(body.account.displayName).to.equal('Spyro the Dragon') @@ -54,13 +54,13 @@ describe('Test id and pass auth plugins', function () { it('Should login Crash, create the user and use the token', async function () { { - const body = await server.loginCommand.login({ user: { username: 'crash', password: 'crash password' } }) + const body = await server.login.login({ user: { username: 'crash', password: 'crash password' } }) crashAccessToken = body.access_token crashRefreshToken = body.refresh_token } { - const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) + const body = await server.users.getMyInfo({ token: crashAccessToken }) expect(body.username).to.equal('crash') expect(body.account.displayName).to.equal('Crash Bandicoot') @@ -70,13 +70,13 @@ describe('Test id and pass auth plugins', function () { it('Should login the first Laguna, create the user and use the token', async function () { { - const body = await server.loginCommand.login({ user: { username: 'laguna', password: 'laguna password' } }) + const body = await server.login.login({ user: { username: 'laguna', password: 'laguna password' } }) lagunaAccessToken = body.access_token lagunaRefreshToken = body.refresh_token } { - const body = await server.usersCommand.getMyInfo({ token: lagunaAccessToken }) + const body = await server.users.getMyInfo({ token: lagunaAccessToken }) expect(body.username).to.equal('laguna') expect(body.account.displayName).to.equal('laguna') @@ -86,46 +86,46 @@ describe('Test id and pass auth plugins', function () { it('Should refresh crash token, but not laguna token', async function () { { - const resRefresh = await server.loginCommand.refreshToken({ refreshToken: crashRefreshToken }) + const resRefresh = await server.login.refreshToken({ refreshToken: crashRefreshToken }) crashAccessToken = resRefresh.body.access_token crashRefreshToken = resRefresh.body.refresh_token - const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) + const body = await server.users.getMyInfo({ token: crashAccessToken }) expect(body.username).to.equal('crash') } { - await server.loginCommand.refreshToken({ refreshToken: lagunaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.refreshToken({ refreshToken: lagunaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) it('Should update Crash profile', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: crashAccessToken, displayName: 'Beautiful Crash', description: 'Mutant eastern barred bandicoot' }) - const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) + const body = await server.users.getMyInfo({ token: crashAccessToken }) expect(body.account.displayName).to.equal('Beautiful Crash') expect(body.account.description).to.equal('Mutant eastern barred bandicoot') }) it('Should logout Crash', async function () { - await server.loginCommand.logout({ token: crashAccessToken }) + await server.login.logout({ token: crashAccessToken }) }) it('Should have logged out Crash', async function () { - await server.serversCommand.waitUntilLog('On logout for auth 1 - 2') + await server.servers.waitUntilLog('On logout for auth 1 - 2') - await server.usersCommand.getMyInfo({ token: crashAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ token: crashAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should login Crash and keep the old existing profile', async function () { - crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' }) + crashAccessToken = await server.login.getAccessToken({ username: 'crash', password: 'crash password' }) - const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) + const body = await server.users.getMyInfo({ token: crashAccessToken }) expect(body.username).to.equal('crash') expect(body.account.displayName).to.equal('Beautiful Crash') @@ -138,38 +138,38 @@ describe('Test id and pass auth plugins', function () { await wait(5000) - await server.usersCommand.getMyInfo({ token: lagunaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ token: lagunaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should reject an invalid username, email, role or display name', async function () { - const command = server.loginCommand + const command = server.login await command.login({ user: { username: 'ward', password: 'ward password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await server.serversCommand.waitUntilLog('valid username') + await server.servers.waitUntilLog('valid username') await command.login({ user: { username: 'kiros', password: 'kiros password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await server.serversCommand.waitUntilLog('valid display name') + await server.servers.waitUntilLog('valid display name') await command.login({ user: { username: 'raine', password: 'raine password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await server.serversCommand.waitUntilLog('valid role') + await server.servers.waitUntilLog('valid role') await command.login({ user: { username: 'ellone', password: 'elonne password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await server.serversCommand.waitUntilLog('valid email') + await server.servers.waitUntilLog('valid email') }) it('Should unregister spyro-auth and do not login existing Spyro', async function () { - await server.pluginsCommand.updateSettings({ + await server.plugins.updateSettings({ npmName: 'peertube-plugin-test-id-pass-auth-one', settings: { disableSpyro: true } }) - const command = server.loginCommand + const command = server.login await command.login({ user: { username: 'spyro', password: 'spyro password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await command.login({ user: { username: 'spyro', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should have disabled this auth', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(7) @@ -179,16 +179,16 @@ describe('Test id and pass auth plugins', function () { }) it('Should uninstall the plugin one and do not login existing Crash', async function () { - await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' }) + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' }) - await server.loginCommand.login({ + await server.login.login({ user: { username: 'crash', password: 'crash password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should display the correct configuration', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(6) @@ -198,7 +198,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should display plugin auth information in users list', async function () { - const { data } = await server.usersCommand.list() + const { data } = await server.users.list() const root = data.find(u => u.username === 'root') const crash = data.find(u => u.username === 'crash') diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 509aba13d..cf16aaa9d 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -39,28 +39,28 @@ describe('Test plugin helpers', function () { await doubleFollow(servers[0], servers[1]) - await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-four') }) + await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-four') }) }) describe('Logger', function () { it('Should have logged things', async function () { - 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) + await servers[0].servers.waitUntilLog('localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false) + await servers[0].servers.waitUntilLog('Hello world from plugin four', 1) }) }) describe('Database', function () { it('Should have made a query', async function () { - await servers[0].serversCommand.waitUntilLog(`root email is admin${servers[0].internalServerNumber}@example.com`) + await servers[0].servers.waitUntilLog(`root email is admin${servers[0].internalServerNumber}@example.com`) }) }) describe('Config', function () { it('Should have the correct webserver url', async function () { - await servers[0].serversCommand.waitUntilLog(`server url is http://localhost:${servers[0].port}`) + await servers[0].servers.waitUntilLog(`server url is http://localhost:${servers[0].port}`) }) it('Should have the correct config', async function () { @@ -78,7 +78,7 @@ describe('Test plugin helpers', function () { describe('Server', function () { it('Should get the server actor', async function () { - await servers[0].serversCommand.waitUntilLog('server actor name is peertube') + await servers[0].servers.waitUntilLog('server actor name is peertube') }) }) @@ -140,17 +140,17 @@ describe('Test plugin helpers', function () { this.timeout(60000) { - const res = await await servers[0].videosCommand.quickUpload({ name: 'video server 1' }) + const res = await await servers[0].videos.quickUpload({ name: 'video server 1' }) videoUUIDServer1 = res.uuid } { - await await servers[1].videosCommand.quickUpload({ name: 'video server 2' }) + await await servers[1].videos.quickUpload({ name: 'video server 2' }) } await waitJobs(servers) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data).to.have.lengthOf(2) }) @@ -159,7 +159,7 @@ describe('Test plugin helpers', function () { this.timeout(10000) await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data).to.have.lengthOf(1) expect(data[0].name).to.equal('video server 1') @@ -168,7 +168,7 @@ describe('Test plugin helpers', function () { it('Should unmute server 2', async function () { await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data).to.have.lengthOf(2) }) @@ -176,7 +176,7 @@ describe('Test plugin helpers', function () { it('Should mute account of server 2', async function () { await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data).to.have.lengthOf(1) expect(data[0].name).to.equal('video server 1') @@ -185,7 +185,7 @@ describe('Test plugin helpers', function () { it('Should unmute account of server 2', async function () { await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data).to.have.lengthOf(2) }) @@ -198,7 +198,7 @@ describe('Test plugin helpers', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.have.lengthOf(1) expect(data[0].name).to.equal('video server 2') @@ -213,7 +213,7 @@ describe('Test plugin helpers', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.have.lengthOf(2) } @@ -224,7 +224,7 @@ describe('Test plugin helpers', function () { let videoUUID: string before(async () => { - const res = await await servers[0].videosCommand.quickUpload({ name: 'video1' }) + const res = await await servers[0].videos.quickUpload({ name: 'video1' }) videoUUID = res.uuid }) @@ -232,15 +232,15 @@ describe('Test plugin helpers', function () { this.timeout(40000) // Should not throw -> video exists - await servers[0].videosCommand.get({ id: videoUUID }) + await servers[0].videos.get({ id: videoUUID }) // Should delete the video - await servers[0].videosCommand.view({ id: videoUUID }) + await servers[0].videos.view({ id: videoUUID }) - await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.') + await servers[0].servers.waitUntilLog('Video deleted by plugin four.') try { // Should throw because the video should have been deleted - await servers[0].videosCommand.get({ id: videoUUID }) + await servers[0].videos.get({ id: videoUUID }) throw new Error('Video exists') } catch (err) { if (err.message.includes('exists')) throw err @@ -250,7 +250,7 @@ describe('Test plugin helpers', function () { }) it('Should have fetched the video by URL', async function () { - await servers[0].serversCommand.waitUntilLog(`video from DB uuid is ${videoUUID}`) + await servers[0].servers.waitUntilLog(`video from DB uuid is ${videoUUID}`) }) }) diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts index 81e18dabd..1c53dd80c 100644 --- a/server/tests/plugins/plugin-router.ts +++ b/server/tests/plugins/plugin-router.ts @@ -26,7 +26,7 @@ describe('Test plugin helpers', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-five') }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') }) }) it('Should answer "pong"', async function () { @@ -82,7 +82,7 @@ describe('Test plugin helpers', function () { }) it('Should remove the plugin and remove the routes', async function () { - await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-five' }) + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-five' }) for (const path of basePaths) { await makeGetRequest({ diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 9babfc83e..30e231439 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts @@ -16,13 +16,13 @@ describe('Test plugin storage', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) }) describe('DB storage', function () { it('Should correctly store a subkey', async function () { - await server.serversCommand.waitUntilLog('superkey stored value is toto') + await server.servers.waitUntilLog('superkey stored value is toto') }) }) @@ -38,12 +38,12 @@ describe('Test plugin storage', function () { } before(function () { - dataPath = server.serversCommand.buildDirectory('plugins/data') + dataPath = server.servers.buildDirectory('plugins/data') pluginDataPath = join(dataPath, 'peertube-plugin-test-six') }) it('Should have created the directory on install', async function () { - const dataPath = server.serversCommand.buildDirectory('plugins/data') + const dataPath = server.servers.buildDirectory('plugins/data') const pluginDataPath = join(dataPath, 'peertube-plugin-test-six') expect(await pathExists(dataPath)).to.be.true @@ -64,14 +64,14 @@ describe('Test plugin storage', function () { }) it('Should still have the file after an uninstallation', async function () { - await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-six' }) + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' }) const content = await getFileContent() expect(content).to.equal('Prince Ali') }) it('Should still have the file after the reinstallation', async function () { - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) const content = await getFileContent() expect(content).to.equal('Prince Ali') diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index a3613293a..3a03065b0 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -19,17 +19,17 @@ import { VideoPrivacy } from '@shared/models' async function createLiveWrapper (server: ServerInfo) { const liveAttributes = { name: 'live video', - channelId: server.videoChannel.id, + channelId: server.store.channel.id, privacy: VideoPrivacy.PUBLIC } - const { uuid } = await server.liveCommand.create({ fields: liveAttributes }) + const { uuid } = await server.live.create({ fields: liveAttributes }) return uuid } function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { - return server.configCommand.updateCustomSubConfig({ + return server.config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: true, @@ -79,7 +79,7 @@ describe('Test transcoding plugins', function () { describe('When using a plugin adding profiles to existing encoders', function () { async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) { - const video = await server.videosCommand.get({ id: uuid }) + const video = await server.videos.get({ id: uuid }) const files = video.files.concat(...video.streamingPlaylists.map(p => p.files)) for (const file of files) { @@ -103,11 +103,11 @@ describe('Test transcoding plugins', function () { } before(async function () { - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') }) }) it('Should have the appropriate available profiles', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ]) expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ]) @@ -116,7 +116,7 @@ describe('Test transcoding plugins', function () { it('Should not use the plugin profile if not chosen by the admin', async function () { this.timeout(240000) - const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'above', 20) @@ -127,7 +127,7 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'low-vod', 'default') - const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'below', 12) @@ -138,7 +138,7 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'input-options-vod', 'default') - const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'below', 6) @@ -149,11 +149,11 @@ describe('Test transcoding plugins', function () { await updateConf(server, 'bad-scale-vod', 'default') - const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) // Transcoding failed - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.files).to.have.lengthOf(1) expect(video.streamingPlaylists).to.have.lengthOf(0) }) @@ -163,8 +163,8 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) - await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) + await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.live.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'above', 20) @@ -177,8 +177,8 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) - await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) + await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.live.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'below', 12) @@ -191,8 +191,8 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) - await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) + await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.live.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) await checkLiveFPS(liveVideoId, 'below', 6) @@ -205,21 +205,21 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - const command = await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + const command = await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) await testFfmpegStreamError(command, true) }) it('Should default to the default profile if the specified profile does not exist', async function () { this.timeout(240000) - await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) - const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid + const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid await waitJobs([ server ]) await checkVideoFPS(videoUUID, 'above', 20) @@ -230,7 +230,7 @@ describe('Test transcoding plugins', function () { describe('When using a plugin adding new encoders', function () { before(async function () { - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') }) await updateConf(server, 'test-vod-profile', 'test-live-profile') }) @@ -238,10 +238,10 @@ describe('Test transcoding plugins', function () { it('Should use the new vod encoders', async function () { this.timeout(240000) - const videoUUID = (await server.videosCommand.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid + const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid await waitJobs([ server ]) - const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) + const path = server.servers.buildDirectory(join('videos', videoUUID + '-240.mp4')) const audioProbe = await getAudioStream(path) expect(audioProbe.audioStream.codec_name).to.equal('opus') @@ -254,8 +254,8 @@ describe('Test transcoding plugins', function () { const liveVideoId = await createLiveWrapper(server) - await server.liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) - await server.liveCommand.waitUntilPublished({ videoId: liveVideoId }) + await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) + await server.live.waitUntilPublished({ videoId: liveVideoId }) await waitJobs([ server ]) const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8` diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts index f430f82b8..26a27abca 100644 --- a/server/tests/plugins/plugin-unloading.ts +++ b/server/tests/plugins/plugin-unloading.ts @@ -16,7 +16,7 @@ describe('Test plugins module unloading', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) }) it('Should return a numeric value', async function () { @@ -41,7 +41,7 @@ describe('Test plugins module unloading', function () { }) it('Should uninstall the plugin and free the route', async function () { - await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-unloading' }) + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-unloading' }) await makeGetRequest({ url: server.url, @@ -51,7 +51,7 @@ describe('Test plugins module unloading', function () { }) it('Should return a different numeric value', async function () { - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) const res = await makeGetRequest({ url: server.url, diff --git a/server/tests/plugins/translations.ts b/server/tests/plugins/translations.ts index 0e11a0b53..d8d878026 100644 --- a/server/tests/plugins/translations.ts +++ b/server/tests/plugins/translations.ts @@ -17,7 +17,7 @@ describe('Test plugin translations', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - command = server.pluginsCommand + command = server.plugins await command.install({ path: PluginsCommand.getPluginTestPath() }) await command.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index 641e37fbb..facc6bbc1 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -17,11 +17,11 @@ describe('Test plugin altering video constants', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) }) it('Should have updated languages', async function () { - const languages = await server.videosCommand.getLanguages() + const languages = await server.videos.getLanguages() expect(languages['en']).to.not.exist expect(languages['fr']).to.not.exist @@ -32,7 +32,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated categories', async function () { - const categories = await server.videosCommand.getCategories() + const categories = await server.videos.getCategories() expect(categories[1]).to.not.exist expect(categories[2]).to.not.exist @@ -42,7 +42,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated licences', async function () { - const licences = await server.videosCommand.getLicences() + const licences = await server.videos.getLicences() expect(licences[1]).to.not.exist expect(licences[7]).to.not.exist @@ -52,7 +52,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated video privacies', async function () { - const privacies = await server.videosCommand.getPrivacies() + const privacies = await server.videos.getPrivacies() expect(privacies[1]).to.exist expect(privacies[2]).to.not.exist @@ -61,7 +61,7 @@ describe('Test plugin altering video constants', function () { }) it('Should have updated playlist privacies', async function () { - const playlistPrivacies = await server.playlistsCommand.getPrivacies() + const playlistPrivacies = await server.playlists.getPrivacies() expect(playlistPrivacies[1]).to.exist expect(playlistPrivacies[2]).to.exist @@ -70,29 +70,29 @@ describe('Test plugin altering video constants', function () { it('Should not be able to create a video with this privacy', async function () { const attributes = { name: 'video', privacy: 2 } - await server.videosCommand.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not be able to create a video with this privacy', async function () { const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } - await server.playlistsCommand.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should be able to upload a video with these values', async function () { const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } - const { uuid } = await server.videosCommand.upload({ attributes }) + const { uuid } = await server.videos.upload({ attributes }) - const video = await server.videosCommand.get({ id: uuid }) + const video = await server.videos.get({ id: uuid }) expect(video.language.label).to.equal('Al Bhed 2') expect(video.licence.label).to.equal('Best licence') expect(video.category.label).to.equal('Best category') }) it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { - await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) + await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) { - const languages = await server.videosCommand.getLanguages() + const languages = await server.videos.getLanguages() expect(languages['en']).to.equal('English') expect(languages['fr']).to.equal('French') @@ -103,7 +103,7 @@ describe('Test plugin altering video constants', function () { } { - const categories = await server.videosCommand.getCategories() + const categories = await server.videos.getCategories() expect(categories[1]).to.equal('Music') expect(categories[2]).to.equal('Films') @@ -113,7 +113,7 @@ describe('Test plugin altering video constants', function () { } { - const licences = await server.videosCommand.getLicences() + const licences = await server.videos.getLicences() expect(licences[1]).to.equal('Attribution') expect(licences[7]).to.equal('Public Domain Dedication') @@ -123,7 +123,7 @@ describe('Test plugin altering video constants', function () { } { - const privacies = await server.videosCommand.getPrivacies() + const privacies = await server.videos.getPrivacies() expect(privacies[1]).to.exist expect(privacies[2]).to.exist @@ -132,7 +132,7 @@ describe('Test plugin altering video constants', function () { } { - const playlistPrivacies = await server.playlistsCommand.getPrivacies() + const playlistPrivacies = await server.playlists.getPrivacies() expect(playlistPrivacies[1]).to.exist expect(playlistPrivacies[2]).to.exist -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- server/tests/plugins/action-hooks.ts | 11 +++++------ server/tests/plugins/external-auth.ts | 10 +++++----- server/tests/plugins/filter-hooks.ts | 8 ++++---- server/tests/plugins/html-injection.ts | 8 ++++---- server/tests/plugins/id-and-pass-auth.ts | 6 +++--- server/tests/plugins/plugin-helpers.ts | 10 +++++----- server/tests/plugins/plugin-router.ts | 8 ++++---- server/tests/plugins/plugin-storage.ts | 13 ++++++++++--- server/tests/plugins/plugin-transcoding.ts | 12 ++++++------ server/tests/plugins/plugin-unloading.ts | 13 ++++++++++--- server/tests/plugins/translations.ts | 7 +++---- server/tests/plugins/video-constants.ts | 6 +++--- 12 files changed, 62 insertions(+), 50 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 12d5c23c5..b96de4e90 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -3,18 +3,17 @@ import 'mocha' import { cleanupTests, - flushAndRunMultipleServers, + createMultipleServers, killallServers, + PeerTubeServer, PluginsCommand, - reRunServer, - ServerInfo, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' describe('Test plugin action hooks', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoUUID: string let threadId: number @@ -25,7 +24,7 @@ describe('Test plugin action hooks', function () { before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) @@ -33,7 +32,7 @@ describe('Test plugin action hooks', function () { await killallServers([ servers[0] ]) - await reRunServer(servers[0], { + await servers[0].run({ live: { enabled: true } diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index 48f942f7f..c0834a14c 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -6,16 +6,16 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, decodeQueryString, - flushAndRunServer, + createSingleServer, PluginsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' import { UserRole } from '@shared/models' async function loginExternal (options: { - server: ServerInfo + server: PeerTubeServer npmName: string authName: string username: string @@ -46,7 +46,7 @@ async function loginExternal (options: { } describe('Test external auth plugins', function () { - let server: ServerInfo + let server: PeerTubeServer let cyanAccessToken: string let cyanRefreshToken: string @@ -59,7 +59,7 @@ describe('Test external auth plugins', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) for (const suffix of [ 'one', 'two', 'three' ]) { diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 18479dcf5..5d94303a9 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -6,11 +6,11 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, ImportsCommand, makeRawRequest, PluginsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs @@ -20,14 +20,14 @@ import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, Vi const expect = chai.expect describe('Test plugin filter hooks', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoUUID: string let threadId: number before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts index 0cb89f511..2902c39b7 100644 --- a/server/tests/plugins/html-injection.ts +++ b/server/tests/plugins/html-injection.ts @@ -4,23 +4,23 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunServer, + createSingleServer, makeHTMLRequest, PluginsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '../../../shared/extra-utils' const expect = chai.expect describe('Test plugins HTML injection', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let command: PluginsCommand before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) command = server.plugins diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 203996af8..981bcad91 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -3,11 +3,11 @@ import 'mocha' import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' import { UserRole } from '@shared/models' describe('Test id and pass auth plugins', function () { - let server: ServerInfo + let server: PeerTubeServer let crashAccessToken: string let crashRefreshToken: string @@ -18,7 +18,7 @@ describe('Test id and pass auth plugins', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) for (const suffix of [ 'one', 'two', 'three' ]) { diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index cf16aaa9d..1d87b84ae 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -7,16 +7,16 @@ import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeGetRequest, makePostBodyRequest, PluginsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' -function postCommand (server: ServerInfo, command: string, bodyArg?: object) { +function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) { const body = { command } if (bodyArg) Object.assign(body, bodyArg) @@ -29,12 +29,12 @@ function postCommand (server: ServerInfo, command: string, bodyArg?: object) { } describe('Test plugin helpers', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts index 1c53dd80c..dec8ca4bb 100644 --- a/server/tests/plugins/plugin-router.ts +++ b/server/tests/plugins/plugin-router.ts @@ -5,16 +5,16 @@ import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, makePostBodyRequest, PluginsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' describe('Test plugin helpers', function () { - let server: ServerInfo + let server: PeerTubeServer const basePaths = [ '/plugins/test-five/router/', '/plugins/test-five/0.0.1/router/' @@ -23,7 +23,7 @@ describe('Test plugin helpers', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') }) diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 30e231439..5745914a5 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts @@ -5,15 +5,22 @@ import { expect } from 'chai' import { pathExists, readdir, readFile } from 'fs-extra' import { join } from 'path' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { + cleanupTests, + createSingleServer, + makeGetRequest, + PeerTubeServer, + PluginsCommand, + setAccessTokensToServers +} from '@shared/extra-utils' describe('Test plugin storage', function () { - let server: ServerInfo + let server: PeerTubeServer before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index 3a03065b0..3c54d3796 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -6,9 +6,9 @@ import { join } from 'path' import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, PluginsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, testFfmpegStreamError, @@ -16,7 +16,7 @@ import { } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' -async function createLiveWrapper (server: ServerInfo) { +async function createLiveWrapper (server: PeerTubeServer) { const liveAttributes = { name: 'live video', channelId: server.store.channel.id, @@ -28,7 +28,7 @@ async function createLiveWrapper (server: ServerInfo) { return uuid } -function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { +function updateConf (server: PeerTubeServer, vodProfile: string, liveProfile: string) { return server.config.updateCustomSubConfig({ newConfig: { transcoding: { @@ -64,12 +64,12 @@ function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string } describe('Test transcoding plugins', function () { - let server: ServerInfo + let server: PeerTubeServer before(async function () { this.timeout(60000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts index 26a27abca..6c405b7f5 100644 --- a/server/tests/plugins/plugin-unloading.ts +++ b/server/tests/plugins/plugin-unloading.ts @@ -3,17 +3,24 @@ import 'mocha' import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { + cleanupTests, + createSingleServer, + makeGetRequest, + PeerTubeServer, + PluginsCommand, + setAccessTokensToServers +} from '@shared/extra-utils' describe('Test plugins module unloading', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null const requestPath = '/plugins/test-unloading/router/get' let value: string = null before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) diff --git a/server/tests/plugins/translations.ts b/server/tests/plugins/translations.ts index d8d878026..8b25c6b75 100644 --- a/server/tests/plugins/translations.ts +++ b/server/tests/plugins/translations.ts @@ -2,19 +2,18 @@ import 'mocha' import * as chai from 'chai' -import { PluginsCommand, setAccessTokensToServers } from '../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' +import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/extra-utils' const expect = chai.expect describe('Test plugin translations', function () { - let server: ServerInfo + let server: PeerTubeServer let command: PluginsCommand before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) command = server.plugins diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index facc6bbc1..953916e8e 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -3,18 +3,18 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test plugin altering video constants', function () { - let server: ServerInfo + let server: PeerTubeServer before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) -- cgit v1.2.3 From 59bbcced37005dd511daca9bd58ae2998cb931b1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:19:16 +0200 Subject: Centralize test URLs --- server/tests/plugins/filter-hooks.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 5d94303a9..df52bb3b5 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -5,12 +5,12 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - doubleFollow, createMultipleServers, - ImportsCommand, + doubleFollow, + FIXTURE_URLS, makeRawRequest, - PluginsCommand, PeerTubeServer, + PluginsCommand, setAccessTokensToServers, setDefaultVideoChannel, waitJobs @@ -136,7 +136,7 @@ describe('Test plugin filter hooks', function () { name: 'normal title', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].store.channel.id, - targetUrl: ImportsCommand.getGoodVideoUrl() + 'bad' + targetUrl: FIXTURE_URLS.goodVideo + 'bad' } await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -161,7 +161,7 @@ describe('Test plugin filter hooks', function () { name: 'title with bad word', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].store.channel.id, - targetUrl: ImportsCommand.getGoodVideoUrl() + targetUrl: FIXTURE_URLS.goodVideo } const body = await servers[0].imports.importVideo({ attributes }) videoImportId = body.id @@ -273,7 +273,7 @@ describe('Test plugin filter hooks', function () { const attributes = { name: 'video please blacklist me', - targetUrl: ImportsCommand.getGoodVideoUrl(), + targetUrl: FIXTURE_URLS.goodVideo, channelId: servers[0].store.channel.id } const body = await servers[0].imports.importVideo({ attributes }) -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- server/tests/plugins/external-auth.ts | 20 ++++++++++---------- server/tests/plugins/filter-hooks.ts | 10 +++++----- server/tests/plugins/id-and-pass-auth.ts | 2 +- server/tests/plugins/plugin-helpers.ts | 20 ++++++++++---------- server/tests/plugins/plugin-router.ts | 14 +++++++------- server/tests/plugins/plugin-storage.ts | 4 ++-- server/tests/plugins/plugin-unloading.ts | 10 +++++----- server/tests/plugins/video-constants.ts | 2 +- 8 files changed, 41 insertions(+), 41 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index c0834a14c..a2828603a 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, decodeQueryString, @@ -20,15 +20,15 @@ async function loginExternal (options: { authName: string username: string query?: any - statusCodeExpected?: HttpStatusCode - statusCodeExpectedStep2?: HttpStatusCode + expectedStatus?: HttpStatusCode + expectedStatusStep2?: HttpStatusCode }) { const res = await options.server.plugins.getExternalAuth({ npmName: options.npmName, npmVersion: '0.0.1', authName: options.authName, query: options.query, - expectedStatus: options.statusCodeExpected || HttpStatusCode.FOUND_302 + expectedStatus: options.expectedStatus || HttpStatusCode.FOUND_302 }) if (res.status !== HttpStatusCode.FOUND_302) return @@ -39,7 +39,7 @@ async function loginExternal (options: { const resLogin = await options.server.login.loginUsingExternalToken({ username: options.username, externalAuthToken: externalAuthToken as string, - expectedStatus: options.statusCodeExpectedStep2 + expectedStatus: options.expectedStatusStep2 }) return resLogin.body @@ -268,7 +268,7 @@ describe('Test external auth plugins', function () { username: 'kefka' }, username: 'kefka', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -293,7 +293,7 @@ describe('Test external auth plugins', function () { username: 'cyan' }, username: 'cyan', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await server.login.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) @@ -307,7 +307,7 @@ describe('Test external auth plugins', function () { npmName: 'test-external-auth-two', authName: 'external-auth-4', username: 'kefka2', - statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 + expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400 }) await loginExternal({ @@ -315,7 +315,7 @@ describe('Test external auth plugins', function () { npmName: 'test-external-auth-two', authName: 'external-auth-4', username: 'kefka', - statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 + expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -327,7 +327,7 @@ describe('Test external auth plugins', function () { npmName: 'test-external-auth-two', authName: 'external-auth-6', username: 'existing_user', - statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 + expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400 }) }) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index df52bb3b5..ba84dd27a 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createMultipleServers, @@ -71,28 +71,28 @@ describe('Test plugin filter hooks', function () { }) it('Should run filter:api.accounts.videos.list.params', async function () { - const { data } = await servers[0].videos.listByAccount({ accountName: 'root', start: 0, count: 2 }) + const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) // 1 plugin do +1 to the count parameter expect(data).to.have.lengthOf(3) }) it('Should run filter:api.accounts.videos.list.result', async function () { - const { total } = await servers[0].videos.listByAccount({ accountName: 'root', start: 0, count: 2 }) + const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) // Plugin do +2 to the total result expect(total).to.equal(12) }) it('Should run filter:api.video-channels.videos.list.params', async function () { - const { data } = await servers[0].videos.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) + const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 }) // 1 plugin do +3 to the count parameter expect(data).to.have.lengthOf(5) }) it('Should run filter:api.video-channels.videos.list.result', async function () { - const { total } = await servers[0].videos.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) + const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 }) // Plugin do +3 to the total result expect(total).to.equal(13) diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 981bcad91..a73d76caa 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' import { UserRole } from '@shared/models' diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 1d87b84ae..5cb664bda 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkVideoFilesWereRemoved, cleanupTests, @@ -24,7 +24,7 @@ function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) url: server.url, path: '/plugins/test-four/router/commander', fields: body, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) } @@ -67,7 +67,7 @@ describe('Test plugin helpers', function () { const res = await makeGetRequest({ url: servers[0].url, path: '/plugins/test-four/router/server-config', - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.serverConfig).to.exist @@ -88,7 +88,7 @@ describe('Test plugin helpers', function () { const res = await makeGetRequest({ url: servers[0].url, path: '/plugins/test-four/router/static-route', - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/') @@ -100,7 +100,7 @@ describe('Test plugin helpers', function () { const res = await makeGetRequest({ url: servers[0].url, path: baseRouter + 'router-route', - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.routerRoute).to.equal(baseRouter) @@ -113,7 +113,7 @@ describe('Test plugin helpers', function () { await makeGetRequest({ url: servers[0].url, path: '/plugins/test-four/router/user', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -122,7 +122,7 @@ describe('Test plugin helpers', function () { url: servers[0].url, token: servers[0].accessToken, path: '/plugins/test-four/router/user', - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.username).to.equal('root') @@ -140,12 +140,12 @@ describe('Test plugin helpers', function () { this.timeout(60000) { - const res = await await servers[0].videos.quickUpload({ name: 'video server 1' }) + const res = await servers[0].videos.quickUpload({ name: 'video server 1' }) videoUUIDServer1 = res.uuid } { - await await servers[1].videos.quickUpload({ name: 'video server 2' }) + await servers[1].videos.quickUpload({ name: 'video server 2' }) } await waitJobs(servers) @@ -224,7 +224,7 @@ describe('Test plugin helpers', function () { let videoUUID: string before(async () => { - const res = await await servers[0].videos.quickUpload({ name: 'video1' }) + const res = await servers[0].videos.quickUpload({ name: 'video1' }) videoUUID = res.uuid }) diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts index dec8ca4bb..becb7c47b 100644 --- a/server/tests/plugins/plugin-router.ts +++ b/server/tests/plugins/plugin-router.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -34,7 +34,7 @@ describe('Test plugin helpers', function () { const res = await makeGetRequest({ url: server.url, path: path + 'ping', - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.message).to.equal('pong') @@ -47,7 +47,7 @@ describe('Test plugin helpers', function () { url: server.url, path: path + 'is-authenticated', token: server.accessToken, - statusCodeExpected: 200 + expectedStatus: 200 }) expect(res.body.isAuthenticated).to.equal(true) @@ -55,7 +55,7 @@ describe('Test plugin helpers', function () { const secRes = await makeGetRequest({ url: server.url, path: path + 'is-authenticated', - statusCodeExpected: 200 + expectedStatus: 200 }) expect(secRes.body.isAuthenticated).to.equal(false) @@ -74,7 +74,7 @@ describe('Test plugin helpers', function () { url: server.url, path: path + 'form/post/mirror', fields: body, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body).to.deep.equal(body) @@ -88,14 +88,14 @@ describe('Test plugin helpers', function () { await makeGetRequest({ url: server.url, path: path + 'ping', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await makePostBodyRequest({ url: server.url, path: path + 'ping', fields: {}, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 5745914a5..90dafa3e1 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts @@ -4,7 +4,7 @@ import 'mocha' import { expect } from 'chai' import { pathExists, readdir, readFile } from 'fs-extra' import { join } from 'path' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -63,7 +63,7 @@ describe('Test plugin storage', function () { url: server.url, token: server.accessToken, path: '/plugins/test-six/router/create-file', - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) const content = await getFileContent() diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts index 6c405b7f5..faf9cc599 100644 --- a/server/tests/plugins/plugin-unloading.ts +++ b/server/tests/plugins/plugin-unloading.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -30,7 +30,7 @@ describe('Test plugins module unloading', function () { const res = await makeGetRequest({ url: server.url, path: requestPath, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.message).to.match(/^\d+$/) @@ -41,7 +41,7 @@ describe('Test plugins module unloading', function () { const res = await makeGetRequest({ url: server.url, path: requestPath, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.message).to.be.equal(value) @@ -53,7 +53,7 @@ describe('Test plugins module unloading', function () { await makeGetRequest({ url: server.url, path: requestPath, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -63,7 +63,7 @@ describe('Test plugins module unloading', function () { const res = await makeGetRequest({ url: server.url, path: requestPath, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.message).to.match(/^\d+$/) diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index 953916e8e..dd3b40225 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { VideoPlaylistPrivacy } from '@shared/models' -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/tests/plugins/action-hooks.ts | 2 +- server/tests/plugins/external-auth.ts | 7 +++---- server/tests/plugins/filter-hooks.ts | 3 +-- server/tests/plugins/html-injection.ts | 2 +- server/tests/plugins/id-and-pass-auth.ts | 5 ++--- server/tests/plugins/plugin-helpers.ts | 6 +++--- server/tests/plugins/plugin-router.ts | 4 ++-- server/tests/plugins/plugin-storage.ts | 2 +- server/tests/plugins/plugin-transcoding.ts | 2 +- server/tests/plugins/plugin-unloading.ts | 2 +- server/tests/plugins/video-constants.ts | 5 ++--- 11 files changed, 18 insertions(+), 22 deletions(-) (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index b96de4e90..4c1bc7d06 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -120,7 +120,7 @@ describe('Test plugin action hooks', function () { }) it('Should run action:api.user.oauth2-got-token', async function () { - await servers[0].login.getAccessToken('created_user', 'super_password') + await servers[0].login.login({ user: { username: 'created_user' } }) await checkHook('action:api.user.oauth2-got-token') }) diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index a2828603a..f3e018d43 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -2,17 +2,16 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, - decodeQueryString, createSingleServer, - PluginsCommand, + decodeQueryString, PeerTubeServer, + PluginsCommand, setAccessTokensToServers, wait } from '@shared/extra-utils' -import { UserRole } from '@shared/models' +import { HttpStatusCode, UserRole } from '@shared/models' async function loginExternal (options: { server: PeerTubeServer diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index ba84dd27a..c00ac8f91 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createMultipleServers, @@ -15,7 +14,7 @@ import { setDefaultVideoChannel, waitJobs } from '@shared/extra-utils' -import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts index 2902c39b7..95c0cd687 100644 --- a/server/tests/plugins/html-injection.ts +++ b/server/tests/plugins/html-injection.ts @@ -6,8 +6,8 @@ import { cleanupTests, createSingleServer, makeHTMLRequest, - PluginsCommand, PeerTubeServer, + PluginsCommand, setAccessTokensToServers } from '../../../shared/extra-utils' diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index a73d76caa..fde0166f9 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -2,9 +2,8 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' -import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' -import { UserRole } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers, wait } from '@shared/extra-utils' +import { HttpStatusCode, UserRole } from '@shared/models' describe('Test id and pass auth plugins', function () { let server: PeerTubeServer diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 5cb664bda..242994273 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -2,19 +2,19 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' import { checkVideoFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeGetRequest, makePostBodyRequest, - PluginsCommand, PeerTubeServer, + PluginsCommand, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) { const body = { command } diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts index becb7c47b..b1ac9e2fe 100644 --- a/server/tests/plugins/plugin-router.ts +++ b/server/tests/plugins/plugin-router.ts @@ -2,16 +2,16 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, makeGetRequest, makePostBodyRequest, - PluginsCommand, PeerTubeServer, + PluginsCommand, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test plugin helpers', function () { let server: PeerTubeServer diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 90dafa3e1..e20c36dba 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts @@ -4,7 +4,6 @@ import 'mocha' import { expect } from 'chai' import { pathExists, readdir, readFile } from 'fs-extra' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -13,6 +12,7 @@ import { PluginsCommand, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test plugin storage', function () { let server: PeerTubeServer diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index 3c54d3796..0bf1fab01 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -7,8 +7,8 @@ import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server import { cleanupTests, createSingleServer, - PluginsCommand, PeerTubeServer, + PluginsCommand, setAccessTokensToServers, setDefaultVideoChannel, testFfmpegStreamError, diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts index faf9cc599..6bf2fda9b 100644 --- a/server/tests/plugins/plugin-unloading.ts +++ b/server/tests/plugins/plugin-unloading.ts @@ -2,7 +2,6 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -11,6 +10,7 @@ import { PluginsCommand, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test plugins module unloading', function () { let server: PeerTubeServer = null diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index dd3b40225..f527a2b30 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -2,9 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' -import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { VideoPlaylistPrivacy } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect -- cgit v1.2.3