]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/services.ts
nginx optimizations
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / services.ts
CommitLineData
d8755eed
C
1/* tslint:disable:no-unused-expression */
2
d8755eed 3import * as chai from 'chai'
8b0d42ee
C
4import 'mocha'
5import { flushTests, getOEmbed, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index'
c5d31dba 6import { runServer } from '../../utils/server/servers'
d8755eed 7
8b0d42ee
C
8const expect = chai.expect
9
d8755eed
C
10describe('Test services', function () {
11 let server: ServerInfo = null
12
13 before(async function () {
572f8d3d 14 this.timeout(10000)
d8755eed
C
15
16 await flushTests()
17
18 server = await runServer(1)
19
20 await setAccessTokensToServers([ server ])
21
22 const videoAttributes = {
23 name: 'my super name'
24 }
8b0d42ee
C
25 await uploadVideo(server.url, server.accessToken, videoAttributes)
26
27 const res = await getVideosList(server.url)
28 server.video = res.body.data[0]
d8755eed
C
29 })
30
31 it('Should have a valid oEmbed response', async function () {
32 const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
33
34 const res = await getOEmbed(server.url, oembedUrl)
35 const expectedHtml = `<iframe width="560" height="315" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
36 'frameborder="0" allowfullscreen></iframe>'
164174a6 37 const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg'
d8755eed
C
38
39 expect(res.body.html).to.equal(expectedHtml)
40 expect(res.body.title).to.equal(server.video.name)
b1fa3eba 41 expect(res.body.author_name).to.equal(server.video.accountName)
d8755eed 42 expect(res.body.width).to.equal(560)
164174a6 43 expect(res.body.height).to.equal(315)
d8755eed 44 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
164174a6
C
45 expect(res.body.thumbnail_width).to.equal(560)
46 expect(res.body.thumbnail_height).to.equal(315)
d8755eed
C
47 })
48
49 it('Should have a valid oEmbed response with small max height query', async function () {
50 const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
51 const format = 'json'
52 const maxHeight = 50
53 const maxWidth = 50
54
55 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
56 const expectedHtml = `<iframe width="50" height="50" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
57 'frameborder="0" allowfullscreen></iframe>'
58
59 expect(res.body.html).to.equal(expectedHtml)
60 expect(res.body.title).to.equal(server.video.name)
b1fa3eba 61 expect(res.body.author_name).to.equal(server.video.accountName)
d8755eed
C
62 expect(res.body.height).to.equal(50)
63 expect(res.body.width).to.equal(50)
64 expect(res.body).to.not.have.property('thumbnail_url')
65 expect(res.body).to.not.have.property('thumbnail_width')
66 expect(res.body).to.not.have.property('thumbnail_height')
67 })
68
69 after(async function () {
70 killallServers([ server ])
71
72 // Keep the logs if the test failed
73 if (this['ok']) {
74 await flushTests()
75 }
76 })
77})