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