1
0
Fork 0
peertube/server/tests/plugins/plugin-router.ts

107 lines
2.6 KiB
TypeScript
Raw Normal View History

/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
2021-07-07 04:33:49 -04:00
import { expect } from 'chai'
import {
2021-07-07 04:33:49 -04:00
cleanupTests,
2021-07-16 03:47:51 -04:00
createSingleServer,
makeGetRequest,
makePostBodyRequest,
2021-07-16 03:47:51 -04:00
PeerTubeServer,
2021-07-16 08:27:30 -04:00
PluginsCommand,
2021-07-07 04:33:49 -04:00
setAccessTokensToServers
} from '@shared/extra-utils'
2021-07-16 08:27:30 -04:00
import { HttpStatusCode } from '@shared/models'
describe('Test plugin helpers', function () {
2021-07-16 03:47:51 -04:00
let server: PeerTubeServer
const basePaths = [
'/plugins/test-five/router/',
'/plugins/test-five/0.0.1/router/'
]
before(async function () {
this.timeout(30000)
2021-07-16 03:47:51 -04:00
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
2021-07-16 03:04:35 -04:00
await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') })
})
it('Should answer "pong"', async function () {
for (const path of basePaths) {
const res = await makeGetRequest({
url: server.url,
path: path + 'ping',
2021-07-16 04:42:24 -04:00
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,
2021-07-16 04:42:24 -04:00
expectedStatus: 200
})
expect(res.body.isAuthenticated).to.equal(true)
const secRes = await makeGetRequest({
url: server.url,
path: path + 'is-authenticated',
2021-07-16 04:42:24 -04:00
expectedStatus: 200
})
expect(secRes.body.isAuthenticated).to.equal(false)
}
})
it('Should mirror post body', async function () {
const body = {
hello: 'world',
riri: 'fifi',
loulou: 'picsou'
}
for (const path of basePaths) {
const res = await makePostBodyRequest({
url: server.url,
path: path + 'form/post/mirror',
fields: body,
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.OK_200
})
expect(res.body).to.deep.equal(body)
}
})
it('Should remove the plugin and remove the routes', async function () {
2021-07-16 03:04:35 -04:00
await server.plugins.uninstall({ npmName: 'peertube-plugin-test-five' })
for (const path of basePaths) {
await makeGetRequest({
url: server.url,
path: path + 'ping',
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.NOT_FOUND_404
})
await makePostBodyRequest({
url: server.url,
path: path + 'ping',
fields: {},
2021-07-16 04:42:24 -04:00
expectedStatus: HttpStatusCode.NOT_FOUND_404
})
}
})
after(async function () {
await cleanupTests([ server ])
})
})