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'
16 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 describe('Test services API validators', function () {
19 let server: ServerInfo
20 let playlistUUID: string
22 // ---------------------------------------------------------------
24 before(async function () {
27 server = await flushAndRunServer(1)
28 await setAccessTokensToServers([ server ])
29 await setDefaultVideoChannel([ server ])
32 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
33 server.video = res.body.video
37 const res = await createVideoPlaylist({
39 token: server.accessToken,
41 displayName: 'super playlist',
42 privacy: VideoPlaylistPrivacy.PUBLIC,
43 videoChannelId: server.videoChannel.id
47 playlistUUID = res.body.videoPlaylist.uuid
51 describe('Test oEmbed API validators', function () {
53 it('Should fail with an invalid url', async function () {
54 const embedUrl = 'hello.com'
55 await checkParamEmbed(server, embedUrl)
58 it('Should fail with an invalid host', async function () {
59 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
60 await checkParamEmbed(server, embedUrl)
63 it('Should fail with an invalid element id', async function () {
64 const embedUrl = `http://localhost:${server.port}/videos/watch/blabla`
65 await checkParamEmbed(server, embedUrl)
68 it('Should fail with an unknown element', async function () {
69 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
70 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404)
73 it('Should fail with an invalid path', async function () {
74 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}`
76 await checkParamEmbed(server, embedUrl)
79 it('Should fail with an invalid max height', async function () {
80 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
82 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
85 it('Should fail with an invalid max width', async function () {
86 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
88 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
91 it('Should fail with an invalid format', async function () {
92 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
94 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
97 it('Should fail with a non supported format', async function () {
98 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
100 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
103 it('Should succeed with the correct params with a video', async function () {
104 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
111 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
114 it('Should succeed with the correct params with a playlist', async function () {
115 const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}`
122 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
126 after(async function () {
127 await cleanupTests([ server ])
131 function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) {
132 const path = '/services/oembed'
134 return makeGetRequest({
137 query: Object.assign(query, { url: embedUrl }),