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