aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/services.ts159
-rw-r--r--server/tests/api/index.ts1
-rw-r--r--server/tests/api/services.ts85
-rw-r--r--server/tests/client.ts17
-rw-r--r--server/tests/utils/index.ts1
-rw-r--r--server/tests/utils/servers.ts2
-rw-r--r--server/tests/utils/services.ts23
8 files changed, 287 insertions, 2 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 399a05bc3..954b206e9 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -3,6 +3,7 @@ import './pods'
3import './remotes' 3import './remotes'
4import './users' 4import './users'
5import './request-schedulers' 5import './request-schedulers'
6import './services'
6import './videos' 7import './videos'
7import './video-abuses' 8import './video-abuses'
8import './video-blacklist' 9import './video-blacklist'
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
new file mode 100644
index 000000000..780254df5
--- /dev/null
+++ b/server/tests/api/check-params/services.ts
@@ -0,0 +1,159 @@
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})
diff --git a/server/tests/api/index.ts b/server/tests/api/index.ts
index 03711e68a..e50e65049 100644
--- a/server/tests/api/index.ts
+++ b/server/tests/api/index.ts
@@ -8,6 +8,7 @@ import './video-abuse'
8import './video-blacklist' 8import './video-blacklist'
9import './video-blacklist-management' 9import './video-blacklist-management'
10import './multiple-pods' 10import './multiple-pods'
11import './services'
11import './request-schedulers' 12import './request-schedulers'
12import './friends-advanced' 13import './friends-advanced'
13import './video-transcoder' 14import './video-transcoder'
diff --git a/server/tests/api/services.ts b/server/tests/api/services.ts
new file mode 100644
index 000000000..b396ea582
--- /dev/null
+++ b/server/tests/api/services.ts
@@ -0,0 +1,85 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
5const expect = chai.expect
6
7import {
8 ServerInfo,
9 flushTests,
10 uploadVideo,
11 getVideosList,
12 setAccessTokensToServers,
13 killallServers,
14 getOEmbed
15} from '../utils'
16import { runServer } from '../utils/servers'
17
18describe('Test services', function () {
19 let server: ServerInfo = null
20
21 before(async function () {
22 this.timeout(120000)
23
24 await flushTests()
25
26 server = await runServer(1)
27
28 await setAccessTokensToServers([ server ])
29
30 const videoAttributes = {
31 name: 'my super name'
32 }
33 await uploadVideo(server.url, server.accessToken, videoAttributes)
34
35 const res = await getVideosList(server.url)
36 server.video = res.body.data[0]
37 })
38
39 it('Should have a valid oEmbed response', async function () {
40 const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
41
42 const res = await getOEmbed(server.url, oembedUrl)
43 const expectedHtml = `<iframe width="560" height="315" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
44 'frameborder="0" allowfullscreen></iframe>'
45 const expectedThumbnailUrl = 'http://localhost:9001/static/thumbnails/' + server.video.uuid + '.jpg'
46
47 expect(res.body.html).to.equal(expectedHtml)
48 expect(res.body.title).to.equal(server.video.name)
49 expect(res.body.author_name).to.equal(server.video.author)
50 expect(res.body.height).to.equal(315)
51 expect(res.body.width).to.equal(560)
52 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
53 expect(res.body.thumbnail_width).to.equal(200)
54 expect(res.body.thumbnail_height).to.equal(110)
55 })
56
57 it('Should have a valid oEmbed response with small max height query', async function () {
58 const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
59 const format = 'json'
60 const maxHeight = 50
61 const maxWidth = 50
62
63 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
64 const expectedHtml = `<iframe width="50" height="50" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
65 'frameborder="0" allowfullscreen></iframe>'
66
67 expect(res.body.html).to.equal(expectedHtml)
68 expect(res.body.title).to.equal(server.video.name)
69 expect(res.body.author_name).to.equal(server.video.author)
70 expect(res.body.height).to.equal(50)
71 expect(res.body.width).to.equal(50)
72 expect(res.body).to.not.have.property('thumbnail_url')
73 expect(res.body).to.not.have.property('thumbnail_width')
74 expect(res.body).to.not.have.property('thumbnail_height')
75 })
76
77 after(async function () {
78 killallServers([ server ])
79
80 // Keep the logs if the test failed
81 if (this['ok']) {
82 await flushTests()
83 }
84 })
85})
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 5e5abba5a..5f947ed2b 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -39,7 +39,7 @@ describe('Test a client controllers', function () {
39 server.video = videos[0] 39 server.video = videos[0]
40 }) 40 })
41 41
42 it('It should have valid Open Graph tags on the watch page with video id', async function () { 42 it('Should have valid Open Graph tags on the watch page with video id', async function () {
43 const res = await request(server.url) 43 const res = await request(server.url)
44 .get('/videos/watch/' + server.video.id) 44 .get('/videos/watch/' + server.video.id)
45 .expect(200) 45 .expect(200)
@@ -48,7 +48,7 @@ describe('Test a client controllers', function () {
48 expect(res.text).to.contain('<meta property="og:description" content="my super description for pod 1" />') 48 expect(res.text).to.contain('<meta property="og:description" content="my super description for pod 1" />')
49 }) 49 })
50 50
51 it('It should have valid Open Graph tags on the watch page with video uuid', async function () { 51 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
52 const res = await request(server.url) 52 const res = await request(server.url)
53 .get('/videos/watch/' + server.video.uuid) 53 .get('/videos/watch/' + server.video.uuid)
54 .expect(200) 54 .expect(200)
@@ -57,6 +57,19 @@ describe('Test a client controllers', function () {
57 expect(res.text).to.contain('<meta property="og:description" content="my super description for pod 1" />') 57 expect(res.text).to.contain('<meta property="og:description" content="my super description for pod 1" />')
58 }) 58 })
59 59
60 it('Should have valid oEmbed discovery tags', async function () {
61 const path = '/videos/watch/' + server.video.uuid
62 const res = await request(server.url)
63 .get(path)
64 .expect(200)
65
66 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:9001/services/oembed?' +
67 `url=http%3A%2F%2Flocalhost%3A9001%2Fvideos%2Fwatch%2F${server.video.uuid}" ` +
68 `title="${server.video.name}" />`
69
70 expect(res.text).to.contain(expectedLink)
71 })
72
60 after(async function () { 73 after(async function () {
61 process.kill(-server.app.pid) 74 process.kill(-server.app.pid)
62 75
diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts
index 99c445887..90ee2d515 100644
--- a/server/tests/utils/index.ts
+++ b/server/tests/utils/index.ts
@@ -7,6 +7,7 @@ export * from './pods'
7export * from './request-schedulers' 7export * from './request-schedulers'
8export * from './requests' 8export * from './requests'
9export * from './servers' 9export * from './servers'
10export * from './services'
10export * from './users' 11export * from './users'
11export * from './video-abuses' 12export * from './video-abuses'
12export * from './video-blacklist' 13export * from './video-blacklist'
diff --git a/server/tests/utils/servers.ts b/server/tests/utils/servers.ts
index 88027f74e..3526ffa51 100644
--- a/server/tests/utils/servers.ts
+++ b/server/tests/utils/servers.ts
@@ -23,6 +23,8 @@ interface ServerInfo {
23 video?: { 23 video?: {
24 id: number 24 id: number
25 uuid: string 25 uuid: string
26 name: string
27 author: string
26 } 28 }
27 29
28 remoteVideo?: { 30 remoteVideo?: {
diff --git a/server/tests/utils/services.ts b/server/tests/utils/services.ts
new file mode 100644
index 000000000..1a53dd4cf
--- /dev/null
+++ b/server/tests/utils/services.ts
@@ -0,0 +1,23 @@
1import * as request from 'supertest'
2
3function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: number, maxWidth?: number) {
4 const path = '/services/oembed'
5 const query = {
6 url: oembedUrl,
7 format,
8 maxheight: maxHeight,
9 maxwidth: maxWidth
10 }
11
12 return request(url)
13 .get(path)
14 .query(query)
15 .set('Accept', 'application/json')
16 .expect(200)
17}
18
19// ---------------------------------------------------------------------------
20
21export {
22 getOEmbed
23}