1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands'
5 import { Video, VideoPlaylistPrivacy } from '@shared/models'
7 const expect = chai.expect
9 describe('Test services', function () {
10 let server: PeerTubeServer = null
11 let playlistUUID: string
12 let playlistDisplayName: string
25 input: '?muted=1&warningTitle=0&toto=1',
26 output: '?muted=1&warningTitle=0'
30 before(async function () {
33 server = await createSingleServer(1)
35 await setAccessTokensToServers([ server ])
36 await setDefaultVideoChannel([ server ])
39 const attributes = { name: 'my super name' }
40 await server.videos.upload({ attributes })
42 const { data } = await server.videos.list()
47 const created = await server.playlists.create({
49 displayName: 'The Life and Times of Scrooge McDuck',
50 privacy: VideoPlaylistPrivacy.PUBLIC,
51 videoChannelId: server.store.channel.id
55 playlistUUID = created.uuid
56 playlistDisplayName = 'The Life and Times of Scrooge McDuck'
58 await server.playlists.addElement({
59 playlistId: created.id,
67 it('Should have a valid oEmbed video response', async function () {
68 for (const basePath of [ '/videos/watch/', '/w/' ]) {
69 for (const suffix of urlSuffixes) {
70 const oembedUrl = server.url + basePath + video.uuid + suffix.input
72 const res = await server.services.getOEmbed({ oembedUrl })
73 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' +
74 `title="${video.name}" src="http://${server.host}/videos/embed/${video.uuid}${suffix.output}" ` +
75 'frameborder="0" allowfullscreen></iframe>'
77 const expectedThumbnailUrl = 'http://' + server.host + video.previewPath
79 expect(res.body.html).to.equal(expectedHtml)
80 expect(res.body.title).to.equal(video.name)
81 expect(res.body.author_name).to.equal(server.store.channel.displayName)
82 expect(res.body.width).to.equal(560)
83 expect(res.body.height).to.equal(315)
84 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
85 expect(res.body.thumbnail_width).to.equal(850)
86 expect(res.body.thumbnail_height).to.equal(480)
91 it('Should have a valid playlist oEmbed response', async function () {
92 for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) {
93 for (const suffix of urlSuffixes) {
94 const oembedUrl = server.url + basePath + playlistUUID + suffix.input
96 const res = await server.services.getOEmbed({ oembedUrl })
97 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' +
98 `title="${playlistDisplayName}" src="http://${server.host}/video-playlists/embed/${playlistUUID}${suffix.output}" ` +
99 'frameborder="0" allowfullscreen></iframe>'
101 expect(res.body.html).to.equal(expectedHtml)
102 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
103 expect(res.body.author_name).to.equal(server.store.channel.displayName)
104 expect(res.body.width).to.equal(560)
105 expect(res.body.height).to.equal(315)
106 expect(res.body.thumbnail_url).exist
107 expect(res.body.thumbnail_width).to.equal(280)
108 expect(res.body.thumbnail_height).to.equal(157)
113 it('Should have a valid oEmbed response with small max height query', async function () {
114 for (const basePath of [ '/videos/watch/', '/w/' ]) {
115 const oembedUrl = 'http://' + server.host + basePath + video.uuid
116 const format = 'json'
120 const res = await server.services.getOEmbed({ oembedUrl, format, maxHeight, maxWidth })
121 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts allow-popups" ' +
122 `title="${video.name}" src="http://${server.host}/videos/embed/${video.uuid}" ` +
123 'frameborder="0" allowfullscreen></iframe>'
125 expect(res.body.html).to.equal(expectedHtml)
126 expect(res.body.title).to.equal(video.name)
127 expect(res.body.author_name).to.equal(server.store.channel.displayName)
128 expect(res.body.height).to.equal(50)
129 expect(res.body.width).to.equal(50)
130 expect(res.body).to.not.have.property('thumbnail_url')
131 expect(res.body).to.not.have.property('thumbnail_width')
132 expect(res.body).to.not.have.property('thumbnail_height')
136 after(async function () {
137 await cleanupTests([ server ])