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