]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/client.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / tests / client.ts
... / ...
CommitLineData
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import * as request from 'supertest'
6import { Account, VideoPlaylistPrivacy } from '@shared/models'
7import {
8 addVideoInPlaylist,
9 cleanupTests,
10 createVideoPlaylist,
11 doubleFollow,
12 flushAndRunMultipleServers,
13 getAccount,
14 getCustomConfig,
15 getVideosList,
16 makeHTMLRequest,
17 ServerInfo,
18 setAccessTokensToServers,
19 setDefaultVideoChannel,
20 updateCustomConfig,
21 updateCustomSubConfig,
22 updateMyUser,
23 updateVideoChannel,
24 uploadVideo,
25 waitJobs
26} from '../../shared/extra-utils'
27import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
28
29const expect = chai.expect
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}
36
37describe('Test a client controllers', function () {
38 let servers: ServerInfo[] = []
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'
49
50 before(async function () {
51 this.timeout(120000)
52
53 servers = await flushAndRunMultipleServers(2)
54
55 await setAccessTokensToServers(servers)
56
57 await doubleFollow(servers[0], servers[1])
58
59 await setDefaultVideoChannel(servers)
60
61 await updateVideoChannel(servers[0].url, servers[0].accessToken, servers[0].videoChannel.name, { description: channelDescription })
62
63 // Video
64
65 const videoAttributes = { name: videoName, description: videoDescription }
66 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
67
68 const resVideosRequest = await getVideosList(servers[0].url)
69 const videos = resVideosRequest.body.data
70 expect(videos.length).to.equal(1)
71
72 servers[0].video = videos[0]
73
74 // Playlist
75
76 const playlistAttrs = {
77 displayName: playlistName,
78 description: playlistDescription,
79 privacy: VideoPlaylistPrivacy.PUBLIC,
80 videoChannelId: servers[0].videoChannel.id
81 }
82
83 const resVideoPlaylistRequest = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs })
84
85 const playlist = resVideoPlaylistRequest.body.videoPlaylist
86 const playlistId = playlist.id
87 playlistUUID = playlist.uuid
88
89 await addVideoInPlaylist({
90 url: servers[0].url,
91 token: servers[0].accessToken,
92 playlistId,
93 elementAttrs: { videoId: servers[0].video.id }
94 })
95
96 // Account
97
98 await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' })
99
100 const resAccountRequest = await getAccount(servers[0].url, `${servers[0].user.username}@${servers[0].host}`)
101 account = resAccountRequest.body
102
103 await waitJobs(servers)
104 })
105
106 describe('oEmbed', function () {
107 it('Should have valid oEmbed discovery tags for videos', async function () {
108 const path = '/videos/watch/' + servers[0].video.uuid
109 const res = await request(servers[0].url)
110 .get(path)
111 .set('Accept', 'text/html')
112 .expect(HttpStatusCode.OK_200)
113
114 const port = servers[0].port
115
116 const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' +
117 `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2F${servers[0].video.uuid}" ` +
118 `title="${servers[0].video.name}" />`
119
120 expect(res.text).to.contain(expectedLink)
121 })
122
123 it('Should have valid oEmbed discovery tags for a playlist', async function () {
124 const res = await request(servers[0].url)
125 .get('/videos/watch/playlist/' + playlistUUID)
126 .set('Accept', 'text/html')
127 .expect(HttpStatusCode.OK_200)
128
129 const port = servers[0].port
130
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}" />`
134
135 expect(res.text).to.contain(expectedLink)
136 })
137 })
138
139 describe('Open Graph', function () {
140
141 it('Should have valid Open Graph tags on the account page', async function () {
142 const res = await request(servers[0].url)
143 .get('/accounts/' + servers[0].user.username)
144 .set('Accept', 'text/html')
145 .expect(HttpStatusCode.OK_200)
146
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" />')
150 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`)
151 })
152
153 it('Should have valid Open Graph tags on the channel page', async function () {
154 const res = await request(servers[0].url)
155 .get('/video-channels/' + servers[0].videoChannel.name)
156 .set('Accept', 'text/html')
157 .expect(HttpStatusCode.OK_200)
158
159 expect(res.text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`)
160 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
161 expect(res.text).to.contain('<meta property="og:type" content="website" />')
162 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`)
163 })
164
165 it('Should have valid Open Graph tags on the watch page with video id', async function () {
166 const res = await request(servers[0].url)
167 .get('/videos/watch/' + servers[0].video.id)
168 .set('Accept', 'text/html')
169 .expect(HttpStatusCode.OK_200)
170
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" />')
174 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
175 })
176
177 it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
178 const res = await request(servers[0].url)
179 .get('/videos/watch/' + servers[0].video.uuid)
180 .set('Accept', 'text/html')
181 .expect(HttpStatusCode.OK_200)
182
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" />')
186 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
187 })
188
189 it('Should have valid Open Graph tags on the watch playlist page', async function () {
190 const res = await request(servers[0].url)
191 .get('/videos/watch/playlist/' + playlistUUID)
192 .set('Accept', 'text/html')
193 .expect(HttpStatusCode.OK_200)
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" />')
198 expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/playlist/${playlistUUID}" />`)
199 })
200 })
201
202 describe('Twitter card', async function () {
203
204 it('Should have valid twitter card on the watch video page', async function () {
205 const res = await request(servers[0].url)
206 .get('/videos/watch/' + servers[0].video.uuid)
207 .set('Accept', 'text/html')
208 .expect(HttpStatusCode.OK_200)
209
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 })
215
216 it('Should have valid twitter card on the watch playlist page', async function () {
217 const res = await request(servers[0].url)
218 .get('/videos/watch/playlist/' + playlistUUID)
219 .set('Accept', 'text/html')
220 .expect(HttpStatusCode.OK_200)
221
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 })
227
228 it('Should have valid twitter card on the account page', async function () {
229 const res = await request(servers[0].url)
230 .get('/accounts/' + account.name)
231 .set('Accept', 'text/html')
232 .expect(HttpStatusCode.OK_200)
233
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 })
239
240 it('Should have valid twitter card on the channel page', async function () {
241 const res = await request(servers[0].url)
242 .get('/video-channels/' + servers[0].videoChannel.name)
243 .set('Accept', 'text/html')
244 .expect(HttpStatusCode.OK_200)
245
246 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
247 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
248 expect(res.text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`)
249 expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`)
250 })
251
252 it('Should have valid twitter card if Twitter is whitelisted', async function () {
253 const res1 = await getCustomConfig(servers[0].url, servers[0].accessToken)
254 const config = res1.body
255 config.services.twitter = {
256 username: '@Kuja',
257 whitelisted: true
258 }
259 await updateCustomConfig(servers[0].url, servers[0].accessToken, config)
260
261 const resVideoRequest = await request(servers[0].url)
262 .get('/videos/watch/' + servers[0].video.uuid)
263 .set('Accept', 'text/html')
264 .expect(HttpStatusCode.OK_200)
265
266 expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />')
267 expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
268
269 const resVideoPlaylistRequest = await request(servers[0].url)
270 .get('/videos/watch/playlist/' + playlistUUID)
271 .set('Accept', 'text/html')
272 .expect(HttpStatusCode.OK_200)
273
274 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />')
275 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
276
277 const resAccountRequest = await request(servers[0].url)
278 .get('/accounts/' + account.name)
279 .set('Accept', 'text/html')
280 .expect(HttpStatusCode.OK_200)
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
285 const resChannelRequest = await request(servers[0].url)
286 .get('/video-channels/' + servers[0].videoChannel.name)
287 .set('Accept', 'text/html')
288 .expect(HttpStatusCode.OK_200)
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 })
293 })
294
295 describe('Index HTML', function () {
296
297 it('Should have valid index html tags (title, description...)', async function () {
298 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
299
300 const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
301 checkIndexTags(res.text, 'PeerTube', description, '')
302 })
303
304 it('Should update the customized configuration and have the correct index html tags', async function () {
305 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
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 })
319
320 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
321
322 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
323 })
324
325 it('Should have valid index html updated tags (title, description...)', async function () {
326 const res = await makeHTMLRequest(servers[0].url, '/videos/trending')
327
328 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
329 })
330
331 it('Should use the original video URL for the canonical tag', async function () {
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}" />`)
349 })
350 })
351
352 after(async function () {
353 await cleanupTests(servers)
354 })
355})