]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands' | |
6 | import { Video, VideoPlaylistPrivacy } from '@shared/models' | |
7 | ||
8 | const expect = chai.expect | |
9 | ||
10 | describe('Test services', function () { | |
11 | let server: PeerTubeServer = null | |
12 | let playlistUUID: string | |
13 | let playlistDisplayName: string | |
14 | let video: Video | |
15 | ||
16 | const urlSuffixes = [ | |
17 | { | |
18 | input: '', | |
19 | output: '' | |
20 | }, | |
21 | { | |
22 | input: '?param=1', | |
23 | output: '' | |
24 | }, | |
25 | { | |
26 | input: '?muted=1&warningTitle=0&toto=1', | |
27 | output: '?muted=1&warningTitle=0' | |
28 | } | |
29 | ] | |
30 | ||
31 | before(async function () { | |
32 | this.timeout(30000) | |
33 | ||
34 | server = await createSingleServer(1) | |
35 | ||
36 | await setAccessTokensToServers([ server ]) | |
37 | await setDefaultVideoChannel([ server ]) | |
38 | ||
39 | { | |
40 | const attributes = { name: 'my super name' } | |
41 | await server.videos.upload({ attributes }) | |
42 | ||
43 | const { data } = await server.videos.list() | |
44 | video = data[0] | |
45 | } | |
46 | ||
47 | { | |
48 | const created = await server.playlists.create({ | |
49 | attributes: { | |
50 | displayName: 'The Life and Times of Scrooge McDuck', | |
51 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
52 | videoChannelId: server.store.channel.id | |
53 | } | |
54 | }) | |
55 | ||
56 | playlistUUID = created.uuid | |
57 | playlistDisplayName = 'The Life and Times of Scrooge McDuck' | |
58 | ||
59 | await server.playlists.addElement({ | |
60 | playlistId: created.id, | |
61 | attributes: { | |
62 | videoId: video.id | |
63 | } | |
64 | }) | |
65 | } | |
66 | }) | |
67 | ||
68 | it('Should have a valid oEmbed video response', async function () { | |
69 | for (const basePath of [ '/videos/watch/', '/w/' ]) { | |
70 | for (const suffix of urlSuffixes) { | |
71 | const oembedUrl = server.url + basePath + video.uuid + suffix.input | |
72 | ||
73 | const res = await server.services.getOEmbed({ oembedUrl }) | |
74 | const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' + | |
75 | `title="${video.name}" src="http://${server.host}/videos/embed/${video.uuid}${suffix.output}" ` + | |
76 | 'frameborder="0" allowfullscreen></iframe>' | |
77 | ||
78 | const expectedThumbnailUrl = 'http://' + server.host + video.previewPath | |
79 | ||
80 | expect(res.body.html).to.equal(expectedHtml) | |
81 | expect(res.body.title).to.equal(video.name) | |
82 | expect(res.body.author_name).to.equal(server.store.channel.displayName) | |
83 | expect(res.body.width).to.equal(560) | |
84 | expect(res.body.height).to.equal(315) | |
85 | expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) | |
86 | expect(res.body.thumbnail_width).to.equal(850) | |
87 | expect(res.body.thumbnail_height).to.equal(480) | |
88 | } | |
89 | } | |
90 | }) | |
91 | ||
92 | it('Should have a valid playlist oEmbed response', async function () { | |
93 | for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) { | |
94 | for (const suffix of urlSuffixes) { | |
95 | const oembedUrl = server.url + basePath + playlistUUID + suffix.input | |
96 | ||
97 | const res = await server.services.getOEmbed({ oembedUrl }) | |
98 | const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' + | |
99 | `title="${playlistDisplayName}" src="http://${server.host}/video-playlists/embed/${playlistUUID}${suffix.output}" ` + | |
100 | 'frameborder="0" allowfullscreen></iframe>' | |
101 | ||
102 | expect(res.body.html).to.equal(expectedHtml) | |
103 | expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck') | |
104 | expect(res.body.author_name).to.equal(server.store.channel.displayName) | |
105 | expect(res.body.width).to.equal(560) | |
106 | expect(res.body.height).to.equal(315) | |
107 | expect(res.body.thumbnail_url).exist | |
108 | expect(res.body.thumbnail_width).to.equal(280) | |
109 | expect(res.body.thumbnail_height).to.equal(157) | |
110 | } | |
111 | } | |
112 | }) | |
113 | ||
114 | it('Should have a valid oEmbed response with small max height query', async function () { | |
115 | for (const basePath of [ '/videos/watch/', '/w/' ]) { | |
116 | const oembedUrl = 'http://' + server.host + basePath + video.uuid | |
117 | const format = 'json' | |
118 | const maxHeight = 50 | |
119 | const maxWidth = 50 | |
120 | ||
121 | const res = await server.services.getOEmbed({ oembedUrl, format, maxHeight, maxWidth }) | |
122 | const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts allow-popups" ' + | |
123 | `title="${video.name}" src="http://${server.host}/videos/embed/${video.uuid}" ` + | |
124 | 'frameborder="0" allowfullscreen></iframe>' | |
125 | ||
126 | expect(res.body.html).to.equal(expectedHtml) | |
127 | expect(res.body.title).to.equal(video.name) | |
128 | expect(res.body.author_name).to.equal(server.store.channel.displayName) | |
129 | expect(res.body.height).to.equal(50) | |
130 | expect(res.body.width).to.equal(50) | |
131 | expect(res.body).to.not.have.property('thumbnail_url') | |
132 | expect(res.body).to.not.have.property('thumbnail_width') | |
133 | expect(res.body).to.not.have.property('thumbnail_height') | |
134 | } | |
135 | }) | |
136 | ||
137 | after(async function () { | |
138 | await cleanupTests([ server ]) | |
139 | }) | |
140 | }) |