]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/services.ts
Fix real world script
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / services.ts
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/index'
16 import { runServer } from '../../utils/server/servers'
17
18 describe('Test services', function () {
19 let server: ServerInfo = null
20
21 before(async function () {
22 this.timeout(10000)
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 const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
34 server.video = res.body.video
35 })
36
37 it('Should have a valid oEmbed response', async function () {
38 const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
39
40 const res = await getOEmbed(server.url, oembedUrl)
41 const expectedHtml = `<iframe width="560" height="315" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
42 'frameborder="0" allowfullscreen></iframe>'
43 const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg'
44
45 expect(res.body.html).to.equal(expectedHtml)
46 expect(res.body.title).to.equal(server.video.name)
47 expect(res.body.author_name).to.equal(server.video.accountName)
48 expect(res.body.width).to.equal(560)
49 expect(res.body.height).to.equal(315)
50 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
51 expect(res.body.thumbnail_width).to.equal(560)
52 expect(res.body.thumbnail_height).to.equal(315)
53 })
54
55 it('Should have a valid oEmbed response with small max height query', async function () {
56 const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
57 const format = 'json'
58 const maxHeight = 50
59 const maxWidth = 50
60
61 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
62 const expectedHtml = `<iframe width="50" height="50" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
63 'frameborder="0" allowfullscreen></iframe>'
64
65 expect(res.body.html).to.equal(expectedHtml)
66 expect(res.body.title).to.equal(server.video.name)
67 expect(res.body.author_name).to.equal(server.video.accountName)
68 expect(res.body.height).to.equal(50)
69 expect(res.body.width).to.equal(50)
70 expect(res.body).to.not.have.property('thumbnail_url')
71 expect(res.body).to.not.have.property('thumbnail_width')
72 expect(res.body).to.not.have.property('thumbnail_height')
73 })
74
75 after(async function () {
76 killallServers([ server ])
77
78 // Keep the logs if the test failed
79 if (this['ok']) {
80 await flushTests()
81 }
82 })
83 })