1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 setAccessTokensToServers,
10 setDefaultVideoChannel,
14 } from '../../../../shared/extra-utils'
15 import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
16 import { VideoPlaylistPrivacy } from '@shared/models'
18 const expect = chai.expect
20 describe('Test services', function () {
21 let server: ServerInfo = null
22 let playlistUUID: string
24 before(async function () {
27 server = await flushAndRunServer(1)
29 await setAccessTokensToServers([ server ])
30 await setDefaultVideoChannel([ server ])
33 const videoAttributes = {
36 await uploadVideo(server.url, server.accessToken, videoAttributes)
38 const res = await getVideosList(server.url)
39 server.video = res.body.data[0]
43 const res = await createVideoPlaylist({
45 token: server.accessToken,
47 displayName: 'The Life and Times of Scrooge McDuck',
48 privacy: VideoPlaylistPrivacy.PUBLIC,
49 videoChannelId: server.videoChannel.id
53 playlistUUID = res.body.videoPlaylist.uuid
55 await addVideoInPlaylist({
57 token: server.accessToken,
58 playlistId: res.body.videoPlaylist.id,
60 videoId: server.video.id
66 it('Should have a valid oEmbed video response', async function () {
67 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid
69 const res = await getOEmbed(server.url, oembedUrl)
70 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
71 `src="http://localhost:${server.port}/videos/embed/${server.video.uuid}" ` +
72 'frameborder="0" allowfullscreen></iframe>'
73 const expectedThumbnailUrl = 'http://localhost:' + server.port + '/lazy-static/previews/' + server.video.uuid + '.jpg'
75 expect(res.body.html).to.equal(expectedHtml)
76 expect(res.body.title).to.equal(server.video.name)
77 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
78 expect(res.body.width).to.equal(560)
79 expect(res.body.height).to.equal(315)
80 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
81 expect(res.body.thumbnail_width).to.equal(850)
82 expect(res.body.thumbnail_height).to.equal(480)
85 it('Should have a valid playlist oEmbed response', async function () {
86 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/playlist/' + playlistUUID
88 const res = await getOEmbed(server.url, oembedUrl)
89 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
90 `src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
91 'frameborder="0" allowfullscreen></iframe>'
93 expect(res.body.html).to.equal(expectedHtml)
94 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
95 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
96 expect(res.body.width).to.equal(560)
97 expect(res.body.height).to.equal(315)
98 expect(res.body.thumbnail_url).exist
99 expect(res.body.thumbnail_width).to.equal(223)
100 expect(res.body.thumbnail_height).to.equal(122)
103 it('Should have a valid oEmbed response with small max height query', async function () {
104 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid
105 const format = 'json'
109 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
110 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
111 `src="http://localhost:${server.port}/videos/embed/${server.video.uuid}" ` +
112 'frameborder="0" allowfullscreen></iframe>'
114 expect(res.body.html).to.equal(expectedHtml)
115 expect(res.body.title).to.equal(server.video.name)
116 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
117 expect(res.body.height).to.equal(50)
118 expect(res.body.width).to.equal(50)
119 expect(res.body).to.not.have.property('thumbnail_url')
120 expect(res.body).to.not.have.property('thumbnail_width')
121 expect(res.body).to.not.have.property('thumbnail_height')
124 after(async function () {
125 await cleanupTests([ server ])