1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
10 setAccessTokensToServers,
13 setDefaultVideoChannel
14 } from '../../../../shared/extra-utils'
15 import { VideoPlaylistPrivacy } from '@shared/models'
17 describe('Test services API validators', function () {
18 let server: ServerInfo
19 let playlistUUID: string
21 // ---------------------------------------------------------------
23 before(async function () {
26 server = await flushAndRunServer(1)
27 await setAccessTokensToServers([ server ])
28 await setDefaultVideoChannel([ server ])
31 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
32 server.video = res.body.video
36 const res = await createVideoPlaylist({
38 token: server.accessToken,
40 displayName: 'super playlist',
41 privacy: VideoPlaylistPrivacy.PUBLIC,
42 videoChannelId: server.videoChannel.id
46 playlistUUID = res.body.videoPlaylist.uuid
50 describe('Test oEmbed API validators', function () {
52 it('Should fail with an invalid url', async function () {
53 const embedUrl = 'hello.com'
54 await checkParamEmbed(server, embedUrl)
57 it('Should fail with an invalid host', async function () {
58 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
59 await checkParamEmbed(server, embedUrl)
62 it('Should fail with an invalid element id', async function () {
63 const embedUrl = `http://localhost:${server.port}/videos/watch/blabla`
64 await checkParamEmbed(server, embedUrl)
67 it('Should fail with an unknown element', async function () {
68 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
69 await checkParamEmbed(server, embedUrl, 404)
72 it('Should fail with an invalid path', async function () {
73 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}`
75 await checkParamEmbed(server, embedUrl)
78 it('Should fail with an invalid max height', async function () {
79 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
81 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' })
84 it('Should fail with an invalid max width', async function () {
85 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
87 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' })
90 it('Should fail with an invalid format', async function () {
91 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
93 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' })
96 it('Should fail with a non supported format', async function () {
97 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
99 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' })
102 it('Should succeed with the correct params with a video', async function () {
103 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
110 await checkParamEmbed(server, embedUrl, 200, query)
113 it('Should succeed with the correct params with a playlist', async function () {
114 const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}`
121 await checkParamEmbed(server, embedUrl, 200, query)
125 after(async function () {
126 await cleanupTests([ server ])
130 function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) {
131 const path = '/services/oembed'
133 return makeGetRequest({
136 query: Object.assign(query, { url: embedUrl }),