]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/services.ts
Cleanup tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / services.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4
5 import {
6 flushTests,
7 killallServers,
8 makeGetRequest,
9 flushAndRunServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo
13 } from '../../../../shared/extra-utils'
14
15 describe('Test services API validators', function () {
16 let server: ServerInfo
17
18 // ---------------------------------------------------------------
19
20 before(async function () {
21 this.timeout(60000)
22
23 server = await flushAndRunServer(1)
24 await setAccessTokensToServers([ server ])
25
26 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
27 server.video = res.body.video
28 })
29
30 describe('Test oEmbed API validators', function () {
31
32 it('Should fail with an invalid url', async function () {
33 const embedUrl = 'hello.com'
34 await checkParamEmbed(server, embedUrl)
35 })
36
37 it('Should fail with an invalid host', async function () {
38 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
39 await checkParamEmbed(server, embedUrl)
40 })
41
42 it('Should fail with an invalid video id', async function () {
43 const embedUrl = 'http://localhost:9001/videos/watch/blabla'
44 await checkParamEmbed(server, embedUrl)
45 })
46
47 it('Should fail with an unknown video', async function () {
48 const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c'
49 await checkParamEmbed(server, embedUrl, 404)
50 })
51
52 it('Should fail with an invalid path', async function () {
53 const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid
54
55 await checkParamEmbed(server, embedUrl)
56 })
57
58 it('Should fail with an invalid max height', async function () {
59 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
60
61 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' })
62 })
63
64 it('Should fail with an invalid max width', async function () {
65 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
66
67 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' })
68 })
69
70 it('Should fail with an invalid format', async function () {
71 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
72
73 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' })
74 })
75
76 it('Should fail with a non supported format', async function () {
77 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
78
79 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' })
80 })
81
82 it('Should succeed with the correct params', async function () {
83 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
84 const query = {
85 format: 'json',
86 maxheight: 400,
87 maxwidth: 400
88 }
89
90 await checkParamEmbed(server, embedUrl, 200, query)
91 })
92 })
93
94 after(function () {
95 killallServers([ server ])
96 })
97 })
98
99 function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) {
100 const path = '/services/oembed'
101
102 return makeGetRequest({
103 url: server.url,
104 path,
105 query: Object.assign(query, { url: embedUrl }),
106 statusCodeExpected
107 })
108 }