]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/services.ts
Merge branch 'release/4.0.0' into develop
[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 'mocha'
4 import * as chai from 'chai'
5 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils'
6 import { Video, VideoPlaylistPrivacy } from '@shared/models'
7
8 const expect = chai.expect
9
10 describe('Test services', function () {
11 let server: PeerTubeServer = null
12 let playlistUUID: string
13 let playlistDisplayName: string
14 let video: Video
15
16 before(async function () {
17 this.timeout(30000)
18
19 server = await createSingleServer(1)
20
21 await setAccessTokensToServers([ server ])
22 await setDefaultVideoChannel([ server ])
23
24 {
25 const attributes = { name: 'my super name' }
26 await server.videos.upload({ attributes })
27
28 const { data } = await server.videos.list()
29 video = data[0]
30 }
31
32 {
33 const created = await server.playlists.create({
34 attributes: {
35 displayName: 'The Life and Times of Scrooge McDuck',
36 privacy: VideoPlaylistPrivacy.PUBLIC,
37 videoChannelId: server.store.channel.id
38 }
39 })
40
41 playlistUUID = created.uuid
42 playlistDisplayName = 'The Life and Times of Scrooge McDuck'
43
44 await server.playlists.addElement({
45 playlistId: created.id,
46 attributes: {
47 videoId: video.id
48 }
49 })
50 }
51 })
52
53 it('Should have a valid oEmbed video response', async function () {
54 for (const basePath of [ '/videos/watch/', '/w/' ]) {
55 for (const suffix of [ '', '?param=1' ]) {
56 const oembedUrl = server.url + basePath + video.uuid + suffix
57
58 const res = await server.services.getOEmbed({ oembedUrl })
59 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' +
60 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
61 'frameborder="0" allowfullscreen></iframe>'
62 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath
63
64 expect(res.body.html).to.equal(expectedHtml)
65 expect(res.body.title).to.equal(video.name)
66 expect(res.body.author_name).to.equal(server.store.channel.displayName)
67 expect(res.body.width).to.equal(560)
68 expect(res.body.height).to.equal(315)
69 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
70 expect(res.body.thumbnail_width).to.equal(850)
71 expect(res.body.thumbnail_height).to.equal(480)
72 }
73 }
74 })
75
76 it('Should have a valid playlist oEmbed response', async function () {
77 for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) {
78 for (const suffix of [ '', '?param=1' ]) {
79 const oembedUrl = server.url + basePath + playlistUUID + suffix
80
81 const res = await server.services.getOEmbed({ oembedUrl })
82 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' +
83 `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
84 'frameborder="0" allowfullscreen></iframe>'
85
86 expect(res.body.html).to.equal(expectedHtml)
87 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
88 expect(res.body.author_name).to.equal(server.store.channel.displayName)
89 expect(res.body.width).to.equal(560)
90 expect(res.body.height).to.equal(315)
91 expect(res.body.thumbnail_url).exist
92 expect(res.body.thumbnail_width).to.equal(280)
93 expect(res.body.thumbnail_height).to.equal(157)
94 }
95 }
96 })
97
98 it('Should have a valid oEmbed response with small max height query', async function () {
99 for (const basePath of [ '/videos/watch/', '/w/' ]) {
100 const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid
101 const format = 'json'
102 const maxHeight = 50
103 const maxWidth = 50
104
105 const res = await server.services.getOEmbed({ oembedUrl, format, maxHeight, maxWidth })
106 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts allow-popups" ' +
107 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
108 'frameborder="0" allowfullscreen></iframe>'
109
110 expect(res.body.html).to.equal(expectedHtml)
111 expect(res.body.title).to.equal(video.name)
112 expect(res.body.author_name).to.equal(server.store.channel.displayName)
113 expect(res.body.height).to.equal(50)
114 expect(res.body.width).to.equal(50)
115 expect(res.body).to.not.have.property('thumbnail_url')
116 expect(res.body).to.not.have.property('thumbnail_width')
117 expect(res.body).to.not.have.property('thumbnail_height')
118 }
119 })
120
121 after(async function () {
122 await cleanupTests([ server ])
123 })
124 })