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