Merge branch 'develop' of https://github.com/Chocobozzz/PeerTube into move-utils...
[oweals/peertube.git] / server / tests / api / videos / services.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6   flushTests,
7   getOEmbed,
8   getVideosList,
9   killallServers,
10   ServerInfo,
11   setAccessTokensToServers,
12   uploadVideo
13 } from '../../../../shared/utils/index'
14 import { runServer } from '../../../../shared/utils/server/servers'
15
16 const expect = chai.expect
17
18 describe('Test services', function () {
19   let server: ServerInfo = null
20
21   before(async function () {
22     this.timeout(30000)
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" sandbox="allow-same-origin allow-scripts" ' +
44                          `src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
45                          'frameborder="0" allowfullscreen></iframe>'
46     const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg'
47
48     expect(res.body.html).to.equal(expectedHtml)
49     expect(res.body.title).to.equal(server.video.name)
50     expect(res.body.author_name).to.equal(server.video.account.name)
51     expect(res.body.width).to.equal(560)
52     expect(res.body.height).to.equal(315)
53     expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
54     expect(res.body.thumbnail_width).to.equal(560)
55     expect(res.body.thumbnail_height).to.equal(315)
56   })
57
58   it('Should have a valid oEmbed response with small max height query', async function () {
59     const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
60     const format = 'json'
61     const maxHeight = 50
62     const maxWidth = 50
63
64     const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
65     const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
66                          `src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
67                          'frameborder="0" allowfullscreen></iframe>'
68
69     expect(res.body.html).to.equal(expectedHtml)
70     expect(res.body.title).to.equal(server.video.name)
71     expect(res.body.author_name).to.equal(server.video.account.name)
72     expect(res.body.height).to.equal(50)
73     expect(res.body.width).to.equal(50)
74     expect(res.body).to.not.have.property('thumbnail_url')
75     expect(res.body).to.not.have.property('thumbnail_width')
76     expect(res.body).to.not.have.property('thumbnail_height')
77   })
78
79   after(async function () {
80     killallServers([ server ])
81   })
82 })