]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/services.ts
We don't need to import mocha
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / services.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands'
5 import { Video, VideoPlaylistPrivacy } from '@shared/models'
6
7 const expect = chai.expect
8
9 describe('Test services', function () {
10 let server: PeerTubeServer = null
11 let playlistUUID: string
12 let playlistDisplayName: string
13 let video: Video
14
15 const urlSuffixes = [
16 {
17 input: '',
18 output: ''
19 },
20 {
21 input: '?param=1',
22 output: ''
23 },
24 {
25 input: '?muted=1&warningTitle=0&toto=1',
26 output: '?muted=1&warningTitle=0'
27 }
28 ]
29
30 before(async function () {
31 this.timeout(30000)
32
33 server = await createSingleServer(1)
34
35 await setAccessTokensToServers([ server ])
36 await setDefaultVideoChannel([ server ])
37
38 {
39 const attributes = { name: 'my super name' }
40 await server.videos.upload({ attributes })
41
42 const { data } = await server.videos.list()
43 video = data[0]
44 }
45
46 {
47 const created = await server.playlists.create({
48 attributes: {
49 displayName: 'The Life and Times of Scrooge McDuck',
50 privacy: VideoPlaylistPrivacy.PUBLIC,
51 videoChannelId: server.store.channel.id
52 }
53 })
54
55 playlistUUID = created.uuid
56 playlistDisplayName = 'The Life and Times of Scrooge McDuck'
57
58 await server.playlists.addElement({
59 playlistId: created.id,
60 attributes: {
61 videoId: video.id
62 }
63 })
64 }
65 })
66
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
71
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>'
76
77 const expectedThumbnailUrl = 'http://' + server.host + video.previewPath
78
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)
87 }
88 }
89 })
90
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
95
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>'
100
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)
109 }
110 }
111 })
112
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'
117 const maxHeight = 50
118 const maxWidth = 50
119
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>'
124
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')
133 }
134 })
135
136 after(async function () {
137 await cleanupTests([ server ])
138 })
139 })