1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { VideoPlaylistPrivacy } from '@shared/models'
5 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
14 } from '../../../../shared/extra-utils'
16 describe('Test services API validators', function () {
17 let server: ServerInfo
18 let playlistUUID: string
20 // ---------------------------------------------------------------
22 before(async function () {
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
27 await setDefaultVideoChannel([ server ])
30 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
31 server.video = res.body.video
35 const created = await server.playlistsCommand.create({
37 displayName: 'super playlist',
38 privacy: VideoPlaylistPrivacy.PUBLIC,
39 videoChannelId: server.videoChannel.id
43 playlistUUID = created.uuid
47 describe('Test oEmbed API validators', function () {
49 it('Should fail with an invalid url', async function () {
50 const embedUrl = 'hello.com'
51 await checkParamEmbed(server, embedUrl)
54 it('Should fail with an invalid host', async function () {
55 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
56 await checkParamEmbed(server, embedUrl)
59 it('Should fail with an invalid element id', async function () {
60 const embedUrl = `http://localhost:${server.port}/videos/watch/blabla`
61 await checkParamEmbed(server, embedUrl)
64 it('Should fail with an unknown element', async function () {
65 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
66 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404)
69 it('Should fail with an invalid path', async function () {
70 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}`
72 await checkParamEmbed(server, embedUrl)
75 it('Should fail with an invalid max height', async function () {
76 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
78 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
81 it('Should fail with an invalid max width', async function () {
82 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
84 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
87 it('Should fail with an invalid format', async function () {
88 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
90 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
93 it('Should fail with a non supported format', async function () {
94 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
96 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
99 it('Should succeed with the correct params with a video', async function () {
100 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
107 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
110 it('Should succeed with the correct params with a playlist', async function () {
111 const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}`
118 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
122 after(async function () {
123 await cleanupTests([ server ])
127 function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) {
128 const path = '/services/oembed'
130 return makeGetRequest({
133 query: Object.assign(query, { url: embedUrl }),