aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/services.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/services.ts')
-rw-r--r--server/tests/api/check-params/services.ts49
1 files changed, 20 insertions, 29 deletions
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
index 514e3da70..4c4a5cade 100644
--- a/server/tests/api/check-params/services.ts
+++ b/server/tests/api/check-params/services.ts
@@ -1,22 +1,18 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import { 4import {
6 cleanupTests, 5 cleanupTests,
7 flushAndRunServer, 6 createSingleServer,
8 makeGetRequest, 7 makeGetRequest,
9 ServerInfo, 8 PeerTubeServer,
10 setAccessTokensToServers, 9 setAccessTokensToServers,
11 uploadVideo,
12 createVideoPlaylist,
13 setDefaultVideoChannel 10 setDefaultVideoChannel
14} from '../../../../shared/extra-utils' 11} from '@shared/extra-utils'
15import { VideoPlaylistPrivacy } from '@shared/models' 12import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
16import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
17 13
18describe('Test services API validators', function () { 14describe('Test services API validators', function () {
19 let server: ServerInfo 15 let server: PeerTubeServer
20 let playlistUUID: string 16 let playlistUUID: string
21 17
22 // --------------------------------------------------------------- 18 // ---------------------------------------------------------------
@@ -24,27 +20,22 @@ describe('Test services API validators', function () {
24 before(async function () { 20 before(async function () {
25 this.timeout(60000) 21 this.timeout(60000)
26 22
27 server = await flushAndRunServer(1) 23 server = await createSingleServer(1)
28 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
29 await setDefaultVideoChannel([ server ]) 25 await setDefaultVideoChannel([ server ])
30 26
31 { 27 server.store.video = await server.videos.upload({ attributes: { name: 'my super name' } })
32 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
33 server.video = res.body.video
34 }
35 28
36 { 29 {
37 const res = await createVideoPlaylist({ 30 const created = await server.playlists.create({
38 url: server.url, 31 attributes: {
39 token: server.accessToken,
40 playlistAttrs: {
41 displayName: 'super playlist', 32 displayName: 'super playlist',
42 privacy: VideoPlaylistPrivacy.PUBLIC, 33 privacy: VideoPlaylistPrivacy.PUBLIC,
43 videoChannelId: server.videoChannel.id 34 videoChannelId: server.store.channel.id
44 } 35 }
45 }) 36 })
46 37
47 playlistUUID = res.body.videoPlaylist.uuid 38 playlistUUID = created.uuid
48 } 39 }
49 }) 40 })
50 41
@@ -56,7 +47,7 @@ describe('Test services API validators', function () {
56 }) 47 })
57 48
58 it('Should fail with an invalid host', async function () { 49 it('Should fail with an invalid host', async function () {
59 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid 50 const embedUrl = 'http://hello.com/videos/watch/' + server.store.video.uuid
60 await checkParamEmbed(server, embedUrl) 51 await checkParamEmbed(server, embedUrl)
61 }) 52 })
62 53
@@ -71,37 +62,37 @@ describe('Test services API validators', function () {
71 }) 62 })
72 63
73 it('Should fail with an invalid path', async function () { 64 it('Should fail with an invalid path', async function () {
74 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}` 65 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.video.uuid}`
75 66
76 await checkParamEmbed(server, embedUrl) 67 await checkParamEmbed(server, embedUrl)
77 }) 68 })
78 69
79 it('Should fail with an invalid max height', async function () { 70 it('Should fail with an invalid max height', async function () {
80 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 71 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
81 72
82 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' }) 73 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
83 }) 74 })
84 75
85 it('Should fail with an invalid max width', async function () { 76 it('Should fail with an invalid max width', async function () {
86 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 77 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
87 78
88 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' }) 79 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
89 }) 80 })
90 81
91 it('Should fail with an invalid format', async function () { 82 it('Should fail with an invalid format', async function () {
92 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 83 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
93 84
94 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' }) 85 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
95 }) 86 })
96 87
97 it('Should fail with a non supported format', async function () { 88 it('Should fail with a non supported format', async function () {
98 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 89 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
99 90
100 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' }) 91 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
101 }) 92 })
102 93
103 it('Should succeed with the correct params with a video', async function () { 94 it('Should succeed with the correct params with a video', async function () {
104 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 95 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
105 const query = { 96 const query = {
106 format: 'json', 97 format: 'json',
107 maxheight: 400, 98 maxheight: 400,
@@ -128,13 +119,13 @@ describe('Test services API validators', function () {
128 }) 119 })
129}) 120})
130 121
131function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) { 122function checkParamEmbed (server: PeerTubeServer, embedUrl: string, expectedStatus = HttpStatusCode.BAD_REQUEST_400, query = {}) {
132 const path = '/services/oembed' 123 const path = '/services/oembed'
133 124
134 return makeGetRequest({ 125 return makeGetRequest({
135 url: server.url, 126 url: server.url,
136 path, 127 path,
137 query: Object.assign(query, { url: embedUrl }), 128 query: Object.assign(query, { url: embedUrl }),
138 statusCodeExpected 129 expectedStatus
139 }) 130 })
140} 131}