]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/services.ts
Update videos api list for account
[github/Chocobozzz/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" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
36 'frameborder="0" allowfullscreen></iframe>'
37 const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg'
38
39 expect(res.body.html).to.equal(expectedHtml)
40 expect(res.body.title).to.equal(server.video.name)
41 expect(res.body.author_name).to.equal(server.video.account.name)
42 expect(res.body.width).to.equal(560)
43 expect(res.body.height).to.equal(315)
44 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
45 expect(res.body.thumbnail_width).to.equal(560)
46 expect(res.body.thumbnail_height).to.equal(315)
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)
61 expect(res.body.author_name).to.equal(server.video.account.name)
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 })