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