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