]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/services.ts
Fix benchmark
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / services.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
d8755eed 2
8b0d42ee 3import 'mocha'
6fad8e51 4import * as chai from 'chai'
6302d599 5import { Video, VideoPlaylistPrivacy } from '@shared/models'
6fad8e51 6import {
6302d599
C
7 addVideoInPlaylist,
8 createVideoPlaylist,
6fad8e51
C
9 getOEmbed,
10 getVideosList,
11 ServerInfo,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
6302d599 14 uploadVideo
6fad8e51 15} from '../../../../shared/extra-utils'
7c3b7976 16import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
d8755eed 17
8b0d42ee
C
18const expect = chai.expect
19
d8755eed
C
20describe('Test services', function () {
21 let server: ServerInfo = null
6fad8e51 22 let playlistUUID: string
6302d599 23 let video: Video
d8755eed
C
24
25 before(async function () {
e212f887 26 this.timeout(30000)
d8755eed 27
210feb6c 28 server = await flushAndRunServer(1)
d8755eed
C
29
30 await setAccessTokensToServers([ server ])
6fad8e51 31 await setDefaultVideoChannel([ server ])
d8755eed 32
6fad8e51
C
33 {
34 const videoAttributes = {
35 name: 'my super name'
36 }
37 await uploadVideo(server.url, server.accessToken, videoAttributes)
38
39 const res = await getVideosList(server.url)
6302d599 40 video = res.body.data[0]
d8755eed 41 }
8b0d42ee 42
6fad8e51
C
43 {
44 const res = await createVideoPlaylist({
45 url: server.url,
46 token: server.accessToken,
47 playlistAttrs: {
48 displayName: 'The Life and Times of Scrooge McDuck',
49 privacy: VideoPlaylistPrivacy.PUBLIC,
50 videoChannelId: server.videoChannel.id
51 }
52 })
53
54 playlistUUID = res.body.videoPlaylist.uuid
55
56 await addVideoInPlaylist({
57 url: server.url,
58 token: server.accessToken,
59 playlistId: res.body.videoPlaylist.id,
60 elementAttrs: {
6302d599 61 videoId: video.id
6fad8e51
C
62 }
63 })
64 }
d8755eed
C
65 })
66
6fad8e51 67 it('Should have a valid oEmbed video response', async function () {
6302d599 68 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid
d8755eed
C
69
70 const res = await getOEmbed(server.url, oembedUrl)
2186386c 71 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
6302d599 72 `src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
a1587156 73 'frameborder="0" allowfullscreen></iframe>'
6302d599 74 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath
d8755eed
C
75
76 expect(res.body.html).to.equal(expectedHtml)
6302d599 77 expect(res.body.title).to.equal(video.name)
6fad8e51 78 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
d8755eed 79 expect(res.body.width).to.equal(560)
164174a6 80 expect(res.body.height).to.equal(315)
d8755eed 81 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
80b8ad2a
C
82 expect(res.body.thumbnail_width).to.equal(850)
83 expect(res.body.thumbnail_height).to.equal(480)
d8755eed
C
84 })
85
6fad8e51
C
86 it('Should have a valid playlist oEmbed response', async function () {
87 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/playlist/' + playlistUUID
88
89 const res = await getOEmbed(server.url, oembedUrl)
90 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
91 `src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
92 'frameborder="0" allowfullscreen></iframe>'
93
94 expect(res.body.html).to.equal(expectedHtml)
95 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
96 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
97 expect(res.body.width).to.equal(560)
98 expect(res.body.height).to.equal(315)
99 expect(res.body.thumbnail_url).exist
100 expect(res.body.thumbnail_width).to.equal(223)
101 expect(res.body.thumbnail_height).to.equal(122)
102 })
103
d8755eed 104 it('Should have a valid oEmbed response with small max height query', async function () {
6302d599 105 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid
d8755eed
C
106 const format = 'json'
107 const maxHeight = 50
108 const maxWidth = 50
109
110 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
3cd0734f 111 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
6302d599 112 `src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
a1587156 113 'frameborder="0" allowfullscreen></iframe>'
d8755eed
C
114
115 expect(res.body.html).to.equal(expectedHtml)
6302d599 116 expect(res.body.title).to.equal(video.name)
6fad8e51 117 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
d8755eed
C
118 expect(res.body.height).to.equal(50)
119 expect(res.body.width).to.equal(50)
120 expect(res.body).to.not.have.property('thumbnail_url')
121 expect(res.body).to.not.have.property('thumbnail_width')
122 expect(res.body).to.not.have.property('thumbnail_height')
123 })
124
7c3b7976
C
125 after(async function () {
126 await cleanupTests([ server ])
d8755eed
C
127 })
128})