]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/services.ts
Speed up activity pub http requests
[github/Chocobozzz/PeerTube.git] / server / tests / api / services.ts
CommitLineData
d8755eed
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
5const expect = chai.expect
6
7import {
8 ServerInfo,
9 flushTests,
10 uploadVideo,
11 getVideosList,
12 setAccessTokensToServers,
13 killallServers,
14 getOEmbed
15} from '../utils'
16import { runServer } from '../utils/servers'
afffe988 17import { Video } from '../../../client/src/app/videos/shared/video.model'
d8755eed
C
18
19describe('Test services', function () {
20 let server: ServerInfo = null
21
22 before(async function () {
23 this.timeout(120000)
24
25 await flushTests()
26
27 server = await runServer(1)
28
29 await setAccessTokensToServers([ server ])
30
31 const videoAttributes = {
32 name: 'my super name'
33 }
34 await uploadVideo(server.url, server.accessToken, videoAttributes)
35
36 const res = await getVideosList(server.url)
37 server.video = res.body.data[0]
38 })
39
40 it('Should have a valid oEmbed response', async function () {
41 const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
42
43 const res = await getOEmbed(server.url, oembedUrl)
44 const expectedHtml = `<iframe width="560" height="315" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
45 'frameborder="0" allowfullscreen></iframe>'
164174a6 46 const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg'
d8755eed
C
47
48 expect(res.body.html).to.equal(expectedHtml)
49 expect(res.body.title).to.equal(server.video.name)
afffe988 50 expect(res.body.author_name).to.equal(server.video.account)
d8755eed 51 expect(res.body.width).to.equal(560)
164174a6 52 expect(res.body.height).to.equal(315)
d8755eed 53 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
164174a6
C
54 expect(res.body.thumbnail_width).to.equal(560)
55 expect(res.body.thumbnail_height).to.equal(315)
d8755eed
C
56 })
57
58 it('Should have a valid oEmbed response with small max height query', async function () {
59 const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid
60 const format = 'json'
61 const maxHeight = 50
62 const maxWidth = 50
63
64 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
65 const expectedHtml = `<iframe width="50" height="50" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` +
66 'frameborder="0" allowfullscreen></iframe>'
67
68 expect(res.body.html).to.equal(expectedHtml)
69 expect(res.body.title).to.equal(server.video.name)
afffe988 70 expect(res.body.author_name).to.equal(server.video.account)
d8755eed
C
71 expect(res.body.height).to.equal(50)
72 expect(res.body.width).to.equal(50)
73 expect(res.body).to.not.have.property('thumbnail_url')
74 expect(res.body).to.not.have.property('thumbnail_width')
75 expect(res.body).to.not.have.property('thumbnail_height')
76 })
77
78 after(async function () {
79 killallServers([ server ])
80
81 // Keep the logs if the test failed
82 if (this['ok']) {
83 await flushTests()
84 }
85 })
86})