]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/client.ts
Add fcbk open-graph and twitter-card metas for accounts, video-channels, playlists...
[github/Chocobozzz/PeerTube.git] / server / tests / client.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
0e1dc3e7
C
2
3import 'mocha'
4import * as chai from 'chai'
5import * as request from 'supertest'
0e1dc3e7 6import {
7c3b7976
C
7 cleanupTests,
8 flushAndRunServer,
590fb506
C
9 getCustomConfig,
10 getVideosList,
590fb506 11 makeHTMLRequest,
590fb506 12 ServerInfo,
eec63bbc 13 serverLogin,
590fb506
C
14 updateCustomConfig,
15 updateCustomSubConfig,
8d987ec6
K
16 uploadVideo,
17 createVideoPlaylist,
18 addVideoInPlaylist,
19 getAccount,
20 addVideoChannel
94565d52 21} from '../../shared/extra-utils'
8d987ec6
K
22import { VideoPlaylistPrivacy } from '@shared/models'
23import { MVideoPlaylist, MAccount, MChannel } from '@server/types/models'
590fb506
C
24
25const expect = chai.expect
5bcfd029
C
26
27function checkIndexTags (html: string, title: string, description: string, css: string) {
28 expect(html).to.contain('<title>' + title + '</title>')
29 expect(html).to.contain('<meta name="description" content="' + description + '" />')
30 expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
31}
0e1dc3e7
C
32
33describe('Test a client controllers', function () {
34 let server: ServerInfo
8d987ec6
K
35 let videoPlaylist: MVideoPlaylist
36 let account: MAccount
37 let videoChannel: MChannel
38 const name = 'my super name for server 1'
39 const description = 'my super description for server 1'
0e1dc3e7
C
40
41 before(async function () {
42 this.timeout(120000)
43
210feb6c 44 server = await flushAndRunServer(1)
eec63bbc 45 server.accessToken = await serverLogin(server)
0e1dc3e7 46
8d987ec6
K
47 // Video
48
49 const videoAttributes = { name, description }
50
0e1dc3e7
C
51 await uploadVideo(server.url, server.accessToken, videoAttributes)
52
8d987ec6
K
53 const resVideosRequest = await getVideosList(server.url)
54
55 const videos = resVideosRequest.body.data
0e1dc3e7
C
56
57 expect(videos.length).to.equal(1)
58
59 server.video = videos[0]
8d987ec6
K
60
61 // Playlist
62
63 const playlistAttrs = {
64 displayName: name,
65 description,
66 privacy: VideoPlaylistPrivacy.PUBLIC
67 }
68
69 const resVideoPlaylistRequest = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs })
70
71 videoPlaylist = resVideoPlaylistRequest.body.videoPlaylist
72
73 await addVideoInPlaylist({
74 url: server.url,
75 token: server.accessToken,
76 playlistId: videoPlaylist.id,
77 elementAttrs: { videoId: server.video.id }
78 })
79
80 // Account
81
82 const resAccountRequest = await getAccount(server.url, `${server.user.username}@${server.host}:${server.port}`)
83
84 account = resAccountRequest.body.account
85
86 // Channel
87
88 const videoChannelAttributesArg = {
89 name: `${server.user.username}_channel`,
90 displayName: name,
91 description
92 }
93
94 const resChannelRequest = await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
95
96 videoChannel = resChannelRequest.body.videoChannel
0e1dc3e7
C
97 })
98
d8755eed 99 it('Should have valid Open Graph tags on the watch page with video id', async function () {
0e1dc3e7 100 const res = await request(server.url)
98ec8b8e
C
101 .get('/videos/watch/' + server.video.id)
102 .set('Accept', 'text/html')
103 .expect(200)
0e1dc3e7 104
8d987ec6
K
105 expect(res.text).to.contain(`<meta property="og:title" content="${name}" />`)
106 expect(res.text).to.contain(`<meta property="og:description" content="${description}" />`)
107 expect(res.text).to.contain('<meta property="og:type" content="video" />')
108 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/${server.video.uuid}" />`)
0e1dc3e7
C
109 })
110
d8755eed 111 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
0e1dc3e7 112 const res = await request(server.url)
98ec8b8e
C
113 .get('/videos/watch/' + server.video.uuid)
114 .set('Accept', 'text/html')
115 .expect(200)
0e1dc3e7 116
8d987ec6
K
117 expect(res.text).to.contain(`<meta property="og:title" content="${name}" />`)
118 expect(res.text).to.contain(`<meta property="og:description" content="${description}" />`)
119 expect(res.text).to.contain('<meta property="og:type" content="video" />')
120 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/${server.video.uuid}" />`)
121 })
122
123 it('Should have valid Open Graph tags on the watch playlist page', async function () {
124 const res = await request(server.url)
125 .get('/videos/watch/playlist/' + videoPlaylist.uuid)
126 .set('Accept', 'text/html')
127 .expect(200)
128
129 expect(res.text).to.contain(`<meta property="og:title" content="${videoPlaylist.name}" />`)
130 expect(res.text).to.contain(`<meta property="og:description" content="${videoPlaylist.description}" />`)
131 expect(res.text).to.contain('<meta property="og:type" content="video" />')
132 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/playlist/${videoPlaylist.uuid}" />`)
133 })
134
135 it('Should have valid Open Graph tags on the account page', async function () {
136 const res = await request(server.url)
137 .get('/accounts/' + server.user.username)
138 .set('Accept', 'text/html')
139 .expect(200)
140
141 expect(res.text).to.contain(`<meta property="og:title" content="${account.getDisplayName()}" />`)
142 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
143 expect(res.text).to.contain('<meta property="og:type" content="website" />')
144 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/accounts/${server.user.username}" />`)
145 })
146
147 it('Should have valid Open Graph tags on the channel page', async function () {
148 const res = await request(server.url)
149 .get('/video-channels/' + videoChannel.name)
150 .set('Accept', 'text/html')
151 .expect(200)
152
153 expect(res.text).to.contain(`<meta property="og:title" content="${videoChannel.getDisplayName()}" />`)
154 expect(res.text).to.contain(`<meta property="og:description" content="${videoChannel.description}" />`)
155 expect(res.text).to.contain('<meta property="og:type" content="website" />')
156 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/video-channels/${videoChannel.name}" />`)
0e1dc3e7
C
157 })
158
d8755eed
C
159 it('Should have valid oEmbed discovery tags', async function () {
160 const path = '/videos/watch/' + server.video.uuid
161 const res = await request(server.url)
162 .get(path)
98ec8b8e 163 .set('Accept', 'text/html')
d8755eed
C
164 .expect(200)
165
166 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:9001/services/oembed?' +
167 `url=http%3A%2F%2Flocalhost%3A9001%2Fvideos%2Fwatch%2F${server.video.uuid}" ` +
168 `title="${server.video.name}" />`
169
170 expect(res.text).to.contain(expectedLink)
171 })
172
8d987ec6 173 it('Should have valid twitter card on the whatch video page', async function () {
8be1afa1
C
174 const res = await request(server.url)
175 .get('/videos/watch/' + server.video.uuid)
176 .set('Accept', 'text/html')
177 .expect(200)
178
179 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
180 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
8d987ec6
K
181 expect(res.text).to.contain(`<meta property="twitter:title" content="${name}" />`)
182 expect(res.text).to.contain(`<meta property="twitter:description" content="${description}" />`)
183 })
184
185 it('Should have valid twitter card on the watch playlist page', async function () {
186 const res = await request(server.url)
187 .get('/videos/watch/playlist/' + videoPlaylist.uuid)
188 .set('Accept', 'text/html')
189 .expect(200)
190
191 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
192 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
193 expect(res.text).to.contain(`<meta property="twitter:title" content="${videoPlaylist.name}" />`)
194 expect(res.text).to.contain(`<meta property="twitter:description" content="${videoPlaylist.description}" />`)
195 })
196
197 it('Should have valid twitter card on the account page', async function () {
198 const res = await request(server.url)
199 .get('/accounts/' + account.name)
200 .set('Accept', 'text/html')
201 .expect(200)
202
203 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
204 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
205 expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`)
206 expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`)
207 })
208
209 it('Should have valid twitter card on the channel page', async function () {
210 const res = await request(server.url)
211 .get('/video-channels/' + videoChannel.name)
212 .set('Accept', 'text/html')
213 .expect(200)
214
215 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
216 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
217 expect(res.text).to.contain(`<meta property="twitter:title" content="${videoChannel.name}" />`)
218 expect(res.text).to.contain(`<meta property="twitter:description" content="${videoChannel.description}" />`)
8be1afa1
C
219 })
220
221 it('Should have valid twitter card if Twitter is whitelisted', async function () {
222 const res1 = await getCustomConfig(server.url, server.accessToken)
223 const config = res1.body
224 config.services.twitter = {
225 username: '@Kuja',
226 whitelisted: true
227 }
228 await updateCustomConfig(server.url, server.accessToken, config)
229
8d987ec6 230 const resVideoRequest = await request(server.url)
8be1afa1
C
231 .get('/videos/watch/' + server.video.uuid)
232 .set('Accept', 'text/html')
233 .expect(200)
234
8d987ec6
K
235 expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />')
236 expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
237
238 const resVideoPlaylistRequest = await request(server.url)
239 .get('/videos/watch/playlist/' + videoPlaylist.uuid)
240 .set('Accept', 'text/html')
241 .expect(200)
242
243 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />')
244 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
245
246 const resAccountRequest = await request(server.url)
247 .get('/accounts/' + account.name)
248 .set('Accept', 'text/html')
249 .expect(200)
250
251 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="player" />')
252 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
253
254 const resChannelRequest = await request(server.url)
255 .get('/video-channels/' + videoChannel.name)
256 .set('Accept', 'text/html')
257 .expect(200)
258
259 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="player" />')
260 expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
8be1afa1
C
261 })
262
5bcfd029
C
263 it('Should have valid index html tags (title, description...)', async function () {
264 const res = await makeHTMLRequest(server.url, '/videos/trending')
265
482fa503 266 const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
5bcfd029
C
267 checkIndexTags(res.text, 'PeerTube', description, '')
268 })
269
270 it('Should update the customized configuration and have the correct index html tags', async function () {
590fb506 271 await updateCustomSubConfig(server.url, server.accessToken, {
5bcfd029 272 instance: {
60979b07
C
273 name: 'PeerTube updated',
274 shortDescription: 'my short description',
275 description: 'my super description',
276 terms: 'my super terms',
277 defaultClientRoute: '/videos/recently-added',
278 defaultNSFWPolicy: 'blur',
5bcfd029
C
279 customizations: {
280 javascript: 'alert("coucou")',
281 css: 'body { background-color: red; }'
282 }
5bcfd029 283 }
590fb506 284 })
5bcfd029
C
285
286 const res = await makeHTMLRequest(server.url, '/videos/trending')
287
288 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
289 })
290
291 it('Should have valid index html updated tags (title, description...)', async function () {
292 const res = await makeHTMLRequest(server.url, '/videos/trending')
293
294 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
295 })
296
7c3b7976
C
297 after(async function () {
298 await cleanupTests([ server ])
0e1dc3e7
C
299 })
300})