1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode } from '@shared/core-utils'
10 setAccessTokensToServers,
11 setDefaultVideoChannel
12 } from '@shared/extra-utils'
13 import { VideoPlaylistPrivacy } from '@shared/models'
15 describe('Test services API validators', function () {
16 let server: PeerTubeServer
17 let playlistUUID: string
19 // ---------------------------------------------------------------
21 before(async function () {
24 server = await createSingleServer(1)
25 await setAccessTokensToServers([ server ])
26 await setDefaultVideoChannel([ server ])
28 server.store.video = await server.videos.upload({ attributes: { name: 'my super name' } })
31 const created = await server.playlists.create({
33 displayName: 'super playlist',
34 privacy: VideoPlaylistPrivacy.PUBLIC,
35 videoChannelId: server.store.channel.id
39 playlistUUID = created.uuid
43 describe('Test oEmbed API validators', function () {
45 it('Should fail with an invalid url', async function () {
46 const embedUrl = 'hello.com'
47 await checkParamEmbed(server, embedUrl)
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)
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)
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)
65 it('Should fail with an invalid path', async function () {
66 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.video.uuid}`
68 await checkParamEmbed(server, embedUrl)
71 it('Should fail with an invalid max height', async function () {
72 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
74 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
77 it('Should fail with an invalid max width', async function () {
78 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
80 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
83 it('Should fail with an invalid format', async function () {
84 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
86 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
89 it('Should fail with a non supported format', async function () {
90 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
92 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
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}`
103 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
106 it('Should succeed with the correct params with a playlist', async function () {
107 const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}`
114 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
118 after(async function () {
119 await cleanupTests([ server ])
123 function checkParamEmbed (server: PeerTubeServer, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) {
124 const path = '/services/oembed'
126 return makeGetRequest({
129 query: Object.assign(query, { url: embedUrl }),