1 /* tslint:disable:no-unused-expression */
10 setAccessTokensToServers,
12 } from '../../../../shared/extra-utils'
14 describe('Test services API validators', function () {
15 let server: ServerInfo
17 // ---------------------------------------------------------------
19 before(async function () {
22 server = await flushAndRunServer(1)
23 await setAccessTokensToServers([ server ])
25 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
26 server.video = res.body.video
29 describe('Test oEmbed API validators', function () {
31 it('Should fail with an invalid url', async function () {
32 const embedUrl = 'hello.com'
33 await checkParamEmbed(server, embedUrl)
36 it('Should fail with an invalid host', async function () {
37 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
38 await checkParamEmbed(server, embedUrl)
41 it('Should fail with an invalid video id', async function () {
42 const embedUrl = `http://localhost:${server.port}/videos/watch/blabla`
43 await checkParamEmbed(server, embedUrl)
46 it('Should fail with an unknown video', async function () {
47 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
48 await checkParamEmbed(server, embedUrl, 404)
51 it('Should fail with an invalid path', async function () {
52 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}`
54 await checkParamEmbed(server, embedUrl)
57 it('Should fail with an invalid max height', async function () {
58 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
60 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' })
63 it('Should fail with an invalid max width', async function () {
64 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
66 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' })
69 it('Should fail with an invalid format', async function () {
70 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
72 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' })
75 it('Should fail with a non supported format', async function () {
76 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
78 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' })
81 it('Should succeed with the correct params', async function () {
82 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
89 await checkParamEmbed(server, embedUrl, 200, query)
93 after(async function () {
94 await cleanupTests([ server ])
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 }),