]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/services.ts
Handle playlist oembed
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / services.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 getOEmbed,
7 getVideosList,
8 ServerInfo,
9 setAccessTokensToServers,
10 setDefaultVideoChannel,
11 uploadVideo,
12 createVideoPlaylist,
13 addVideoInPlaylist
14 } from '../../../../shared/extra-utils'
15 import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
16 import { VideoPlaylistPrivacy } from '@shared/models'
17
18 const expect = chai.expect
19
20 describe('Test services', function () {
21 let server: ServerInfo = null
22 let playlistUUID: string
23
24 before(async function () {
25 this.timeout(30000)
26
27 server = await flushAndRunServer(1)
28
29 await setAccessTokensToServers([ server ])
30 await setDefaultVideoChannel([ server ])
31
32 {
33 const videoAttributes = {
34 name: 'my super name'
35 }
36 await uploadVideo(server.url, server.accessToken, videoAttributes)
37
38 const res = await getVideosList(server.url)
39 server.video = res.body.data[0]
40 }
41
42 {
43 const res = await createVideoPlaylist({
44 url: server.url,
45 token: server.accessToken,
46 playlistAttrs: {
47 displayName: 'The Life and Times of Scrooge McDuck',
48 privacy: VideoPlaylistPrivacy.PUBLIC,
49 videoChannelId: server.videoChannel.id
50 }
51 })
52
53 playlistUUID = res.body.videoPlaylist.uuid
54
55 await addVideoInPlaylist({
56 url: server.url,
57 token: server.accessToken,
58 playlistId: res.body.videoPlaylist.id,
59 elementAttrs: {
60 videoId: server.video.id
61 }
62 })
63 }
64 })
65
66 it('Should have a valid oEmbed video response', async function () {
67 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid
68
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 + '/static/previews/' + server.video.uuid + '.jpg'
74
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)
83 })
84
85 it('Should have a valid playlist oEmbed response', async function () {
86 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/playlist/' + playlistUUID
87
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>'
92
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)
101 })
102
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'
106 const maxHeight = 50
107 const maxWidth = 50
108
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>'
113
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')
122 })
123
124 after(async function () {
125 await cleanupTests([ server ])
126 })
127 })