X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fplugins%2Fplugin-router.ts;h=40b15eb79c3ca3d9419dcc9a266ad864d9321a45;hb=2dd4c93c1b1ec0edee3e76626281b318b15a6a87;hp=cf4130f4b1af5aeb73fd916e96926f16425ba3c2;hpb=5e2b2e2775421cd98286d6e2f75cf38aae7a212c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts index cf4130f4b..40b15eb79 100644 --- a/server/tests/plugins/plugin-router.ts +++ b/server/tests/plugins/plugin-router.ts @@ -1,18 +1,19 @@ /* 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 { - getPluginTestPath, - installPlugin, + cleanupTests, + createSingleServer, makeGetRequest, makePostBodyRequest, - setAccessTokensToServers, uninstallPlugin -} from '../../../shared/extra-utils' -import { expect } from 'chai' + PeerTubeServer, + PluginsCommand, + setAccessTokensToServers +} from '@shared/server-commands' +import { HttpStatusCode } from '@shared/models' describe('Test plugin helpers', function () { - let server: ServerInfo + let server: PeerTubeServer const basePaths = [ '/plugins/test-five/router/', '/plugins/test-five/0.0.1/router/' @@ -21,14 +22,10 @@ describe('Test plugin helpers', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-five') - }) + await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') }) }) it('Should answer "pong"', async function () { @@ -36,13 +33,34 @@ describe('Test plugin helpers', function () { const res = await makeGetRequest({ url: server.url, path: path + 'ping', - statusCodeExpected: 200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.message).to.equal('pong') } }) + it('Should check if authenticated', async function () { + for (const path of basePaths) { + const res = await makeGetRequest({ + url: server.url, + path: path + 'is-authenticated', + token: server.accessToken, + expectedStatus: 200 + }) + + expect(res.body.isAuthenticated).to.equal(true) + + const secRes = await makeGetRequest({ + url: server.url, + path: path + 'is-authenticated', + expectedStatus: 200 + }) + + expect(secRes.body.isAuthenticated).to.equal(false) + } + }) + it('Should mirror post body', async function () { const body = { hello: 'world', @@ -55,7 +73,7 @@ describe('Test plugin helpers', function () { url: server.url, path: path + 'form/post/mirror', fields: body, - statusCodeExpected: 200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body).to.deep.equal(body) @@ -63,24 +81,20 @@ 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.plugins.uninstall({ npmName: 'peertube-plugin-test-five' }) for (const path of basePaths) { await makeGetRequest({ url: server.url, path: path + 'ping', - statusCodeExpected: 404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await makePostBodyRequest({ url: server.url, path: path + 'ping', fields: {}, - statusCodeExpected: 404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } })