PeerTube/server/tests/plugins/filter-hooks.ts

81 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-07-19 10:37:35 +02:00
/* tslint:disable:no-unused-expression */
import * as chai from 'chai'
import 'mocha'
2019-07-19 17:30:41 +02:00
import {
cleanupTests,
flushAndRunMultipleServers,
flushAndRunServer, killallServers, reRunServer,
ServerInfo,
waitUntilLog
} from '../../../shared/extra-utils/server/servers'
import {
addVideoCommentReply,
addVideoCommentThread, deleteVideoComment,
getPluginTestPath, getVideosList,
installPlugin, removeVideo,
setAccessTokensToServers,
updateVideo,
uploadVideo,
viewVideo,
getVideosListPagination, getVideo
} from '../../../shared/extra-utils'
2019-07-19 10:37:35 +02:00
const expect = chai.expect
describe('Test plugin filter hooks', function () {
2019-07-19 17:30:41 +02:00
let servers: ServerInfo[]
let videoUUID: string
let threadId: number
2019-07-19 10:37:35 +02:00
before(async function () {
this.timeout(30000)
2019-07-19 17:30:41 +02:00
servers = await flushAndRunMultipleServers(2)
await setAccessTokensToServers(servers)
await installPlugin({
url: servers[0].url,
accessToken: servers[0].accessToken,
path: getPluginTestPath()
})
await installPlugin({
url: servers[0].url,
accessToken: servers[0].accessToken,
path: getPluginTestPath('-two')
})
for (let i = 0; i < 10; i++) {
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i })
}
const res = await getVideosList(servers[0].url)
videoUUID = res.body.data[0].uuid
2019-07-19 10:37:35 +02:00
})
2019-07-19 17:30:41 +02:00
it('Should run filter:api.videos.list.params hook', async function () {
const res = await getVideosListPagination(servers[0].url, 0, 2)
// 2 plugins do +1 to the count parameter
expect(res.body.data).to.have.lengthOf(4)
})
it('Should run filter:api.videos.list.result', async function () {
const res = await getVideosListPagination(servers[0].url, 0, 0)
// Plugin do +1 to the total result
expect(res.body.total).to.equal(11)
})
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')
2019-07-19 10:37:35 +02:00
})
after(async function () {
2019-07-19 17:30:41 +02:00
await cleanupTests(servers)
2019-07-19 10:37:35 +02:00
})
})