1 /* tslint:disable:no-unused-expression */
11 setAccessTokensToServers,
13 } from '../../../../shared/utils'
15 describe('Test services API validators', function () {
16 let server: ServerInfo
18 // ---------------------------------------------------------------
20 before(async function () {
25 server = await runServer(1)
26 await setAccessTokensToServers([ server ])
28 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
29 server.video = res.body.video
32 describe('Test oEmbed API validators', function () {
34 it('Should fail with an invalid url', async function () {
35 const embedUrl = 'hello.com'
36 await checkParamEmbed(server, embedUrl)
39 it('Should fail with an invalid host', async function () {
40 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
41 await checkParamEmbed(server, embedUrl)
44 it('Should fail with an invalid video id', async function () {
45 const embedUrl = 'http://localhost:9001/videos/watch/blabla'
46 await checkParamEmbed(server, embedUrl)
49 it('Should fail with an unknown video', async function () {
50 const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c'
51 await checkParamEmbed(server, embedUrl, 404)
54 it('Should fail with an invalid path', async function () {
55 const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid
57 await checkParamEmbed(server, embedUrl)
60 it('Should fail with an invalid max height', async function () {
61 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
63 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' })
66 it('Should fail with an invalid max width', async function () {
67 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
69 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' })
72 it('Should fail with an invalid format', async function () {
73 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
75 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' })
78 it('Should fail with a non supported format', async function () {
79 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
81 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' })
84 it('Should succeed with the correct params', async function () {
85 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
92 await checkParamEmbed(server, embedUrl, 200, query)
96 after(async function () {
97 killallServers([ server ])
99 // Keep the logs if the test failed
106 function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) {
107 const path = '/services/oembed'
109 return makeGetRequest({
112 query: Object.assign(query, { url: embedUrl }),