]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/client.ts
Fix lint
[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'
39433fa5 6import { Account, VideoPlaylistPrivacy } from '@shared/models'
0e1dc3e7 7import {
39433fa5 8 addVideoInPlaylist,
7c3b7976 9 cleanupTests,
39433fa5 10 createVideoPlaylist,
7c3b7976 11 flushAndRunServer,
39433fa5 12 getAccount,
590fb506
C
13 getCustomConfig,
14 getVideosList,
590fb506 15 makeHTMLRequest,
590fb506 16 ServerInfo,
eec63bbc 17 serverLogin,
39433fa5 18 setDefaultVideoChannel,
590fb506
C
19 updateCustomConfig,
20 updateCustomSubConfig,
8d987ec6 21 uploadVideo,
39433fa5
C
22 updateMyUser,
23 updateVideoChannel
94565d52 24} from '../../shared/extra-utils'
590fb506
C
25
26const expect = chai.expect
5bcfd029
C
27
28function checkIndexTags (html: string, title: string, description: string, css: string) {
29 expect(html).to.contain('<title>' + title + '</title>')
30 expect(html).to.contain('<meta name="description" content="' + description + '" />')
31 expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
32}
0e1dc3e7
C
33
34describe('Test a client controllers', function () {
35 let server: ServerInfo
39433fa5
C
36 let account: Account
37
38 const videoName = 'my super name for server 1'
39 const videoDescription = 'my super description for server 1'
40
41 const playlistName = 'super playlist name'
42 const playlistDescription = 'super playlist description'
43 let playlistUUID: string
44
45 const channelDescription = 'my super channel description'
0e1dc3e7
C
46
47 before(async function () {
48 this.timeout(120000)
49
210feb6c 50 server = await flushAndRunServer(1)
eec63bbc 51 server.accessToken = await serverLogin(server)
39433fa5 52 await setDefaultVideoChannel([ server ])
0e1dc3e7 53
39433fa5 54 await updateVideoChannel(server.url, server.accessToken, server.videoChannel.name, { description: channelDescription })
8d987ec6 55
39433fa5 56 // Video
8d987ec6 57
39433fa5 58 const videoAttributes = { name: videoName, description: videoDescription }
0e1dc3e7
C
59 await uploadVideo(server.url, server.accessToken, videoAttributes)
60
8d987ec6 61 const resVideosRequest = await getVideosList(server.url)
8d987ec6 62 const videos = resVideosRequest.body.data
0e1dc3e7
C
63 expect(videos.length).to.equal(1)
64
65 server.video = videos[0]
8d987ec6
K
66
67 // Playlist
68
69 const playlistAttrs = {
39433fa5
C
70 displayName: playlistName,
71 description: playlistDescription,
72 privacy: VideoPlaylistPrivacy.PUBLIC,
73 videoChannelId: server.videoChannel.id
8d987ec6
K
74 }
75
76 const resVideoPlaylistRequest = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs })
77
39433fa5
C
78 const playlist = resVideoPlaylistRequest.body.videoPlaylist
79 const playlistId = playlist.id
80 playlistUUID = playlist.uuid
8d987ec6
K
81
82 await addVideoInPlaylist({
83 url: server.url,
84 token: server.accessToken,
39433fa5 85 playlistId,
8d987ec6
K
86 elementAttrs: { videoId: server.video.id }
87 })
88
89 // Account
90
39433fa5 91 await updateMyUser({ url: server.url, accessToken: server.accessToken, description: 'my account description' })
8d987ec6 92
39433fa5
C
93 const resAccountRequest = await getAccount(server.url, `${server.user.username}@${server.host}`)
94 account = resAccountRequest.body
0e1dc3e7
C
95 })
96
d8755eed 97 it('Should have valid Open Graph tags on the watch page with video id', async function () {
0e1dc3e7 98 const res = await request(server.url)
98ec8b8e
C
99 .get('/videos/watch/' + server.video.id)
100 .set('Accept', 'text/html')
101 .expect(200)
0e1dc3e7 102
39433fa5
C
103 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
104 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
8d987ec6
K
105 expect(res.text).to.contain('<meta property="og:type" content="video" />')
106 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/${server.video.uuid}" />`)
0e1dc3e7
C
107 })
108
d8755eed 109 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
0e1dc3e7 110 const res = await request(server.url)
98ec8b8e
C
111 .get('/videos/watch/' + server.video.uuid)
112 .set('Accept', 'text/html')
113 .expect(200)
0e1dc3e7 114
39433fa5
C
115 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
116 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
8d987ec6
K
117 expect(res.text).to.contain('<meta property="og:type" content="video" />')
118 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/${server.video.uuid}" />`)
119 })
120
121 it('Should have valid Open Graph tags on the watch playlist page', async function () {
122 const res = await request(server.url)
39433fa5 123 .get('/videos/watch/playlist/' + playlistUUID)
8d987ec6
K
124 .set('Accept', 'text/html')
125 .expect(200)
126
39433fa5
C
127 expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
128 expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
8d987ec6 129 expect(res.text).to.contain('<meta property="og:type" content="video" />')
39433fa5 130 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/playlist/${playlistUUID}" />`)
8d987ec6
K
131 })
132
133 it('Should have valid Open Graph tags on the account page', async function () {
134 const res = await request(server.url)
135 .get('/accounts/' + server.user.username)
136 .set('Accept', 'text/html')
137 .expect(200)
138
39433fa5 139 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
8d987ec6
K
140 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
141 expect(res.text).to.contain('<meta property="og:type" content="website" />')
142 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/accounts/${server.user.username}" />`)
143 })
144
145 it('Should have valid Open Graph tags on the channel page', async function () {
146 const res = await request(server.url)
39433fa5 147 .get('/video-channels/' + server.videoChannel.name)
8d987ec6
K
148 .set('Accept', 'text/html')
149 .expect(200)
150
39433fa5
C
151 expect(res.text).to.contain(`<meta property="og:title" content="${server.videoChannel.displayName}" />`)
152 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
8d987ec6 153 expect(res.text).to.contain('<meta property="og:type" content="website" />')
39433fa5 154 expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/video-channels/${server.videoChannel.name}" />`)
0e1dc3e7
C
155 })
156
d8755eed
C
157 it('Should have valid oEmbed discovery tags', async function () {
158 const path = '/videos/watch/' + server.video.uuid
159 const res = await request(server.url)
160 .get(path)
98ec8b8e 161 .set('Accept', 'text/html')
d8755eed
C
162 .expect(200)
163
f4659d73
C
164 const port = server.port
165
166 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
167 `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2F${server.video.uuid}" ` +
d8755eed
C
168 `title="${server.video.name}" />`
169
170 expect(res.text).to.contain(expectedLink)
171 })
172
39433fa5 173 it('Should have valid twitter card on the watch 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" />')
39433fa5
C
181 expect(res.text).to.contain(`<meta property="twitter:title" content="${videoName}" />`)
182 expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescription}" />`)
8d987ec6
K
183 })
184
185 it('Should have valid twitter card on the watch playlist page', async function () {
186 const res = await request(server.url)
39433fa5 187 .get('/videos/watch/playlist/' + playlistUUID)
8d987ec6
K
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" />')
39433fa5
C
193 expect(res.text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`)
194 expect(res.text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`)
8d987ec6
K
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)
39433fa5 211 .get('/video-channels/' + server.videoChannel.name)
8d987ec6
K
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" />')
39433fa5
C
217 expect(res.text).to.contain(`<meta property="twitter:title" content="${server.videoChannel.displayName}" />`)
218 expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`)
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)
39433fa5 239 .get('/videos/watch/playlist/' + playlistUUID)
8d987ec6
K
240 .set('Accept', 'text/html')
241 .expect(200)
242
39433fa5 243 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
8d987ec6
K
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
39433fa5 251 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
8d987ec6
K
252 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
253
254 const resChannelRequest = await request(server.url)
39433fa5 255 .get('/video-channels/' + server.videoChannel.name)
8d987ec6
K
256 .set('Accept', 'text/html')
257 .expect(200)
258
39433fa5 259 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
8d987ec6 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})