1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
9 setAccessTokensToServers,
10 setDefaultVideoChannel
11 } from '@shared/extra-utils'
12 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
14 describe('Test services API validators', function () {
15 let server: PeerTubeServer
16 let playlistUUID: string
18 // ---------------------------------------------------------------
20 before(async function () {
23 server = await createSingleServer(1)
24 await setAccessTokensToServers([ server ])
25 await setDefaultVideoChannel([ server ])
27 server.store.videoCreated = await server.videos.upload({ attributes: { name: 'my super name' } })
30 const created = await server.playlists.create({
32 displayName: 'super playlist',
33 privacy: VideoPlaylistPrivacy.PUBLIC,
34 videoChannelId: server.store.channel.id
38 playlistUUID = created.uuid
42 describe('Test oEmbed API validators', function () {
44 it('Should fail with an invalid url', async function () {
45 const embedUrl = 'hello.com'
46 await checkParamEmbed(server, embedUrl)
49 it('Should fail with an invalid host', async function () {
50 const embedUrl = 'http://hello.com/videos/watch/' + server.store.videoCreated.uuid
51 await checkParamEmbed(server, embedUrl)
54 it('Should fail with an invalid element id', async function () {
55 const embedUrl = `http://localhost:${server.port}/videos/watch/blabla`
56 await checkParamEmbed(server, embedUrl)
59 it('Should fail with an unknown element', async function () {
60 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
61 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404)
64 it('Should fail with an invalid path', async function () {
65 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.videoCreated.uuid}`
67 await checkParamEmbed(server, embedUrl)
70 it('Should fail with an invalid max height', async function () {
71 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
73 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
76 it('Should fail with an invalid max width', async function () {
77 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
79 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
82 it('Should fail with an invalid format', async function () {
83 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
85 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
88 it('Should fail with a non supported format', async function () {
89 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
91 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
94 it('Should succeed with the correct params with a video', async function () {
95 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
102 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
105 it('Should succeed with the correct params with a playlist', async function () {
106 const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}`
113 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
117 after(async function () {
118 await cleanupTests([ server ])
122 function checkParamEmbed (server: PeerTubeServer, embedUrl: string, expectedStatus = HttpStatusCode.BAD_REQUEST_400, query = {}) {
123 const path = '/services/oembed'
125 return makeGetRequest({
128 query: Object.assign(query, { url: embedUrl }),