]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
d8755eed | 2 | |
8b0d42ee | 3 | import 'mocha' |
6fad8e51 | 4 | import * as chai from 'chai' |
bf54587a | 5 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands' |
6302d599 | 6 | import { Video, VideoPlaylistPrivacy } from '@shared/models' |
d8755eed | 7 | |
8b0d42ee C |
8 | const expect = chai.expect |
9 | ||
d8755eed | 10 | describe('Test services', function () { |
254d3579 | 11 | let server: PeerTubeServer = null |
6fad8e51 | 12 | let playlistUUID: string |
4097c6d6 | 13 | let playlistDisplayName: string |
6302d599 | 14 | let video: Video |
d8755eed | 15 | |
c8bac539 DK |
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 | ||
d8755eed | 31 | before(async function () { |
e212f887 | 32 | this.timeout(30000) |
d8755eed | 33 | |
254d3579 | 34 | server = await createSingleServer(1) |
d8755eed C |
35 | |
36 | await setAccessTokensToServers([ server ]) | |
6fad8e51 | 37 | await setDefaultVideoChannel([ server ]) |
d8755eed | 38 | |
6fad8e51 | 39 | { |
d23dd9fb | 40 | const attributes = { name: 'my super name' } |
89d241a7 | 41 | await server.videos.upload({ attributes }) |
6fad8e51 | 42 | |
89d241a7 | 43 | const { data } = await server.videos.list() |
d23dd9fb | 44 | video = data[0] |
d8755eed | 45 | } |
8b0d42ee | 46 | |
6fad8e51 | 47 | { |
89d241a7 | 48 | const created = await server.playlists.create({ |
e6346d59 | 49 | attributes: { |
6fad8e51 C |
50 | displayName: 'The Life and Times of Scrooge McDuck', |
51 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 52 | videoChannelId: server.store.channel.id |
6fad8e51 C |
53 | } |
54 | }) | |
55 | ||
e6346d59 | 56 | playlistUUID = created.uuid |
4097c6d6 | 57 | playlistDisplayName = 'The Life and Times of Scrooge McDuck' |
6fad8e51 | 58 | |
89d241a7 | 59 | await server.playlists.addElement({ |
e6346d59 C |
60 | playlistId: created.id, |
61 | attributes: { | |
6302d599 | 62 | videoId: video.id |
6fad8e51 C |
63 | } |
64 | }) | |
65 | } | |
d8755eed C |
66 | }) |
67 | ||
6fad8e51 | 68 | it('Should have a valid oEmbed video response', async function () { |
a1eda903 | 69 | for (const basePath of [ '/videos/watch/', '/w/' ]) { |
c8bac539 DK |
70 | for (const suffix of urlSuffixes) { |
71 | const oembedUrl = server.url + basePath + video.uuid + suffix.input | |
e93ee838 C |
72 | |
73 | const res = await server.services.getOEmbed({ oembedUrl }) | |
7e44bd4a | 74 | const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' + |
c8bac539 | 75 | `title="${video.name}" src="http://${server.host}/videos/embed/${video.uuid}${suffix.output}" ` + |
e93ee838 | 76 | 'frameborder="0" allowfullscreen></iframe>' |
c8bac539 DK |
77 | |
78 | const expectedThumbnailUrl = 'http://' + server.host + video.previewPath | |
e93ee838 C |
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 | } | |
a1eda903 | 89 | } |
d8755eed C |
90 | }) |
91 | ||
6fad8e51 | 92 | it('Should have a valid playlist oEmbed response', async function () { |
a1eda903 | 93 | for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) { |
c8bac539 DK |
94 | for (const suffix of urlSuffixes) { |
95 | const oembedUrl = server.url + basePath + playlistUUID + suffix.input | |
e93ee838 C |
96 | |
97 | const res = await server.services.getOEmbed({ oembedUrl }) | |
7e44bd4a | 98 | const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" ' + |
c8bac539 | 99 | `title="${playlistDisplayName}" src="http://${server.host}/video-playlists/embed/${playlistUUID}${suffix.output}" ` + |
e93ee838 C |
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 | } | |
a1eda903 | 111 | } |
6fad8e51 C |
112 | }) |
113 | ||
d8755eed | 114 | it('Should have a valid oEmbed response with small max height query', async function () { |
a1eda903 | 115 | for (const basePath of [ '/videos/watch/', '/w/' ]) { |
c8bac539 | 116 | const oembedUrl = 'http://' + server.host + basePath + video.uuid |
a1eda903 C |
117 | const format = 'json' |
118 | const maxHeight = 50 | |
119 | const maxWidth = 50 | |
120 | ||
89d241a7 | 121 | const res = await server.services.getOEmbed({ oembedUrl, format, maxHeight, maxWidth }) |
7e44bd4a | 122 | const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts allow-popups" ' + |
c8bac539 | 123 | `title="${video.name}" src="http://${server.host}/videos/embed/${video.uuid}" ` + |
a1eda903 C |
124 | 'frameborder="0" allowfullscreen></iframe>' |
125 | ||
126 | expect(res.body.html).to.equal(expectedHtml) | |
127 | expect(res.body.title).to.equal(video.name) | |
89d241a7 | 128 | expect(res.body.author_name).to.equal(server.store.channel.displayName) |
a1eda903 C |
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 | } | |
d8755eed C |
135 | }) |
136 | ||
7c3b7976 C |
137 | after(async function () { |
138 | await cleanupTests([ server ]) | |
d8755eed C |
139 | }) |
140 | }) |