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