1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils'
6 import { Video, VideoPlaylistPrivacy } from '@shared/models'
8 const expect = chai.expect
10 describe('Test services', function () {
11 let server: ServerInfo = null
12 let playlistUUID: string
13 let playlistDisplayName: string
16 before(async function () {
19 server = await flushAndRunServer(1)
21 await setAccessTokensToServers([ server ])
22 await setDefaultVideoChannel([ server ])
25 const attributes = { name: 'my super name' }
26 await server.videosCommand.upload({ attributes })
28 const { data } = await server.videosCommand.list()
33 const created = await server.playlistsCommand.create({
35 displayName: 'The Life and Times of Scrooge McDuck',
36 privacy: VideoPlaylistPrivacy.PUBLIC,
37 videoChannelId: server.videoChannel.id
41 playlistUUID = created.uuid
42 playlistDisplayName = 'The Life and Times of Scrooge McDuck'
44 await server.playlistsCommand.addElement({
45 playlistId: created.id,
53 it('Should have a valid oEmbed video response', async function () {
54 for (const basePath of [ '/videos/watch/', '/w/' ]) {
55 const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid
57 const res = await server.servicesCommand.getOEmbed({ oembedUrl })
58 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
59 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
60 'frameborder="0" allowfullscreen></iframe>'
61 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath
63 expect(res.body.html).to.equal(expectedHtml)
64 expect(res.body.title).to.equal(video.name)
65 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
66 expect(res.body.width).to.equal(560)
67 expect(res.body.height).to.equal(315)
68 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
69 expect(res.body.thumbnail_width).to.equal(850)
70 expect(res.body.thumbnail_height).to.equal(480)
74 it('Should have a valid playlist oEmbed response', async function () {
75 for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) {
76 const oembedUrl = 'http://localhost:' + server.port + basePath + playlistUUID
78 const res = await server.servicesCommand.getOEmbed({ oembedUrl })
79 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
80 `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
81 'frameborder="0" allowfullscreen></iframe>'
83 expect(res.body.html).to.equal(expectedHtml)
84 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
85 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
86 expect(res.body.width).to.equal(560)
87 expect(res.body.height).to.equal(315)
88 expect(res.body.thumbnail_url).exist
89 expect(res.body.thumbnail_width).to.equal(280)
90 expect(res.body.thumbnail_height).to.equal(157)
94 it('Should have a valid oEmbed response with small max height query', async function () {
95 for (const basePath of [ '/videos/watch/', '/w/' ]) {
96 const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid
101 const res = await server.servicesCommand.getOEmbed({ oembedUrl, format, maxHeight, maxWidth })
102 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
103 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
104 'frameborder="0" allowfullscreen></iframe>'
106 expect(res.body.html).to.equal(expectedHtml)
107 expect(res.body.title).to.equal(video.name)
108 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
109 expect(res.body.height).to.equal(50)
110 expect(res.body.width).to.equal(50)
111 expect(res.body).to.not.have.property('thumbnail_url')
112 expect(res.body).to.not.have.property('thumbnail_width')
113 expect(res.body).to.not.have.property('thumbnail_height')
117 after(async function () {
118 await cleanupTests([ server ])