diff options
Diffstat (limited to 'server/tests/api/services.ts')
-rw-r--r-- | server/tests/api/services.ts | 85 |
1 files changed, 85 insertions, 0 deletions
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 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | const expect = chai.expect | ||
6 | |||
7 | import { | ||
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | uploadVideo, | ||
11 | getVideosList, | ||
12 | setAccessTokensToServers, | ||
13 | killallServers, | ||
14 | getOEmbed | ||
15 | } from '../utils' | ||
16 | import { runServer } from '../utils/servers' | ||
17 | |||
18 | describe('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 | }) | ||