diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params/services.ts | 123 |
1 files changed, 36 insertions, 87 deletions
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index f82520574..62a14f51f 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts | |||
@@ -1,18 +1,11 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* tslint:disable:no-unused-expression */ |
2 | 2 | ||
3 | import * as request from 'supertest' | ||
4 | import 'mocha' | 3 | import 'mocha' |
5 | 4 | ||
6 | import { | 5 | import { flushTests, killallServers, makeGetRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' |
7 | flushTests, | ||
8 | runServer, | ||
9 | setAccessTokensToServers, | ||
10 | killallServers | ||
11 | } from '../../utils' | ||
12 | import { getVideosList, uploadVideo } from '../../utils/videos/videos' | ||
13 | 6 | ||
14 | describe('Test services API validators', function () { | 7 | describe('Test services API validators', function () { |
15 | let server | 8 | let server: ServerInfo |
16 | 9 | ||
17 | // --------------------------------------------------------------- | 10 | // --------------------------------------------------------------- |
18 | 11 | ||
@@ -24,127 +17,71 @@ describe('Test services API validators', function () { | |||
24 | server = await runServer(1) | 17 | server = await runServer(1) |
25 | await setAccessTokensToServers([ server ]) | 18 | await setAccessTokensToServers([ server ]) |
26 | 19 | ||
27 | const videoAttributes = { | 20 | const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' }) |
28 | name: 'my super name' | 21 | server.video = res.body.video |
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 | }) | 22 | }) |
35 | 23 | ||
36 | describe('Test oEmbed API validators', function () { | 24 | describe('Test oEmbed API validators', function () { |
37 | const path = '/services/oembed' | ||
38 | 25 | ||
39 | it('Should fail with an invalid url', async function () { | 26 | it('Should fail with an invalid url', async function () { |
40 | const embedUrl = 'hello.com' | 27 | const embedUrl = 'hello.com' |
41 | 28 | await checkParamEmbed(server, embedUrl) | |
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 | }) | 29 | }) |
49 | 30 | ||
50 | it('Should fail with an invalid host', async function () { | 31 | it('Should fail with an invalid host', async function () { |
51 | const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid | 32 | const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid |
52 | 33 | await checkParamEmbed(server, embedUrl) | |
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 | }) | 34 | }) |
60 | 35 | ||
61 | it('Should fail with an invalid video id', async function () { | 36 | it('Should fail with an invalid video id', async function () { |
62 | const embedUrl = 'http://localhost:9001/videos/watch/blabla' | 37 | const embedUrl = 'http://localhost:9001/videos/watch/blabla' |
63 | 38 | await checkParamEmbed(server, embedUrl) | |
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 | }) | 39 | }) |
71 | 40 | ||
72 | it('Should fail with an unknown video', async function () { | 41 | it('Should fail with an unknown video', async function () { |
73 | const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c' | 42 | const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c' |
74 | 43 | await checkParamEmbed(server, embedUrl, 404) | |
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 | }) | 44 | }) |
82 | 45 | ||
83 | it('Should fail with an invalid path', async function () { | 46 | it('Should fail with an invalid path', async function () { |
84 | const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid | 47 | const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid |
85 | 48 | ||
86 | await request(server.url) | 49 | await checkParamEmbed(server, embedUrl) |
87 | .get(path) | ||
88 | .query({ url: embedUrl }) | ||
89 | .set('Accept', 'application/json') | ||
90 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
91 | .expect(400) | ||
92 | }) | 50 | }) |
93 | 51 | ||
94 | it('Should fail with an invalid max height', async function () { | 52 | it('Should fail with an invalid max height', async function () { |
95 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | 53 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid |
96 | 54 | ||
97 | await request(server.url) | 55 | await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' }) |
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 | }) | 56 | }) |
107 | 57 | ||
108 | it('Should fail with an invalid max width', async function () { | 58 | it('Should fail with an invalid max width', async function () { |
109 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | 59 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid |
110 | 60 | ||
111 | await request(server.url) | 61 | await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' }) |
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 | }) | 62 | }) |
121 | 63 | ||
122 | it('Should fail with an invalid format', async function () { | 64 | it('Should fail with an invalid format', async function () { |
123 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | 65 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid |
124 | 66 | ||
125 | await request(server.url) | 67 | await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' }) |
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 | }) | 68 | }) |
135 | 69 | ||
136 | it('Should fail with a non supported format', async function () { | 70 | it('Should fail with a non supported format', async function () { |
137 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid | 71 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid |
138 | 72 | ||
139 | await request(server.url) | 73 | await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) |
140 | .get(path) | 74 | }) |
141 | .query({ | 75 | |
142 | url: embedUrl, | 76 | it('Should succeed with the correct params', async function () { |
143 | format: 'xml' | 77 | const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid |
144 | }) | 78 | const query = { |
145 | .set('Accept', 'application/json') | 79 | format: 'json', |
146 | .set('Authorization', 'Bearer ' + server.accessToken) | 80 | maxheight: 400, |
147 | .expect(501) | 81 | maxwidth: 400 |
82 | } | ||
83 | |||
84 | await checkParamEmbed(server, embedUrl, 200, query) | ||
148 | }) | 85 | }) |
149 | }) | 86 | }) |
150 | 87 | ||
@@ -157,3 +94,15 @@ describe('Test services API validators', function () { | |||
157 | } | 94 | } |
158 | }) | 95 | }) |
159 | }) | 96 | }) |
97 | |||
98 | function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) { | ||
99 | const path = '/services/oembed' | ||
100 | |||
101 | return makeGetRequest({ | ||
102 | url: server.url, | ||
103 | path, | ||
104 | query: Object.assign(query, { url: embedUrl }), | ||
105 | token: server.accessToken, | ||
106 | statusCodeExpected | ||
107 | }) | ||
108 | } | ||