diff options
Diffstat (limited to 'server/tests/client.ts')
-rw-r--r-- | server/tests/client.ts | 449 |
1 files changed, 283 insertions, 166 deletions
diff --git a/server/tests/client.ts b/server/tests/client.ts index 3c99bcd1f..7c4fb4e46 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts | |||
@@ -2,8 +2,9 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import * as request from 'supertest' | 5 | import { omit } from 'lodash' |
6 | import { Account, VideoPlaylistPrivacy } from '@shared/models' | 6 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' |
7 | import { Account, CustomConfig, HTMLServerConfig, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy } from '@shared/models' | ||
7 | import { | 8 | import { |
8 | addVideoInPlaylist, | 9 | addVideoInPlaylist, |
9 | cleanupTests, | 10 | cleanupTests, |
@@ -11,8 +12,10 @@ import { | |||
11 | doubleFollow, | 12 | doubleFollow, |
12 | flushAndRunMultipleServers, | 13 | flushAndRunMultipleServers, |
13 | getAccount, | 14 | getAccount, |
15 | getConfig, | ||
14 | getCustomConfig, | 16 | getCustomConfig, |
15 | getVideosList, | 17 | getVideosList, |
18 | makeGetRequest, | ||
16 | makeHTMLRequest, | 19 | makeHTMLRequest, |
17 | ServerInfo, | 20 | ServerInfo, |
18 | setAccessTokensToServers, | 21 | setAccessTokensToServers, |
@@ -24,14 +27,16 @@ import { | |||
24 | uploadVideo, | 27 | uploadVideo, |
25 | waitJobs | 28 | waitJobs |
26 | } from '../../shared/extra-utils' | 29 | } from '../../shared/extra-utils' |
27 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | ||
28 | 30 | ||
29 | const expect = chai.expect | 31 | const expect = chai.expect |
30 | 32 | ||
31 | function checkIndexTags (html: string, title: string, description: string, css: string) { | 33 | function checkIndexTags (html: string, title: string, description: string, css: string, config: ServerConfig) { |
32 | expect(html).to.contain('<title>' + title + '</title>') | 34 | expect(html).to.contain('<title>' + title + '</title>') |
33 | expect(html).to.contain('<meta name="description" content="' + description + '" />') | 35 | expect(html).to.contain('<meta name="description" content="' + description + '" />') |
34 | expect(html).to.contain('<style class="custom-css-style">' + css + '</style>') | 36 | expect(html).to.contain('<style class="custom-css-style">' + css + '</style>') |
37 | |||
38 | const htmlConfig: HTMLServerConfig = omit(config, 'signup') | ||
39 | expect(html).to.contain(`<script type="application/javascript">window.PeerTubeServerConfig = '${JSON.stringify(htmlConfig)}'</script>`) | ||
35 | } | 40 | } |
36 | 41 | ||
37 | describe('Test a client controllers', function () { | 42 | describe('Test a client controllers', function () { |
@@ -44,10 +49,16 @@ describe('Test a client controllers', function () { | |||
44 | 49 | ||
45 | const playlistName = 'super playlist name' | 50 | const playlistName = 'super playlist name' |
46 | const playlistDescription = 'super playlist description' | 51 | const playlistDescription = 'super playlist description' |
47 | let playlistUUID: string | 52 | let playlist: VideoPlaylistCreateResult |
48 | 53 | ||
49 | const channelDescription = 'my super channel description' | 54 | const channelDescription = 'my super channel description' |
50 | 55 | ||
56 | const watchVideoBasePaths = [ '/videos/watch/', '/w/' ] | ||
57 | const watchPlaylistBasePaths = [ '/videos/watch/playlist/', '/w/p/' ] | ||
58 | |||
59 | let videoIds: (string | number)[] = [] | ||
60 | let playlistIds: (string | number)[] = [] | ||
61 | |||
51 | before(async function () { | 62 | before(async function () { |
52 | this.timeout(120000) | 63 | this.timeout(120000) |
53 | 64 | ||
@@ -70,7 +81,9 @@ describe('Test a client controllers', function () { | |||
70 | const videos = resVideosRequest.body.data | 81 | const videos = resVideosRequest.body.data |
71 | expect(videos.length).to.equal(1) | 82 | expect(videos.length).to.equal(1) |
72 | 83 | ||
73 | servers[0].video = videos[0] | 84 | const video = videos[0] |
85 | servers[0].video = video | ||
86 | videoIds = [ video.id, video.uuid, video.shortUUID ] | ||
74 | 87 | ||
75 | // Playlist | 88 | // Playlist |
76 | 89 | ||
@@ -82,16 +95,14 @@ describe('Test a client controllers', function () { | |||
82 | } | 95 | } |
83 | 96 | ||
84 | const resVideoPlaylistRequest = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) | 97 | const resVideoPlaylistRequest = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) |
85 | 98 | playlist = resVideoPlaylistRequest.body.videoPlaylist | |
86 | const playlist = resVideoPlaylistRequest.body.videoPlaylist | 99 | playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ] |
87 | const playlistId = playlist.id | ||
88 | playlistUUID = playlist.uuid | ||
89 | 100 | ||
90 | await addVideoInPlaylist({ | 101 | await addVideoInPlaylist({ |
91 | url: servers[0].url, | 102 | url: servers[0].url, |
92 | token: servers[0].accessToken, | 103 | token: servers[0].accessToken, |
93 | playlistId, | 104 | playlistId: playlist.shortUUID, |
94 | elementAttrs: { videoId: servers[0].video.id } | 105 | elementAttrs: { videoId: video.id } |
95 | }) | 106 | }) |
96 | 107 | ||
97 | // Account | 108 | // Account |
@@ -105,201 +116,277 @@ describe('Test a client controllers', function () { | |||
105 | }) | 116 | }) |
106 | 117 | ||
107 | describe('oEmbed', function () { | 118 | describe('oEmbed', function () { |
119 | |||
108 | it('Should have valid oEmbed discovery tags for videos', async function () { | 120 | it('Should have valid oEmbed discovery tags for videos', async function () { |
109 | const path = '/videos/watch/' + servers[0].video.uuid | 121 | for (const basePath of watchVideoBasePaths) { |
110 | const res = await request(servers[0].url) | 122 | for (const id of videoIds) { |
111 | .get(path) | 123 | const res = await makeGetRequest({ |
112 | .set('Accept', 'text/html') | 124 | url: servers[0].url, |
113 | .expect(HttpStatusCode.OK_200) | 125 | path: basePath + id, |
126 | accept: 'text/html', | ||
127 | statusCodeExpected: HttpStatusCode.OK_200 | ||
128 | }) | ||
129 | |||
130 | const port = servers[0].port | ||
131 | |||
132 | const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + | ||
133 | `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2F${servers[0].video.uuid}" ` + | ||
134 | `title="${servers[0].video.name}" />` | ||
135 | |||
136 | expect(res.text).to.contain(expectedLink) | ||
137 | } | ||
138 | } | ||
139 | }) | ||
114 | 140 | ||
115 | const port = servers[0].port | 141 | it('Should have valid oEmbed discovery tags for a playlist', async function () { |
142 | for (const basePath of watchPlaylistBasePaths) { | ||
143 | for (const id of playlistIds) { | ||
144 | const res = await makeGetRequest({ | ||
145 | url: servers[0].url, | ||
146 | path: basePath + id, | ||
147 | accept: 'text/html', | ||
148 | statusCodeExpected: HttpStatusCode.OK_200 | ||
149 | }) | ||
150 | |||
151 | const port = servers[0].port | ||
152 | |||
153 | const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + | ||
154 | `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2Fp%2F${playlist.uuid}" ` + | ||
155 | `title="${playlistName}" />` | ||
156 | |||
157 | expect(res.text).to.contain(expectedLink) | ||
158 | } | ||
159 | } | ||
160 | }) | ||
161 | }) | ||
116 | 162 | ||
117 | const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + | 163 | describe('Open Graph', function () { |
118 | `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2F${servers[0].video.uuid}" ` + | ||
119 | `title="${servers[0].video.name}" />` | ||
120 | 164 | ||
121 | expect(res.text).to.contain(expectedLink) | 165 | async function accountPageTest (path: string) { |
122 | }) | 166 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
167 | const text = res.text | ||
123 | 168 | ||
124 | it('Should have valid oEmbed discovery tags for a playlist', async function () { | 169 | expect(text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) |
125 | const res = await request(servers[0].url) | 170 | expect(text).to.contain(`<meta property="og:description" content="${account.description}" />`) |
126 | .get('/videos/watch/playlist/' + playlistUUID) | 171 | expect(text).to.contain('<meta property="og:type" content="website" />') |
127 | .set('Accept', 'text/html') | 172 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`) |
128 | .expect(HttpStatusCode.OK_200) | 173 | } |
129 | 174 | ||
130 | const port = servers[0].port | 175 | async function channelPageTest (path: string) { |
176 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) | ||
177 | const text = res.text | ||
131 | 178 | ||
132 | const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + | 179 | expect(text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`) |
133 | `url=http%3A%2F%2Flocalhost%3A${port}%2Fvideos%2Fwatch%2Fplaylist%2F${playlistUUID}" ` + | 180 | expect(text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) |
134 | `title="${playlistName}" />` | 181 | expect(text).to.contain('<meta property="og:type" content="website" />') |
182 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`) | ||
183 | } | ||
135 | 184 | ||
136 | expect(res.text).to.contain(expectedLink) | 185 | async function watchVideoPageTest (path: string) { |
137 | }) | 186 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
138 | }) | 187 | const text = res.text |
139 | 188 | ||
140 | describe('Open Graph', function () { | 189 | expect(text).to.contain(`<meta property="og:title" content="${videoName}" />`) |
190 | expect(text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`) | ||
191 | expect(text).to.contain('<meta property="og:type" content="video" />') | ||
192 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/${servers[0].video.uuid}" />`) | ||
193 | } | ||
194 | |||
195 | async function watchPlaylistPageTest (path: string) { | ||
196 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) | ||
197 | const text = res.text | ||
198 | |||
199 | expect(text).to.contain(`<meta property="og:title" content="${playlistName}" />`) | ||
200 | expect(text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`) | ||
201 | expect(text).to.contain('<meta property="og:type" content="video" />') | ||
202 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/p/${playlist.uuid}" />`) | ||
203 | } | ||
141 | 204 | ||
142 | it('Should have valid Open Graph tags on the account page', async function () { | 205 | it('Should have valid Open Graph tags on the account page', async function () { |
143 | const res = await request(servers[0].url) | 206 | await accountPageTest('/accounts/' + servers[0].user.username) |
144 | .get('/accounts/' + servers[0].user.username) | 207 | await accountPageTest('/a/' + servers[0].user.username) |
145 | .set('Accept', 'text/html') | 208 | await accountPageTest('/@' + servers[0].user.username) |
146 | .expect(HttpStatusCode.OK_200) | ||
147 | |||
148 | expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) | ||
149 | expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`) | ||
150 | expect(res.text).to.contain('<meta property="og:type" content="website" />') | ||
151 | expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].user.username}" />`) | ||
152 | }) | 209 | }) |
153 | 210 | ||
154 | it('Should have valid Open Graph tags on the channel page', async function () { | 211 | it('Should have valid Open Graph tags on the channel page', async function () { |
155 | const res = await request(servers[0].url) | 212 | await channelPageTest('/video-channels/' + servers[0].videoChannel.name) |
156 | .get('/video-channels/' + servers[0].videoChannel.name) | 213 | await channelPageTest('/c/' + servers[0].videoChannel.name) |
157 | .set('Accept', 'text/html') | 214 | await channelPageTest('/@' + servers[0].videoChannel.name) |
158 | .expect(HttpStatusCode.OK_200) | ||
159 | |||
160 | expect(res.text).to.contain(`<meta property="og:title" content="${servers[0].videoChannel.displayName}" />`) | ||
161 | expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) | ||
162 | expect(res.text).to.contain('<meta property="og:type" content="website" />') | ||
163 | expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].videoChannel.name}" />`) | ||
164 | }) | 215 | }) |
165 | 216 | ||
166 | it('Should have valid Open Graph tags on the watch page with video id', async function () { | 217 | it('Should have valid Open Graph tags on the watch page', async function () { |
167 | const res = await request(servers[0].url) | 218 | for (const path of watchVideoBasePaths) { |
168 | .get('/videos/watch/' + servers[0].video.id) | 219 | for (const id of videoIds) { |
169 | .set('Accept', 'text/html') | 220 | await watchVideoPageTest(path + id) |
170 | .expect(HttpStatusCode.OK_200) | 221 | } |
171 | 222 | } | |
172 | expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`) | ||
173 | expect(res.text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`) | ||
174 | expect(res.text).to.contain('<meta property="og:type" content="video" />') | ||
175 | expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`) | ||
176 | }) | ||
177 | |||
178 | it('Should have valid Open Graph tags on the watch page with video uuid', async function () { | ||
179 | const res = await request(servers[0].url) | ||
180 | .get('/videos/watch/' + servers[0].video.uuid) | ||
181 | .set('Accept', 'text/html') | ||
182 | .expect(HttpStatusCode.OK_200) | ||
183 | |||
184 | expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`) | ||
185 | expect(res.text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`) | ||
186 | expect(res.text).to.contain('<meta property="og:type" content="video" />') | ||
187 | expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`) | ||
188 | }) | 223 | }) |
189 | 224 | ||
190 | it('Should have valid Open Graph tags on the watch playlist page', async function () { | 225 | it('Should have valid Open Graph tags on the watch playlist page', async function () { |
191 | const res = await request(servers[0].url) | 226 | for (const path of watchPlaylistBasePaths) { |
192 | .get('/videos/watch/playlist/' + playlistUUID) | 227 | for (const id of playlistIds) { |
193 | .set('Accept', 'text/html') | 228 | await watchPlaylistPageTest(path + id) |
194 | .expect(HttpStatusCode.OK_200) | 229 | } |
195 | 230 | } | |
196 | expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`) | ||
197 | expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`) | ||
198 | expect(res.text).to.contain('<meta property="og:type" content="video" />') | ||
199 | expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/playlist/${playlistUUID}" />`) | ||
200 | }) | 231 | }) |
201 | }) | 232 | }) |
202 | 233 | ||
203 | describe('Twitter card', async function () { | 234 | describe('Twitter card', async function () { |
204 | 235 | ||
205 | it('Should have valid twitter card on the watch video page', async function () { | 236 | describe('Not whitelisted', function () { |
206 | const res = await request(servers[0].url) | ||
207 | .get('/videos/watch/' + servers[0].video.uuid) | ||
208 | .set('Accept', 'text/html') | ||
209 | .expect(HttpStatusCode.OK_200) | ||
210 | 237 | ||
211 | expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />') | 238 | async function accountPageTest (path: string) { |
212 | expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | 239 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
213 | expect(res.text).to.contain(`<meta property="twitter:title" content="${videoName}" />`) | 240 | const text = res.text |
214 | expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`) | ||
215 | }) | ||
216 | 241 | ||
217 | it('Should have valid twitter card on the watch playlist page', async function () { | 242 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
218 | const res = await request(servers[0].url) | 243 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') |
219 | .get('/videos/watch/playlist/' + playlistUUID) | 244 | expect(text).to.contain(`<meta property="twitter:title" content="${account.name}" />`) |
220 | .set('Accept', 'text/html') | 245 | expect(text).to.contain(`<meta property="twitter:description" content="${account.description}" />`) |
221 | .expect(HttpStatusCode.OK_200) | 246 | } |
222 | 247 | ||
223 | expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') | 248 | async function channelPageTest (path: string) { |
224 | expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | 249 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
225 | expect(res.text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`) | 250 | const text = res.text |
226 | expect(res.text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`) | ||
227 | }) | ||
228 | 251 | ||
229 | it('Should have valid twitter card on the account page', async function () { | 252 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
230 | const res = await request(servers[0].url) | 253 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') |
231 | .get('/accounts/' + account.name) | 254 | expect(text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`) |
232 | .set('Accept', 'text/html') | 255 | expect(text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) |
233 | .expect(HttpStatusCode.OK_200) | 256 | } |
234 | 257 | ||
235 | expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') | 258 | async function watchVideoPageTest (path: string) { |
236 | expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | 259 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
237 | expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`) | 260 | const text = res.text |
238 | expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`) | 261 | |
239 | }) | 262 | expect(text).to.contain('<meta property="twitter:card" content="summary_large_image" />') |
263 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | ||
264 | expect(text).to.contain(`<meta property="twitter:title" content="${videoName}" />`) | ||
265 | expect(text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`) | ||
266 | } | ||
240 | 267 | ||
241 | it('Should have valid twitter card on the channel page', async function () { | 268 | async function watchPlaylistPageTest (path: string) { |
242 | const res = await request(servers[0].url) | 269 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
243 | .get('/video-channels/' + servers[0].videoChannel.name) | 270 | const text = res.text |
244 | .set('Accept', 'text/html') | 271 | |
245 | .expect(HttpStatusCode.OK_200) | 272 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
273 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | ||
274 | expect(text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`) | ||
275 | expect(text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`) | ||
276 | } | ||
246 | 277 | ||
247 | expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') | 278 | it('Should have valid twitter card on the watch video page', async function () { |
248 | expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | 279 | for (const path of watchVideoBasePaths) { |
249 | expect(res.text).to.contain(`<meta property="twitter:title" content="${servers[0].videoChannel.displayName}" />`) | 280 | for (const id of videoIds) { |
250 | expect(res.text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) | 281 | await watchVideoPageTest(path + id) |
282 | } | ||
283 | } | ||
284 | }) | ||
285 | |||
286 | it('Should have valid twitter card on the watch playlist page', async function () { | ||
287 | for (const path of watchPlaylistBasePaths) { | ||
288 | for (const id of playlistIds) { | ||
289 | await watchPlaylistPageTest(path + id) | ||
290 | } | ||
291 | } | ||
292 | }) | ||
293 | |||
294 | it('Should have valid twitter card on the account page', async function () { | ||
295 | await accountPageTest('/accounts/' + account.name) | ||
296 | await accountPageTest('/a/' + account.name) | ||
297 | await accountPageTest('/@' + account.name) | ||
298 | }) | ||
299 | |||
300 | it('Should have valid twitter card on the channel page', async function () { | ||
301 | await channelPageTest('/video-channels/' + servers[0].videoChannel.name) | ||
302 | await channelPageTest('/c/' + servers[0].videoChannel.name) | ||
303 | await channelPageTest('/@' + servers[0].videoChannel.name) | ||
304 | }) | ||
251 | }) | 305 | }) |
252 | 306 | ||
253 | it('Should have valid twitter card if Twitter is whitelisted', async function () { | 307 | describe('Whitelisted', function () { |
254 | const res1 = await getCustomConfig(servers[0].url, servers[0].accessToken) | 308 | |
255 | const config = res1.body | 309 | before(async function () { |
256 | config.services.twitter = { | 310 | const res = await getCustomConfig(servers[0].url, servers[0].accessToken) |
257 | username: '@Kuja', | 311 | const config = res.body as CustomConfig |
258 | whitelisted: true | 312 | config.services.twitter = { |
313 | username: '@Kuja', | ||
314 | whitelisted: true | ||
315 | } | ||
316 | |||
317 | await updateCustomConfig(servers[0].url, servers[0].accessToken, config) | ||
318 | }) | ||
319 | |||
320 | async function accountPageTest (path: string) { | ||
321 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) | ||
322 | const text = res.text | ||
323 | |||
324 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') | ||
325 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | ||
259 | } | 326 | } |
260 | await updateCustomConfig(servers[0].url, servers[0].accessToken, config) | ||
261 | 327 | ||
262 | const resVideoRequest = await request(servers[0].url) | 328 | async function channelPageTest (path: string) { |
263 | .get('/videos/watch/' + servers[0].video.uuid) | 329 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
264 | .set('Accept', 'text/html') | 330 | const text = res.text |
265 | .expect(HttpStatusCode.OK_200) | ||
266 | 331 | ||
267 | expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />') | 332 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
268 | expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | 333 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') |
334 | } | ||
269 | 335 | ||
270 | const resVideoPlaylistRequest = await request(servers[0].url) | 336 | async function watchVideoPageTest (path: string) { |
271 | .get('/videos/watch/playlist/' + playlistUUID) | 337 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
272 | .set('Accept', 'text/html') | 338 | const text = res.text |
273 | .expect(HttpStatusCode.OK_200) | ||
274 | 339 | ||
275 | expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />') | 340 | expect(text).to.contain('<meta property="twitter:card" content="player" />') |
276 | expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | 341 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') |
342 | } | ||
277 | 343 | ||
278 | const resAccountRequest = await request(servers[0].url) | 344 | async function watchPlaylistPageTest (path: string) { |
279 | .get('/accounts/' + account.name) | 345 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', statusCodeExpected: HttpStatusCode.OK_200 }) |
280 | .set('Accept', 'text/html') | 346 | const text = res.text |
281 | .expect(HttpStatusCode.OK_200) | ||
282 | 347 | ||
283 | expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />') | 348 | expect(text).to.contain('<meta property="twitter:card" content="player" />') |
284 | expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | 349 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') |
350 | } | ||
285 | 351 | ||
286 | const resChannelRequest = await request(servers[0].url) | 352 | it('Should have valid twitter card on the watch video page', async function () { |
287 | .get('/video-channels/' + servers[0].videoChannel.name) | 353 | for (const path of watchVideoBasePaths) { |
288 | .set('Accept', 'text/html') | 354 | for (const id of videoIds) { |
289 | .expect(HttpStatusCode.OK_200) | 355 | await watchVideoPageTest(path + id) |
356 | } | ||
357 | } | ||
358 | }) | ||
359 | |||
360 | it('Should have valid twitter card on the watch playlist page', async function () { | ||
361 | for (const path of watchPlaylistBasePaths) { | ||
362 | for (const id of playlistIds) { | ||
363 | await watchPlaylistPageTest(path + id) | ||
364 | } | ||
365 | } | ||
366 | }) | ||
290 | 367 | ||
291 | expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />') | 368 | it('Should have valid twitter card on the account page', async function () { |
292 | expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') | 369 | await accountPageTest('/accounts/' + account.name) |
370 | await accountPageTest('/a/' + account.name) | ||
371 | await accountPageTest('/@' + account.name) | ||
372 | }) | ||
373 | |||
374 | it('Should have valid twitter card on the channel page', async function () { | ||
375 | await channelPageTest('/video-channels/' + servers[0].videoChannel.name) | ||
376 | await channelPageTest('/c/' + servers[0].videoChannel.name) | ||
377 | await channelPageTest('/@' + servers[0].videoChannel.name) | ||
378 | }) | ||
293 | }) | 379 | }) |
294 | }) | 380 | }) |
295 | 381 | ||
296 | describe('Index HTML', function () { | 382 | describe('Index HTML', function () { |
297 | 383 | ||
298 | it('Should have valid index html tags (title, description...)', async function () { | 384 | it('Should have valid index html tags (title, description...)', async function () { |
385 | const resConfig = await getConfig(servers[0].url) | ||
299 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') | 386 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
300 | 387 | ||
301 | const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' | 388 | const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' |
302 | checkIndexTags(res.text, 'PeerTube', description, '') | 389 | checkIndexTags(res.text, 'PeerTube', description, '', resConfig.body) |
303 | }) | 390 | }) |
304 | 391 | ||
305 | it('Should update the customized configuration and have the correct index html tags', async function () { | 392 | it('Should update the customized configuration and have the correct index html tags', async function () { |
@@ -318,35 +405,65 @@ describe('Test a client controllers', function () { | |||
318 | } | 405 | } |
319 | }) | 406 | }) |
320 | 407 | ||
408 | const resConfig = await getConfig(servers[0].url) | ||
321 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') | 409 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
322 | 410 | ||
323 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') | 411 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body) |
324 | }) | 412 | }) |
325 | 413 | ||
326 | it('Should have valid index html updated tags (title, description...)', async function () { | 414 | it('Should have valid index html updated tags (title, description...)', async function () { |
415 | const resConfig = await getConfig(servers[0].url) | ||
327 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') | 416 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
328 | 417 | ||
329 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }') | 418 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body) |
330 | }) | 419 | }) |
331 | 420 | ||
332 | it('Should use the original video URL for the canonical tag', async function () { | 421 | it('Should use the original video URL for the canonical tag', async function () { |
333 | const res = await makeHTMLRequest(servers[1].url, '/videos/watch/' + servers[0].video.uuid) | 422 | for (const basePath of watchVideoBasePaths) { |
334 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`) | 423 | for (const id of videoIds) { |
424 | const res = await makeHTMLRequest(servers[1].url, basePath + id) | ||
425 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`) | ||
426 | } | ||
427 | } | ||
335 | }) | 428 | }) |
336 | 429 | ||
337 | it('Should use the original account URL for the canonical tag', async function () { | 430 | it('Should use the original account URL for the canonical tag', async function () { |
338 | const res = await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host) | 431 | const accountURLtest = (res) => { |
339 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`) | 432 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`) |
433 | } | ||
434 | |||
435 | accountURLtest(await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host)) | ||
436 | accountURLtest(await makeHTMLRequest(servers[1].url, '/a/root@' + servers[0].host)) | ||
437 | accountURLtest(await makeHTMLRequest(servers[1].url, '/@root@' + servers[0].host)) | ||
340 | }) | 438 | }) |
341 | 439 | ||
342 | it('Should use the original channel URL for the canonical tag', async function () { | 440 | it('Should use the original channel URL for the canonical tag', async function () { |
343 | const res = await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host) | 441 | const channelURLtests = (res) => { |
344 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`) | 442 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`) |
443 | } | ||
444 | |||
445 | channelURLtests(await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host)) | ||
446 | channelURLtests(await makeHTMLRequest(servers[1].url, '/c/root_channel@' + servers[0].host)) | ||
447 | channelURLtests(await makeHTMLRequest(servers[1].url, '/@root_channel@' + servers[0].host)) | ||
345 | }) | 448 | }) |
346 | 449 | ||
347 | it('Should use the original playlist URL for the canonical tag', async function () { | 450 | it('Should use the original playlist URL for the canonical tag', async function () { |
348 | const res = await makeHTMLRequest(servers[1].url, '/videos/watch/playlist/' + playlistUUID) | 451 | for (const basePath of watchPlaylistBasePaths) { |
349 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlistUUID}" />`) | 452 | for (const id of playlistIds) { |
453 | const res = await makeHTMLRequest(servers[1].url, basePath + id) | ||
454 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlist.uuid}" />`) | ||
455 | } | ||
456 | } | ||
457 | }) | ||
458 | }) | ||
459 | |||
460 | describe('Embed HTML', function () { | ||
461 | |||
462 | it('Should have the correct embed html tags', async function () { | ||
463 | const resConfig = await getConfig(servers[0].url) | ||
464 | const res = await makeHTMLRequest(servers[0].url, servers[0].video.embedPath) | ||
465 | |||
466 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body) | ||
350 | }) | 467 | }) |
351 | }) | 468 | }) |
352 | 469 | ||