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