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