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'
9 setAccessTokensToServers,
10 setDefaultVideoChannel,
12 } from '../../../../shared/extra-utils'
13 import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
15 const expect = chai.expect
17 describe('Test services', function () {
18 let server: ServerInfo = null
19 let playlistUUID: string
20 let playlistDisplayName: string
23 before(async function () {
26 server = await flushAndRunServer(1)
28 await setAccessTokensToServers([ server ])
29 await setDefaultVideoChannel([ server ])
32 const videoAttributes = {
35 await uploadVideo(server.url, server.accessToken, videoAttributes)
37 const res = await getVideosList(server.url)
38 video = res.body.data[0]
42 const created = await server.playlistsCommand.create({
44 displayName: 'The Life and Times of Scrooge McDuck',
45 privacy: VideoPlaylistPrivacy.PUBLIC,
46 videoChannelId: server.videoChannel.id
50 playlistUUID = created.uuid
51 playlistDisplayName = 'The Life and Times of Scrooge McDuck'
53 await server.playlistsCommand.addElement({
54 playlistId: created.id,
62 it('Should have a valid oEmbed video response', async function () {
63 for (const basePath of [ '/videos/watch/', '/w/' ]) {
64 const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid
66 const res = await server.servicesCommand.getOEmbed({ oembedUrl })
67 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
68 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
69 'frameborder="0" allowfullscreen></iframe>'
70 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath
72 expect(res.body.html).to.equal(expectedHtml)
73 expect(res.body.title).to.equal(video.name)
74 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
75 expect(res.body.width).to.equal(560)
76 expect(res.body.height).to.equal(315)
77 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
78 expect(res.body.thumbnail_width).to.equal(850)
79 expect(res.body.thumbnail_height).to.equal(480)
83 it('Should have a valid playlist oEmbed response', async function () {
84 for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) {
85 const oembedUrl = 'http://localhost:' + server.port + basePath + playlistUUID
87 const res = await server.servicesCommand.getOEmbed({ oembedUrl })
88 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
89 `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
90 'frameborder="0" allowfullscreen></iframe>'
92 expect(res.body.html).to.equal(expectedHtml)
93 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
94 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
95 expect(res.body.width).to.equal(560)
96 expect(res.body.height).to.equal(315)
97 expect(res.body.thumbnail_url).exist
98 expect(res.body.thumbnail_width).to.equal(280)
99 expect(res.body.thumbnail_height).to.equal(157)
103 it('Should have a valid oEmbed response with small max height query', async function () {
104 for (const basePath of [ '/videos/watch/', '/w/' ]) {
105 const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid
106 const format = 'json'
110 const res = await server.servicesCommand.getOEmbed({ oembedUrl, format, maxHeight, maxWidth })
111 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
112 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
113 'frameborder="0" allowfullscreen></iframe>'
115 expect(res.body.html).to.equal(expectedHtml)
116 expect(res.body.title).to.equal(video.name)
117 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
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')
126 after(async function () {
127 await cleanupTests([ server ])