Skip to content

Commit 9cfca56

Browse files
committed
Add client.ts tests for account, channel and playlist tags
1 parent 2587bc4 commit 9cfca56

2 files changed

Lines changed: 175 additions & 23 deletions

File tree

server/lib/client-html.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class ClientHtml {
119119
}
120120

121121
const list = {
122-
'numberOfItems': videoPlaylist.get('videosLength')
122+
numberOfItems: videoPlaylist.get('videosLength')
123123
}
124124

125125
const ogType = 'video'
@@ -284,10 +284,10 @@ export class ClientHtml {
284284
metaTags['og:description'] = tags.description
285285

286286
if (tags.embed) {
287-
metaTags['og:video:url'] = tags.embed.url,
288-
metaTags['og:video:secure_url'] = tags.embed.url,
289-
metaTags['og:video:type'] = 'text/html',
290-
metaTags['og:video:width'] = EMBED_SIZE.width,
287+
metaTags['og:video:url'] = tags.embed.url
288+
metaTags['og:video:secure_url'] = tags.embed.url
289+
metaTags['og:video:type'] = 'text/html'
290+
metaTags['og:video:width'] = EMBED_SIZE.width
291291
metaTags['og:video:height'] = EMBED_SIZE.height
292292
}
293293

@@ -296,9 +296,9 @@ export class ClientHtml {
296296

297297
private static generateStandardMetaTags (tags) {
298298
return {
299-
'name': tags.title,
300-
'description': tags.description,
301-
'image': tags.image.url
299+
name: tags.title,
300+
description: tags.description,
301+
image: tags.image.url
302302
}
303303
}
304304

server/tests/client.ts

Lines changed: 167 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ import {
1313
serverLogin,
1414
updateCustomConfig,
1515
updateCustomSubConfig,
16-
uploadVideo
16+
uploadVideo,
17+
createVideoPlaylist,
18+
addVideoInPlaylist,
19+
getAccount,
20+
addVideoChannel,
21+
getVideoChannel
1722
} from '../../shared/extra-utils'
23+
import { VideoPlaylistPrivacy } from '@shared/models'
24+
import { MVideoPlaylist, MAccount, MChannel } from '@server/types/models'
25+
1826

1927
const expect = chai.expect
2028

@@ -26,25 +34,67 @@ function checkIndexTags (html: string, title: string, description: string, css:
2634

2735
describe('Test a client controllers', function () {
2836
let server: ServerInfo
37+
let videoPlaylist: MVideoPlaylist
38+
let account: MAccount
39+
let videoChannel: MChannel
40+
const name = 'my super name for server 1'
41+
const description = 'my super description for server 1'
2942

3043
before(async function () {
3144
this.timeout(120000)
3245

3346
server = await flushAndRunServer(1)
3447
server.accessToken = await serverLogin(server)
3548

36-
const videoAttributes = {
37-
name: 'my super name for server 1',
38-
description: 'my super description for server 1'
39-
}
49+
50+
// Video
51+
52+
const videoAttributes = { name, description }
53+
4054
await uploadVideo(server.url, server.accessToken, videoAttributes)
4155

42-
const res = await getVideosList(server.url)
43-
const videos = res.body.data
56+
const resVideosRequest = await getVideosList(server.url)
57+
58+
const videos = resVideosRequest.body.data.videos
4459

4560
expect(videos.length).to.equal(1)
4661

4762
server.video = videos[0]
63+
64+
65+
// Playlist
66+
67+
const playlistAttrs = {
68+
displayName: name,
69+
description,
70+
privacy: VideoPlaylistPrivacy.PUBLIC
71+
}
72+
73+
const resVideoPlaylistRequest = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs })
74+
75+
videoPlaylist = resVideoPlaylistRequest.body.videoPlaylist
76+
77+
await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: videoPlaylist.id, 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+
87+
// Channel
88+
89+
const videoChannelAttributesArg = {
90+
name: `${server.user.username}_channel`,
91+
displayName: name,
92+
description
93+
}
94+
95+
const resChannelRequest = await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
96+
97+
videoChannel = resChannelRequest.body.videoChannel
4898
})
4999

50100
it('Should have valid Open Graph tags on the watch page with video id', async function () {
@@ -53,8 +103,10 @@ describe('Test a client controllers', function () {
53103
.set('Accept', 'text/html')
54104
.expect(200)
55105

56-
expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
57-
expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
106+
expect(res.text).to.contain(`<meta property="og:title" content="${name}" />`)
107+
expect(res.text).to.contain(`<meta property="og:description" content="${description}" />`)
108+
expect(res.text).to.contain('<meta property="og:type" content="video" />')
109+
expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/${server.video.uuid}" />`)
58110
})
59111

60112
it('Should have valid Open Graph tags on the watch page with video uuid', async function () {
@@ -63,8 +115,46 @@ describe('Test a client controllers', function () {
63115
.set('Accept', 'text/html')
64116
.expect(200)
65117

66-
expect(res.text).to.contain('<meta property="og:title" content="my super name for server 1" />')
67-
expect(res.text).to.contain('<meta property="og:description" content="my super description for server 1" />')
118+
expect(res.text).to.contain(`<meta property="og:title" content="${name}" />`)
119+
expect(res.text).to.contain(`<meta property="og:description" content="${description}" />`)
120+
expect(res.text).to.contain('<meta property="og:type" content="video" />')
121+
expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/${server.video.uuid}" />`)
122+
})
123+
124+
it('Should have valid Open Graph tags on the watch playlist page', async function () {
125+
const res = await request(server.url)
126+
.get('/videos/watch/playlist/' + videoPlaylist.uuid)
127+
.set('Accept', 'text/html')
128+
.expect(200)
129+
130+
expect(res.text).to.contain(`<meta property="og:title" content="${videoPlaylist.name}" />`)
131+
expect(res.text).to.contain(`<meta property="og:description" content="${videoPlaylist.description}" />`)
132+
expect(res.text).to.contain('<meta property="og:type" content="video" />')
133+
expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/videos/watch/playlist/${videoPlaylist.uuid}" />`)
134+
})
135+
136+
it('Should have valid Open Graph tags on the account page', async function () {
137+
const res = await request(server.url)
138+
.get('/accounts/' + server.user.username)
139+
.set('Accept', 'text/html')
140+
.expect(200)
141+
142+
expect(res.text).to.contain(`<meta property="og:title" content="${account.getDisplayName()}" />`)
143+
expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
144+
expect(res.text).to.contain('<meta property="og:type" content="website" />')
145+
expect(res.text).to.contain(`<meta property="og:url" content="${server.url}/accounts/${server.user.username}" />`)
146+
})
147+
148+
it('Should have valid Open Graph tags on the channel page', async function () {
149+
const res = await request(server.url)
150+
.get('/video-channels/' + videoChannel.name)
151+
.set('Accept', 'text/html')
152+
.expect(200)
153+
154+
expect(res.text).to.contain(`<meta property="og:title" content="${videoChannel.getDisplayName()}" />`)
155+
expect(res.text).to.contain(`<meta property="og:description" content="${videoChannel.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}/video-channels/${videoChannel.name}" />`)
68158
})
69159

70160
it('Should have valid oEmbed discovery tags', async function () {
@@ -81,14 +171,52 @@ describe('Test a client controllers', function () {
81171
expect(res.text).to.contain(expectedLink)
82172
})
83173

84-
it('Should have valid twitter card', async function () {
174+
it('Should have valid twitter card on the whatch video page', async function () {
85175
const res = await request(server.url)
86176
.get('/videos/watch/' + server.video.uuid)
87177
.set('Accept', 'text/html')
88178
.expect(200)
89179

90180
expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
91181
expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
182+
expect(res.text).to.contain(`<meta property="twitter:title" content="${name}" />`)
183+
expect(res.text).to.contain(`<meta property="twitter:description" content="${description}" />`)
184+
})
185+
186+
it('Should have valid twitter card on the watch playlist page', async function () {
187+
const res = await request(server.url)
188+
.get('/videos/watch/playlist/' + videoPlaylist.uuid)
189+
.set('Accept', 'text/html')
190+
.expect(200)
191+
192+
expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
193+
expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
194+
expect(res.text).to.contain(`<meta property="twitter:title" content="${videoPlaylist.name}" />`)
195+
expect(res.text).to.contain(`<meta property="twitter:description" content="${videoPlaylist.description}" />`)
196+
})
197+
198+
it('Should have valid twitter card on the account page', async function () {
199+
const res = await request(server.url)
200+
.get('/accounts/' + account.name)
201+
.set('Accept', 'text/html')
202+
.expect(200)
203+
204+
expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
205+
expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
206+
expect(res.text).to.contain(`<meta property="twitter:title" content="${account.name}" />`)
207+
expect(res.text).to.contain(`<meta property="twitter:description" content="${account.description}" />`)
208+
})
209+
210+
it('Should have valid twitter card on the channel page', async function () {
211+
const res = await request(server.url)
212+
.get('/video-channels/' + videoChannel.name)
213+
.set('Accept', 'text/html')
214+
.expect(200)
215+
216+
expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
217+
expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
218+
expect(res.text).to.contain(`<meta property="twitter:title" content="${videoChannel.name}" />`)
219+
expect(res.text).to.contain(`<meta property="twitter:description" content="${videoChannel.description}" />`)
92220
})
93221

94222
it('Should have valid twitter card if Twitter is whitelisted', async function () {
@@ -100,13 +228,37 @@ describe('Test a client controllers', function () {
100228
}
101229
await updateCustomConfig(server.url, server.accessToken, config)
102230

103-
const res = await request(server.url)
231+
const resVideoRequest = await request(server.url)
104232
.get('/videos/watch/' + server.video.uuid)
105233
.set('Accept', 'text/html')
106234
.expect(200)
107235

108-
expect(res.text).to.contain('<meta property="twitter:card" content="player" />')
109-
expect(res.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
236+
expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />')
237+
expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
238+
239+
const resVideoPlaylistRequest = await request(server.url)
240+
.get('/videos/watch/playlist/' + videoPlaylist.uuid)
241+
.set('Accept', 'text/html')
242+
.expect(200)
243+
244+
expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />')
245+
expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
246+
247+
const resAccountRequest = await request(server.url)
248+
.get('/accounts/' + account.name)
249+
.set('Accept', 'text/html')
250+
.expect(200)
251+
252+
expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="player" />')
253+
expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
254+
255+
const resChannelRequest = await request(server.url)
256+
.get('/video-channels/' + videoChannel.name)
257+
.set('Accept', 'text/html')
258+
.expect(200)
259+
260+
expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="player" />')
261+
expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
110262
})
111263

112264
it('Should have valid index html tags (title, description...)', async function () {

0 commit comments

Comments
 (0)