]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/services.ts
Add ability to list jobs
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / services.ts
CommitLineData
d8755eed
C
1/* tslint:disable:no-unused-expression */
2
3import * as request from 'supertest'
4import 'mocha'
5
6import {
7 flushTests,
8 runServer,
9 setAccessTokensToServers,
10 killallServers
11} from '../../utils'
12import { getVideosList, uploadVideo } from '../../utils/videos'
13
14describe('Test services API validators', function () {
15 let server
16
17 // ---------------------------------------------------------------
18
19 before(async function () {
20 this.timeout(60000)
21
22 await flushTests()
23
24 server = await runServer(1)
25 await setAccessTokensToServers([ server ])
26
27 const videoAttributes = {
28 name: 'my super name'
29 }
30 await uploadVideo(server.url, server.accessToken, videoAttributes)
31
32 const res = await getVideosList(server.url)
33 server.video = res.body.data[0]
34 })
35
36 describe('Test oEmbed API validators', function () {
37 const path = '/services/oembed'
38
39 it('Should fail with an invalid url', async function () {
40 const embedUrl = 'hello.com'
41
42 await request(server.url)
43 .get(path)
44 .query({ url: embedUrl })
45 .set('Accept', 'application/json')
46 .set('Authorization', 'Bearer ' + server.accessToken)
47 .expect(400)
48 })
49
50 it('Should fail with an invalid host', async function () {
51 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid
52
53 await request(server.url)
54 .get(path)
55 .query({ url: embedUrl })
56 .set('Accept', 'application/json')
57 .set('Authorization', 'Bearer ' + server.accessToken)
58 .expect(400)
59 })
60
61 it('Should fail with an invalid video id', async function () {
62 const embedUrl = 'http://localhost:9001/videos/watch/blabla'
63
64 await request(server.url)
65 .get(path)
66 .query({ url: embedUrl })
67 .set('Accept', 'application/json')
68 .set('Authorization', 'Bearer ' + server.accessToken)
69 .expect(400)
70 })
71
72 it('Should fail with an unknown video', async function () {
73 const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c'
74
75 await request(server.url)
76 .get(path)
77 .query({ url: embedUrl })
78 .set('Accept', 'application/json')
79 .set('Authorization', 'Bearer ' + server.accessToken)
80 .expect(404)
81 })
82
83 it('Should fail with an invalid path', async function () {
84 const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid
85
86 await request(server.url)
87 .get(path)
88 .query({ url: embedUrl })
89 .set('Accept', 'application/json')
90 .set('Authorization', 'Bearer ' + server.accessToken)
91 .expect(400)
92 })
93
94 it('Should fail with an invalid max height', async function () {
95 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
96
97 await request(server.url)
98 .get(path)
99 .query({
100 url: embedUrl,
101 maxheight: 'hello'
102 })
103 .set('Accept', 'application/json')
104 .set('Authorization', 'Bearer ' + server.accessToken)
105 .expect(400)
106 })
107
108 it('Should fail with an invalid max width', async function () {
109 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
110
111 await request(server.url)
112 .get(path)
113 .query({
114 url: embedUrl,
115 maxwidth: 'hello'
116 })
117 .set('Accept', 'application/json')
118 .set('Authorization', 'Bearer ' + server.accessToken)
119 .expect(400)
120 })
121
122 it('Should fail with an invalid format', async function () {
123 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
124
125 await request(server.url)
126 .get(path)
127 .query({
128 url: embedUrl,
129 format: 'blabla'
130 })
131 .set('Accept', 'application/json')
132 .set('Authorization', 'Bearer ' + server.accessToken)
133 .expect(400)
134 })
135
136 it('Should fail with a non supported format', async function () {
137 const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
138
139 await request(server.url)
140 .get(path)
141 .query({
142 url: embedUrl,
143 format: 'xml'
144 })
145 .set('Accept', 'application/json')
146 .set('Authorization', 'Bearer ' + server.accessToken)
147 .expect(501)
148 })
149 })
150
151 after(async function () {
152 killallServers([ server ])
153
154 // Keep the logs if the test failed
155 if (this['ok']) {
156 await flushTests()
157 }
158 })
159})