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