]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/client.ts
emit more specific status codes on video upload (#3423)
[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,
a59f210f
C
11 doubleFollow,
12 flushAndRunMultipleServers,
39433fa5 13 getAccount,
590fb506
C
14 getCustomConfig,
15 getVideosList,
590fb506 16 makeHTMLRequest,
590fb506 17 ServerInfo,
a59f210f 18 setAccessTokensToServers,
39433fa5 19 setDefaultVideoChannel,
590fb506
C
20 updateCustomConfig,
21 updateCustomSubConfig,
39433fa5 22 updateMyUser,
e5024f51 23 updateVideoChannel,
a59f210f
C
24 uploadVideo,
25 waitJobs
94565d52 26} from '../../shared/extra-utils'
2d53be02 27import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
590fb506
C
28
29const expect = chai.expect
5bcfd029
C
30
31function checkIndexTags (html: string, title: string, description: string, css: string) {
32 expect(html).to.contain('<title>' + title + '</title>')
33 expect(html).to.contain('<meta name="description" content="' + description + '" />')
34 expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
35}
0e1dc3e7
C
36
37describe('Test a client controllers', function () {
e5024f51 38 let servers: ServerInfo[] = []
39433fa5
C
39 let account: Account
40
41 const videoName = 'my super name for server 1'
42 const videoDescription = 'my super description for server 1'
43
44 const playlistName = 'super playlist name'
45 const playlistDescription = 'super playlist description'
46 let playlistUUID: string
47
48 const channelDescription = 'my super channel description'
0e1dc3e7
C
49
50 before(async function () {
51 this.timeout(120000)
52
e5024f51 53 servers = await flushAndRunMultipleServers(2)
e5024f51
TC
54
55 await setAccessTokensToServers(servers)
56
e5024f51
TC
57 await doubleFollow(servers[0], servers[1])
58
a59f210f 59 await setDefaultVideoChannel(servers)
0e1dc3e7 60
a59f210f 61 await updateVideoChannel(servers[0].url, servers[0].accessToken, servers[0].videoChannel.name, { description: channelDescription })
8d987ec6 62
39433fa5 63 // Video
8d987ec6 64
39433fa5 65 const videoAttributes = { name: videoName, description: videoDescription }
a59f210f 66 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
0e1dc3e7 67
a59f210f 68 const resVideosRequest = await getVideosList(servers[0].url)
8d987ec6 69 const videos = resVideosRequest.body.data
0e1dc3e7
C
70 expect(videos.length).to.equal(1)
71
a59f210f 72 servers[0].video = videos[0]
8d987ec6
K
73
74 // Playlist
75
76 const playlistAttrs = {
39433fa5
C
77 displayName: playlistName,
78 description: playlistDescription,
79 privacy: VideoPlaylistPrivacy.PUBLIC,
a59f210f 80 videoChannelId: servers[0].videoChannel.id
8d987ec6
K
81 }
82
a59f210f 83 const resVideoPlaylistRequest = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs })
8d987ec6 84
39433fa5
C
85 const playlist = resVideoPlaylistRequest.body.videoPlaylist
86 const playlistId = playlist.id
87 playlistUUID = playlist.uuid
8d987ec6
K
88
89 await addVideoInPlaylist({
a59f210f
C
90 url: servers[0].url,
91 token: servers[0].accessToken,
39433fa5 92 playlistId,
a59f210f 93 elementAttrs: { videoId: servers[0].video.id }
8d987ec6
K
94 })
95
96 // Account
97
a59f210f 98 await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' })
8d987ec6 99
a59f210f 100 const resAccountRequest = await getAccount(servers[0].url, `${servers[0].user.username}@${servers[0].host}`)
39433fa5 101 account = resAccountRequest.body
a59f210f
C
102
103 await waitJobs(servers)
0e1dc3e7
C
104 })
105
6fad8e51
C
106 describe('oEmbed', function () {
107 it('Should have valid oEmbed discovery tags for videos', async function () {
a59f210f
C
108 const path = '/videos/watch/' + servers[0].video.uuid
109 const res = await request(servers[0].url)
6fad8e51
C
110 .get(path)
111 .set('Accept', 'text/html')
2d53be02 112 .expect(HttpStatusCode.OK_200)
0e1dc3e7 113
a59f210f 114 const port = servers[0].port
0e1dc3e7 115
6fad8e51 116 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
a59f210f
C
117 `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2F${servers[0].video.uuid}" ` +
118 `title="${servers[0].video.name}" />`
8d987ec6 119
6fad8e51
C
120 expect(res.text).to.contain(expectedLink)
121 })
8d987ec6 122
6fad8e51 123 it('Should have valid oEmbed discovery tags for a playlist', async function () {
a59f210f 124 const res = await request(servers[0].url)
6fad8e51
C
125 .get('/videos/watch/playlist/' + playlistUUID)
126 .set('Accept', 'text/html')
2d53be02 127 .expect(HttpStatusCode.OK_200)
6fad8e51 128
a59f210f 129 const port = servers[0].port
8d987ec6 130
6fad8e51
C
131 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
132 `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2Fplaylist%2F${playlistUUID}" ` +
133 `title="${playlistName}" />`
8d987ec6 134
6fad8e51
C
135 expect(res.text).to.contain(expectedLink)
136 })
8d987ec6
K
137 })
138
6fad8e51 139 describe('Open Graph', function () {
8d987ec6 140
6fad8e51 141 it('Should have valid Open Graph tags on the account page', async function () {
a59f210f
C
142 const res = await request(servers[0].url)
143 .get('/accounts/' + servers[0].user.username)
6fad8e51 144 .set('Accept', 'text/html')
2d53be02 145 .expect(HttpStatusCode.OK_200)
0e1dc3e7 146
6fad8e51
C
147 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
148 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
149 expect(res.text).to.contain('<meta property="og:type" content="website" />')
a59f210f 150 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`)
6fad8e51 151 })
d8755eed 152
6fad8e51 153 it('Should have valid Open Graph tags on the channel page', async function () {
a59f210f
C
154 const res = await request(servers[0].url)
155 .get('/video-channels/' + servers[0].videoChannel.name)
6fad8e51 156 .set('Accept', 'text/html')
2d53be02 157 .expect(HttpStatusCode.OK_200)
f4659d73 158
a59f210f 159 expect(res.text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`)
6fad8e51
C
160 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
161 expect(res.text).to.contain('<meta property="og:type" content="website" />')
a59f210f 162 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`)
6fad8e51 163 })
d8755eed 164
6fad8e51 165 it('Should have valid Open Graph tags on the watch page with video id', async function () {
a59f210f
C
166 const res = await request(servers[0].url)
167 .get('/videos/watch/' + servers[0].video.id)
6fad8e51 168 .set('Accept', 'text/html')
2d53be02 169 .expect(HttpStatusCode.OK_200)
d8755eed 170
6fad8e51
C
171 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
172 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
173 expect(res.text).to.contain('<meta property="og:type" content="video" />')
a59f210f 174 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
6fad8e51 175 })
8be1afa1 176
6fad8e51 177 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
a59f210f
C
178 const res = await request(servers[0].url)
179 .get('/videos/watch/' + servers[0].video.uuid)
6fad8e51 180 .set('Accept', 'text/html')
2d53be02 181 .expect(HttpStatusCode.OK_200)
8d987ec6 182
6fad8e51
C
183 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
184 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
185 expect(res.text).to.contain('<meta property="og:type" content="video" />')
a59f210f 186 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
6fad8e51 187 })
8d987ec6 188
6fad8e51 189 it('Should have valid Open Graph tags on the watch playlist page', async function () {
a59f210f 190 const res = await request(servers[0].url)
6fad8e51
C
191 .get('/videos/watch/playlist/' + playlistUUID)
192 .set('Accept', 'text/html')
2d53be02 193 .expect(HttpStatusCode.OK_200)
6fad8e51
C
194
195 expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
196 expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
197 expect(res.text).to.contain('<meta property="og:type" content="video" />')
a59f210f 198 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/playlist/${playlistUUID}" />`)
6fad8e51 199 })
8d987ec6
K
200 })
201
6fad8e51 202 describe('Twitter card', async function () {
8d987ec6 203
6fad8e51 204 it('Should have valid twitter card on the watch video page', async function () {
a59f210f
C
205 const res = await request(servers[0].url)
206 .get('/videos/watch/' + servers[0].video.uuid)
6fad8e51 207 .set('Accept', 'text/html')
2d53be02 208 .expect(HttpStatusCode.OK_200)
8d987ec6 209
6fad8e51
C
210 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
211 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
212 expect(res.text).to.contain(`<meta property="twitter:title" content="${videoName}" />`)
213 expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescription}" />`)
214 })
8d987ec6 215
6fad8e51 216 it('Should have valid twitter card on the watch playlist page', async function () {
a59f210f 217 const res = await request(servers[0].url)
6fad8e51
C
218 .get('/videos/watch/playlist/' + playlistUUID)
219 .set('Accept', 'text/html')
2d53be02 220 .expect(HttpStatusCode.OK_200)
8be1afa1 221
6fad8e51
C
222 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
223 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
224 expect(res.text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`)
225 expect(res.text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`)
226 })
8be1afa1 227
6fad8e51 228 it('Should have valid twitter card on the account page', async function () {
a59f210f 229 const res = await request(servers[0].url)
6fad8e51
C
230 .get('/accounts/' + account.name)
231 .set('Accept', 'text/html')
2d53be02 232 .expect(HttpStatusCode.OK_200)
8be1afa1 233
6fad8e51
C
234 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
235 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
236 expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`)
237 expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`)
238 })
8d987ec6 239
6fad8e51 240 it('Should have valid twitter card on the channel page', async function () {
a59f210f
C
241 const res = await request(servers[0].url)
242 .get('/video-channels/' + servers[0].videoChannel.name)
6fad8e51 243 .set('Accept', 'text/html')
2d53be02 244 .expect(HttpStatusCode.OK_200)
8d987ec6 245
6fad8e51
C
246 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
247 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
a59f210f 248 expect(res.text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`)
6fad8e51
C
249 expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`)
250 })
8d987ec6 251
6fad8e51 252 it('Should have valid twitter card if Twitter is whitelisted', async function () {
a59f210f 253 const res1 = await getCustomConfig(servers[0].url, servers[0].accessToken)
6fad8e51
C
254 const config = res1.body
255 config.services.twitter = {
256 username: '@Kuja',
257 whitelisted: true
258 }
a59f210f 259 await updateCustomConfig(servers[0].url, servers[0].accessToken, config)
8d987ec6 260
a59f210f
C
261 const resVideoRequest = await request(servers[0].url)
262 .get('/videos/watch/' + servers[0].video.uuid)
6fad8e51 263 .set('Accept', 'text/html')
2d53be02 264 .expect(HttpStatusCode.OK_200)
8d987ec6 265
6fad8e51
C
266 expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />')
267 expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
8d987ec6 268
a59f210f 269 const resVideoPlaylistRequest = await request(servers[0].url)
6fad8e51
C
270 .get('/videos/watch/playlist/' + playlistUUID)
271 .set('Accept', 'text/html')
2d53be02 272 .expect(HttpStatusCode.OK_200)
8be1afa1 273
6fad8e51
C
274 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />')
275 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
5bcfd029 276
a59f210f 277 const resAccountRequest = await request(servers[0].url)
6fad8e51
C
278 .get('/accounts/' + account.name)
279 .set('Accept', 'text/html')
2d53be02 280 .expect(HttpStatusCode.OK_200)
6fad8e51
C
281
282 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
283 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
284
a59f210f
C
285 const resChannelRequest = await request(servers[0].url)
286 .get('/video-channels/' + servers[0].videoChannel.name)
6fad8e51 287 .set('Accept', 'text/html')
2d53be02 288 .expect(HttpStatusCode.OK_200)
6fad8e51
C
289
290 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
291 expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
292 })
5bcfd029
C
293 })
294
6fad8e51
C
295 describe('Index HTML', function () {
296
297 it('Should have valid index html tags (title, description...)', async function () {
a59f210f 298 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
6fad8e51
C
299
300 const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
301 checkIndexTags(res.text, 'PeerTube', description, '')
590fb506 302 })
5bcfd029 303
6fad8e51 304 it('Should update the customized configuration and have the correct index html tags', async function () {
a59f210f 305 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
6fad8e51
C
306 instance: {
307 name: 'PeerTube updated',
308 shortDescription: 'my short description',
309 description: 'my super description',
310 terms: 'my super terms',
311 defaultClientRoute: '/videos/recently-added',
312 defaultNSFWPolicy: 'blur',
313 customizations: {
314 javascript: 'alert("coucou")',
315 css: 'body { background-color: red; }'
316 }
317 }
318 })
5bcfd029 319
a59f210f 320 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
6fad8e51
C
321
322 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
323 })
5bcfd029 324
6fad8e51 325 it('Should have valid index html updated tags (title, description...)', async function () {
a59f210f 326 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
5bcfd029 327
6fad8e51
C
328 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
329 })
e5024f51
TC
330
331 it('Should use the original video URL for the canonical tag', async function () {
a59f210f
C
332 const res = await makeHTMLRequest(servers[1].url, '/videos/watch/' + servers[0].video.uuid)
333 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
334 })
335
336 it('Should use the original account URL for the canonical tag', async function () {
337 const res = await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host)
338 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`)
339 })
340
341 it('Should use the original channel URL for the canonical tag', async function () {
342 const res = await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host)
343 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`)
344 })
345
346 it('Should use the original playlist URL for the canonical tag', async function () {
347 const res = await makeHTMLRequest(servers[1].url, '/videos/watch/playlist/' + playlistUUID)
348 expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlistUUID}" />`)
e5024f51 349 })
5bcfd029
C
350 })
351
7c3b7976 352 after(async function () {
a59f210f 353 await cleanupTests(servers)
0e1dc3e7
C
354 })
355})