X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fplugins%2Ffilter-hooks.ts;h=4d354b68e64be5deb8155a865916985866e51f2c;hb=b488ba1e26b803ac6c637e8b11bdd444ca4c803f;hp=6c1fd40ba7d160afe74120dbc4c6970e98fd735a;hpb=2ad9dcda240ee843c5e4a5b98cc94f7b2aab2c89;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 6c1fd40ba..4d354b68e 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' +import * as chai from 'chai' +import { ServerConfig } from '@shared/models' import { addVideoCommentReply, addVideoCommentThread, @@ -23,10 +23,10 @@ import { uploadVideo, waitJobs } from '../../../shared/extra-utils' +import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' +import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' +import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos' import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' -import { VideoDetails } from '../../../shared/models/videos' -import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports' -import { ServerConfig } from '@shared/models' const expect = chai.expect @@ -87,6 +87,84 @@ describe('Test plugin filter hooks', function () { await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403) }) + it('Should run filter:api.video.pre-import-url.accept.result', async function () { + const baseAttributes = { + name: 'normal title', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].videoChannel.id, + targetUrl: getGoodVideoUrl() + 'bad' + } + await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403) + }) + + it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { + const baseAttributes = { + 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, 403) + }) + + it('Should run filter:api.video.post-import-url.accept.result', async function () { + this.timeout(60000) + + let videoImportId: number + + { + const baseAttributes = { + name: 'title with bad word', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].videoChannel.id, + targetUrl: getGoodVideoUrl() + } + const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) + videoImportId = res.body.id + } + + await waitJobs(servers) + + { + const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) + const videoImports = res.body.data as VideoImport[] + + const videoImport = videoImports.find(i => i.id === videoImportId) + + expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) + expect(videoImport.state.label).to.equal('Rejected') + } + }) + + it('Should run filter:api.video.post-import-torrent.accept.result', async function () { + this.timeout(60000) + + let videoImportId: number + + { + const baseAttributes = { + 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 + } + + await waitJobs(servers) + + { + const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) + const videoImports = res.body.data as VideoImport[] + + const videoImport = videoImports.find(i => i.id === videoImportId) + + expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) + expect(videoImport.state.label).to.equal('Rejected') + } + }) + 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', 403) }) @@ -142,7 +220,7 @@ describe('Test plugin filter hooks', function () { const attributes = { name: 'video please blacklist me', - targetUrl: getYoutubeVideoUrl(), + targetUrl: getGoodVideoUrl(), channelId: servers[0].videoChannel.id } const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)