Add concept of video state, and add ability to wait transcoding before
[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 { flushTests, getOEmbed, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index'
6 import { runServer } from '../../utils/server/servers'
7
8 const expect = chai.expect
9
10 describe('Test services', function () {
11   let server: ServerInfo = null
12
13   before(async function () {
14     this.timeout(30000)
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     }
25     await uploadVideo(server.url, server.accessToken, videoAttributes)
26
27     const res = await getVideosList(server.url)
28     server.video = res.body.data[0]
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" sandbox="allow-same-origin allow-scripts" ' +
36                          `src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
37                          'frameborder="0" allowfullscreen></iframe>'
38     const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg'
39
40     expect(res.body.html).to.equal(expectedHtml)
41     expect(res.body.title).to.equal(server.video.name)
42     expect(res.body.author_name).to.equal(server.video.account.name)
43     expect(res.body.width).to.equal(560)
44     expect(res.body.height).to.equal(315)
45     expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
46     expect(res.body.thumbnail_width).to.equal(560)
47     expect(res.body.thumbnail_height).to.equal(315)
48   })
49
50   it('Should have a valid oEmbed response with small max height query', async function () {
51     const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
52     const format = 'json'
53     const maxHeight = 50
54     const maxWidth = 50
55
56     const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
57     const expectedHtml = `<iframe width="50" height="50" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
58                          'frameborder="0" allowfullscreen></iframe>'
59
60     expect(res.body.html).to.equal(expectedHtml)
61     expect(res.body.title).to.equal(server.video.name)
62     expect(res.body.author_name).to.equal(server.video.account.name)
63     expect(res.body.height).to.equal(50)
64     expect(res.body.width).to.equal(50)
65     expect(res.body).to.not.have.property('thumbnail_url')
66     expect(res.body).to.not.have.property('thumbnail_width')
67     expect(res.body).to.not.have.property('thumbnail_height')
68   })
69
70   after(async function () {
71     killallServers([ server ])
72
73     // Keep the logs if the test failed
74     if (this['ok']) {
75       await flushTests()
76     }
77   })
78 })