]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/services.ts
Fix audio encoding params
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / services.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4
5 import {
6 cleanupTests,
7 flushAndRunServer,
8 makeGetRequest,
9 ServerInfo,
10 setAccessTokensToServers,
11 uploadVideo,
12 createVideoPlaylist,
13 setDefaultVideoChannel
14 } from '../../../../shared/extra-utils'
15 import { VideoPlaylistPrivacy } from '@shared/models'
16
17 describe('Test services API validators', function () {
18 let server: ServerInfo
19 let playlistUUID: string
20
21 // ---------------------------------------------------------------
22
23 before(async function () {
24 this.timeout(60000)
25
26 server = await flushAndRunServer(1)
27 await setAccessTokensToServers([ server ])
28 await setDefaultVideoChannel([ server ])
29
30 {
31 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
32 server.video = res.body.video
33 }
34
35 {
36 const res = await createVideoPlaylist({
37 url: server.url,
38 token: server.accessToken,
39 playlistAttrs: {
40 displayName: 'super playlist',
41 privacy: VideoPlaylistPrivacy.PUBLIC,
42 videoChannelId: server.videoChannel.id
43 }
44 })
45
46 playlistUUID = res.body.videoPlaylist.uuid
47 }
48 })
49
50 describe('Test oEmbed API validators', function () {
51
52 it('Should fail with an invalid url', async function () {
53 const embedUrl = 'hello.com'
54 await checkParamEmbed(server, embedUrl)
55 })
56
57 it('Should fail with an invalid host', async function () {
58 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
59 await checkParamEmbed(server, embedUrl)
60 })
61
62 it('Should fail with an invalid element id', async function () {
63 const embedUrl = `http://localhost:${server.port}/videos/watch/blabla`
64 await checkParamEmbed(server, embedUrl)
65 })
66
67 it('Should fail with an unknown element', async function () {
68 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
69 await checkParamEmbed(server, embedUrl, 404)
70 })
71
72 it('Should fail with an invalid path', async function () {
73 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}`
74
75 await checkParamEmbed(server, embedUrl)
76 })
77
78 it('Should fail with an invalid max height', async function () {
79 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
80
81 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' })
82 })
83
84 it('Should fail with an invalid max width', async function () {
85 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
86
87 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' })
88 })
89
90 it('Should fail with an invalid format', async function () {
91 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
92
93 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' })
94 })
95
96 it('Should fail with a non supported format', async function () {
97 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
98
99 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' })
100 })
101
102 it('Should succeed with the correct params with a video', async function () {
103 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
104 const query = {
105 format: 'json',
106 maxheight: 400,
107 maxwidth: 400
108 }
109
110 await checkParamEmbed(server, embedUrl, 200, query)
111 })
112
113 it('Should succeed with the correct params with a playlist', async function () {
114 const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}`
115 const query = {
116 format: 'json',
117 maxheight: 400,
118 maxwidth: 400
119 }
120
121 await checkParamEmbed(server, embedUrl, 200, query)
122 })
123 })
124
125 after(async function () {
126 await cleanupTests([ server ])
127 })
128 })
129
130 function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) {
131 const path = '/services/oembed'
132
133 return makeGetRequest({
134 url: server.url,
135 path,
136 query: Object.assign(query, { url: embedUrl }),
137 statusCodeExpected
138 })
139 }