]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/services.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / services.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { getOEmbed, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index'
6 import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-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 server = await flushAndRunServer(1)
17
18 await setAccessTokensToServers([ server ])
19
20 const videoAttributes = {
21 name: 'my super name'
22 }
23 await uploadVideo(server.url, server.accessToken, videoAttributes)
24
25 const res = await getVideosList(server.url)
26 server.video = res.body.data[0]
27 })
28
29 it('Should have a valid oEmbed response', async function () {
30 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid
31
32 const res = await getOEmbed(server.url, oembedUrl)
33 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
34 `src="http://localhost:${server.port}/videos/embed/${server.video.uuid}" ` +
35 'frameborder="0" allowfullscreen></iframe>'
36 const expectedThumbnailUrl = 'http://localhost:' + server.port + '/static/previews/' + server.video.uuid + '.jpg'
37
38 expect(res.body.html).to.equal(expectedHtml)
39 expect(res.body.title).to.equal(server.video.name)
40 expect(res.body.author_name).to.equal(server.video.account.name)
41 expect(res.body.width).to.equal(560)
42 expect(res.body.height).to.equal(315)
43 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
44 expect(res.body.thumbnail_width).to.equal(850)
45 expect(res.body.thumbnail_height).to.equal(480)
46 })
47
48 it('Should have a valid oEmbed response with small max height query', async function () {
49 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid
50 const format = 'json'
51 const maxHeight = 50
52 const maxWidth = 50
53
54 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
55 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
56 `src="http://localhost:${server.port}/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 await cleanupTests([ server ])
71 })
72 })