1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { Video, VideoPlaylistPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
15 } from '../../../../shared/extra-utils'
16 import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
18 const expect = chai.expect
20 describe('Test services', function () {
21 let server: ServerInfo = null
22 let playlistUUID: string
23 let playlistDisplayName: string
26 before(async function () {
29 server = await flushAndRunServer(1)
31 await setAccessTokensToServers([ server ])
32 await setDefaultVideoChannel([ server ])
35 const videoAttributes = {
38 await uploadVideo(server.url, server.accessToken, videoAttributes)
40 const res = await getVideosList(server.url)
41 video = res.body.data[0]
45 const res = await createVideoPlaylist({
47 token: server.accessToken,
49 displayName: 'The Life and Times of Scrooge McDuck',
50 privacy: VideoPlaylistPrivacy.PUBLIC,
51 videoChannelId: server.videoChannel.id
55 playlistUUID = res.body.videoPlaylist.uuid
56 playlistDisplayName = 'The Life and Times of Scrooge McDuck'
58 await addVideoInPlaylist({
60 token: server.accessToken,
61 playlistId: res.body.videoPlaylist.id,
69 it('Should have a valid oEmbed video response', async function () {
70 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid
72 const res = await getOEmbed(server.url, oembedUrl)
73 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
74 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
75 'frameborder="0" allowfullscreen></iframe>'
76 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath
78 expect(res.body.html).to.equal(expectedHtml)
79 expect(res.body.title).to.equal(video.name)
80 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
81 expect(res.body.width).to.equal(560)
82 expect(res.body.height).to.equal(315)
83 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
84 expect(res.body.thumbnail_width).to.equal(850)
85 expect(res.body.thumbnail_height).to.equal(480)
88 it('Should have a valid playlist oEmbed response', async function () {
89 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/playlist/' + playlistUUID
91 const res = await getOEmbed(server.url, oembedUrl)
92 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
93 `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
94 'frameborder="0" allowfullscreen></iframe>'
96 expect(res.body.html).to.equal(expectedHtml)
97 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
98 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
99 expect(res.body.width).to.equal(560)
100 expect(res.body.height).to.equal(315)
101 expect(res.body.thumbnail_url).exist
102 expect(res.body.thumbnail_width).to.equal(280)
103 expect(res.body.thumbnail_height).to.equal(157)
106 it('Should have a valid oEmbed response with small max height query', async function () {
107 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid
108 const format = 'json'
112 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
113 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
114 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
115 'frameborder="0" allowfullscreen></iframe>'
117 expect(res.body.html).to.equal(expectedHtml)
118 expect(res.body.title).to.equal(video.name)
119 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
120 expect(res.body.height).to.equal(50)
121 expect(res.body.width).to.equal(50)
122 expect(res.body).to.not.have.property('thumbnail_url')
123 expect(res.body).to.not.have.property('thumbnail_width')
124 expect(res.body).to.not.have.property('thumbnail_height')
127 after(async function () {
128 await cleanupTests([ server ])