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