1 /* tslint:disable:no-unused-expression */
5 import { flushTests, killallServers, makeGetRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils'
7 describe('Test services API validators', function () {
10 // ---------------------------------------------------------------
12 before(async function () {
17 server = await runServer(1)
18 await setAccessTokensToServers([ server ])
20 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
21 server.video = res.body.video
24 describe('Test oEmbed API validators', function () {
26 it('Should fail with an invalid url', async function () {
27 const embedUrl = 'hello.com'
28 await checkParamEmbed(server, embedUrl)
31 it('Should fail with an invalid host', async function () {
32 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
33 await checkParamEmbed(server, embedUrl)
36 it('Should fail with an invalid video id', async function () {
37 const embedUrl = 'http://localhost:9001/videos/watch/blabla'
38 await checkParamEmbed(server, embedUrl)
41 it('Should fail with an unknown video', async function () {
42 const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c'
43 await checkParamEmbed(server, embedUrl, 404)
46 it('Should fail with an invalid path', async function () {
47 const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid
49 await checkParamEmbed(server, embedUrl)
52 it('Should fail with an invalid max height', async function () {
53 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
55 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' })
58 it('Should fail with an invalid max width', async function () {
59 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
61 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' })
64 it('Should fail with an invalid format', async function () {
65 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
67 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' })
70 it('Should fail with a non supported format', async function () {
71 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
73 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' })
76 it('Should succeed with the correct params', async function () {
77 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
84 await checkParamEmbed(server, embedUrl, 200, query)
88 after(async function () {
89 killallServers([ server ])
91 // Keep the logs if the test failed
98 function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) {
99 const path = '/services/oembed'
101 return makeGetRequest({
104 query: Object.assign(query, { url: embedUrl }),