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