]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/services.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / services.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
d8755eed 2
8b0d42ee 3import 'mocha'
6fad8e51 4import * as chai from 'chai'
6302d599 5import { Video, VideoPlaylistPrivacy } from '@shared/models'
6fad8e51 6import {
6302d599
C
7 addVideoInPlaylist,
8 createVideoPlaylist,
6fad8e51
C
9 getOEmbed,
10 getVideosList,
11 ServerInfo,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
6302d599 14 uploadVideo
6fad8e51 15} from '../../../../shared/extra-utils'
7c3b7976 16import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
d8755eed 17
8b0d42ee
C
18const expect = chai.expect
19
d8755eed
C
20describe('Test services', function () {
21 let server: ServerInfo = null
6fad8e51 22 let playlistUUID: string
4097c6d6 23 let playlistDisplayName: string
6302d599 24 let video: Video
d8755eed
C
25
26 before(async function () {
e212f887 27 this.timeout(30000)
d8755eed 28
210feb6c 29 server = await flushAndRunServer(1)
d8755eed
C
30
31 await setAccessTokensToServers([ server ])
6fad8e51 32 await setDefaultVideoChannel([ server ])
d8755eed 33
6fad8e51
C
34 {
35 const videoAttributes = {
36 name: 'my super name'
37 }
38 await uploadVideo(server.url, server.accessToken, videoAttributes)
39
40 const res = await getVideosList(server.url)
6302d599 41 video = res.body.data[0]
d8755eed 42 }
8b0d42ee 43
6fad8e51
C
44 {
45 const res = await createVideoPlaylist({
46 url: server.url,
47 token: server.accessToken,
48 playlistAttrs: {
49 displayName: 'The Life and Times of Scrooge McDuck',
50 privacy: VideoPlaylistPrivacy.PUBLIC,
51 videoChannelId: server.videoChannel.id
52 }
53 })
54
55 playlistUUID = res.body.videoPlaylist.uuid
4097c6d6 56 playlistDisplayName = 'The Life and Times of Scrooge McDuck'
6fad8e51
C
57
58 await addVideoInPlaylist({
59 url: server.url,
60 token: server.accessToken,
61 playlistId: res.body.videoPlaylist.id,
62 elementAttrs: {
6302d599 63 videoId: video.id
6fad8e51
C
64 }
65 })
66 }
d8755eed
C
67 })
68
6fad8e51 69 it('Should have a valid oEmbed video response', async function () {
6302d599 70 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid
d8755eed
C
71
72 const res = await getOEmbed(server.url, oembedUrl)
2186386c 73 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
4097c6d6 74 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
a1587156 75 'frameborder="0" allowfullscreen></iframe>'
6302d599 76 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath
d8755eed
C
77
78 expect(res.body.html).to.equal(expectedHtml)
6302d599 79 expect(res.body.title).to.equal(video.name)
6fad8e51 80 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
d8755eed 81 expect(res.body.width).to.equal(560)
164174a6 82 expect(res.body.height).to.equal(315)
d8755eed 83 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
80b8ad2a
C
84 expect(res.body.thumbnail_width).to.equal(850)
85 expect(res.body.thumbnail_height).to.equal(480)
d8755eed
C
86 })
87
6fad8e51
C
88 it('Should have a valid playlist oEmbed response', async function () {
89 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/playlist/' + playlistUUID
90
91 const res = await getOEmbed(server.url, oembedUrl)
92 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
4097c6d6 93 `title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
6fad8e51
C
94 'frameborder="0" allowfullscreen></iframe>'
95
96 expect(res.body.html).to.equal(expectedHtml)
97 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
98 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
99 expect(res.body.width).to.equal(560)
100 expect(res.body.height).to.equal(315)
101 expect(res.body.thumbnail_url).exist
1bbc0270
C
102 expect(res.body.thumbnail_width).to.equal(280)
103 expect(res.body.thumbnail_height).to.equal(157)
6fad8e51
C
104 })
105
d8755eed 106 it('Should have a valid oEmbed response with small max height query', async function () {
6302d599 107 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid
d8755eed
C
108 const format = 'json'
109 const maxHeight = 50
110 const maxWidth = 50
111
112 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
3cd0734f 113 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
4097c6d6 114 `title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
a1587156 115 'frameborder="0" allowfullscreen></iframe>'
d8755eed
C
116
117 expect(res.body.html).to.equal(expectedHtml)
6302d599 118 expect(res.body.title).to.equal(video.name)
6fad8e51 119 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
d8755eed
C
120 expect(res.body.height).to.equal(50)
121 expect(res.body.width).to.equal(50)
122 expect(res.body).to.not.have.property('thumbnail_url')
123 expect(res.body).to.not.have.property('thumbnail_width')
124 expect(res.body).to.not.have.property('thumbnail_height')
125 })
126
7c3b7976
C
127 after(async function () {
128 await cleanupTests([ server ])
d8755eed
C
129 })
130})