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