2020-04-10 09:07:54 -04:00
|
|
|
/* 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 { HttpStatusCode } from '@shared/core-utils'
|
2020-04-10 09:07:54 -04:00
|
|
|
import {
|
2021-07-07 04:33:49 -04:00
|
|
|
cleanupTests,
|
2021-07-16 03:47:51 -04:00
|
|
|
createSingleServer,
|
2020-04-10 09:07:54 -04:00
|
|
|
makeGetRequest,
|
|
|
|
makePostBodyRequest,
|
2021-07-07 04:33:49 -04:00
|
|
|
PluginsCommand,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2021-07-07 04:33:49 -04:00
|
|
|
setAccessTokensToServers
|
|
|
|
} from '@shared/extra-utils'
|
2020-04-10 09:07:54 -04:00
|
|
|
|
|
|
|
describe('Test plugin helpers', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let server: PeerTubeServer
|
2020-04-10 09:07:54 -04:00
|
|
|
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)
|
2020-04-10 09:07:54 -04:00
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') })
|
2020-04-10 09:07:54 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should answer "pong"', async function () {
|
|
|
|
for (const path of basePaths) {
|
|
|
|
const res = await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + 'ping',
|
2020-12-07 08:32:36 -05:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2020-04-10 09:07:54 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(res.body.message).to.equal('pong')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-12-04 14:56:48 -05:00
|
|
|
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,
|
|
|
|
statusCodeExpected: 200
|
|
|
|
})
|
|
|
|
|
2020-12-04 16:13:11 -05:00
|
|
|
expect(res.body.isAuthenticated).to.equal(true)
|
2020-12-04 14:56:48 -05:00
|
|
|
|
|
|
|
const secRes = await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + 'is-authenticated',
|
|
|
|
statusCodeExpected: 200
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(secRes.body.isAuthenticated).to.equal(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-10 09:07:54 -04:00
|
|
|
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,
|
2020-12-07 08:32:36 -05:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2020-04-10 09:07:54 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
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' })
|
2020-04-10 09:07:54 -04:00
|
|
|
|
|
|
|
for (const path of basePaths) {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + 'ping',
|
2020-12-07 08:32:36 -05:00
|
|
|
statusCodeExpected: HttpStatusCode.NOT_FOUND_404
|
2020-04-10 09:07:54 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + 'ping',
|
|
|
|
fields: {},
|
2020-12-07 08:32:36 -05:00
|
|
|
statusCodeExpected: HttpStatusCode.NOT_FOUND_404
|
2020-04-10 09:07:54 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|