]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/services.ts
Improve tests when waiting pending jobs
[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 () {
e212f887 14 this.timeout(30000)
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)
2186386c
C
35 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
36 `src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
d8755eed 37 'frameborder="0" allowfullscreen></iframe>'
164174a6 38 const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg'
d8755eed
C
39
40 expect(res.body.html).to.equal(expectedHtml)
41 expect(res.body.title).to.equal(server.video.name)
b64c950a 42 expect(res.body.author_name).to.equal(server.video.account.name)
d8755eed 43 expect(res.body.width).to.equal(560)
164174a6 44 expect(res.body.height).to.equal(315)
d8755eed 45 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
164174a6
C
46 expect(res.body.thumbnail_width).to.equal(560)
47 expect(res.body.thumbnail_height).to.equal(315)
d8755eed
C
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)
3cd0734f
C
57 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
58 `src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
d8755eed
C
59 'frameborder="0" allowfullscreen></iframe>'
60
61 expect(res.body.html).to.equal(expectedHtml)
62 expect(res.body.title).to.equal(server.video.name)
b64c950a 63 expect(res.body.author_name).to.equal(server.video.account.name)
d8755eed
C
64 expect(res.body.height).to.equal(50)
65 expect(res.body.width).to.equal(50)
66 expect(res.body).to.not.have.property('thumbnail_url')
67 expect(res.body).to.not.have.property('thumbnail_width')
68 expect(res.body).to.not.have.property('thumbnail_height')
69 })
70
71 after(async function () {
72 killallServers([ server ])
d8755eed
C
73 })
74})