diff options
author | Chocobozzz <me@florianbigard.com> | 2020-08-05 15:35:58 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-08-07 08:58:29 +0200 |
commit | 6fad8e51c47b9d07bea99b777c1f55c10f6d576d (patch) | |
tree | 09b33652d565a6dbe70e413b88c64aa611f7f4b6 /server/tests/api | |
parent | a75292db788d400ba84933693f5f98a83f3aaa60 (diff) | |
download | PeerTube-6fad8e51c47b9d07bea99b777c1f55c10f6d576d.tar.gz PeerTube-6fad8e51c47b9d07bea99b777c1f55c10f6d576d.tar.zst PeerTube-6fad8e51c47b9d07bea99b777c1f55c10f6d576d.zip |
Handle playlist oembed
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params/services.ts | 46 | ||||
-rw-r--r-- | server/tests/api/videos/services.ts | 75 |
2 files changed, 104 insertions, 17 deletions
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index 457adfaab..e57edd9e4 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts | |||
@@ -8,11 +8,15 @@ import { | |||
8 | makeGetRequest, | 8 | makeGetRequest, |
9 | ServerInfo, | 9 | ServerInfo, |
10 | setAccessTokensToServers, | 10 | setAccessTokensToServers, |
11 | uploadVideo | 11 | uploadVideo, |
12 | createVideoPlaylist, | ||
13 | setDefaultVideoChannel | ||
12 | } from '../../../../shared/extra-utils' | 14 | } from '../../../../shared/extra-utils' |
15 | import { VideoPlaylistPrivacy } from '@shared/models' | ||
13 | 16 | ||
14 | describe('Test services API validators', function () { | 17 | describe('Test services API validators', function () { |
15 | let server: ServerInfo | 18 | let server: ServerInfo |
19 | let playlistUUID: string | ||
16 | 20 | ||
17 | // --------------------------------------------------------------- | 21 | // --------------------------------------------------------------- |
18 | 22 | ||
@@ -21,9 +25,26 @@ describe('Test services API validators', function () { | |||
21 | 25 | ||
22 | server = await flushAndRunServer(1) | 26 | server = await flushAndRunServer(1) |
23 | await setAccessTokensToServers([ server ]) | 27 | await setAccessTokensToServers([ server ]) |
24 | 28 | await setDefaultVideoChannel([ server ]) | |
25 | const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' }) | 29 | |
26 | server.video = res.body.video | 30 | { |
31 | const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' }) | ||
32 | server.video = res.body.video | ||
33 | } | ||
34 | |||
35 | { | ||
36 | const res = await createVideoPlaylist({ | ||
37 | url: server.url, | ||
38 | token: server.accessToken, | ||
39 | playlistAttrs: { | ||
40 | displayName: 'super playlist', | ||
41 | privacy: VideoPlaylistPrivacy.PUBLIC, | ||
42 | videoChannelId: server.videoChannel.id | ||
43 | } | ||
44 | }) | ||
45 | |||
46 | playlistUUID = res.body.videoPlaylist.uuid | ||
47 | } | ||
27 | }) | 48 | }) |
28 | 49 | ||
29 | describe('Test oEmbed API validators', function () { | 50 | describe('Test oEmbed API validators', function () { |
@@ -38,12 +59,12 @@ describe('Test services API validators', function () { | |||
38 | await checkParamEmbed(server, embedUrl) | 59 | await checkParamEmbed(server, embedUrl) |
39 | }) | 60 | }) |
40 | 61 | ||
41 | it('Should fail with an invalid video id', async function () { | 62 | it('Should fail with an invalid element id', async function () { |
42 | const embedUrl = `http://localhost:${server.port}/videos/watch/blabla` | 63 | const embedUrl = `http://localhost:${server.port}/videos/watch/blabla` |
43 | await checkParamEmbed(server, embedUrl) | 64 | await checkParamEmbed(server, embedUrl) |
44 | }) | 65 | }) |
45 | 66 | ||
46 | it('Should fail with an unknown video', async function () { | 67 | it('Should fail with an unknown element', async function () { |
47 | const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` | 68 | const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` |
48 | await checkParamEmbed(server, embedUrl, 404) | 69 | await checkParamEmbed(server, embedUrl, 404) |
49 | }) | 70 | }) |
@@ -78,7 +99,7 @@ describe('Test services API validators', function () { | |||
78 | await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) | 99 | await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) |
79 | }) | 100 | }) |
80 | 101 | ||
81 | it('Should succeed with the correct params', async function () { | 102 | it('Should succeed with the correct params with a video', async function () { |
82 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` | 103 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` |
83 | const query = { | 104 | const query = { |
84 | format: 'json', | 105 | format: 'json', |
@@ -88,6 +109,17 @@ describe('Test services API validators', function () { | |||
88 | 109 | ||
89 | await checkParamEmbed(server, embedUrl, 200, query) | 110 | await checkParamEmbed(server, embedUrl, 200, query) |
90 | }) | 111 | }) |
112 | |||
113 | it('Should succeed with the correct params with a playlist', async function () { | ||
114 | const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}` | ||
115 | const query = { | ||
116 | format: 'json', | ||
117 | maxheight: 400, | ||
118 | maxwidth: 400 | ||
119 | } | ||
120 | |||
121 | await checkParamEmbed(server, embedUrl, 200, query) | ||
122 | }) | ||
91 | }) | 123 | }) |
92 | 124 | ||
93 | after(async function () { | 125 | after(async function () { |
diff --git a/server/tests/api/videos/services.ts b/server/tests/api/videos/services.ts index 5505a845a..897f37c04 100644 --- a/server/tests/api/videos/services.ts +++ b/server/tests/api/videos/services.ts | |||
@@ -1,14 +1,25 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
5 | import { getOEmbed, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index' | 4 | import * as chai from 'chai' |
5 | import { | ||
6 | getOEmbed, | ||
7 | getVideosList, | ||
8 | ServerInfo, | ||
9 | setAccessTokensToServers, | ||
10 | setDefaultVideoChannel, | ||
11 | uploadVideo, | ||
12 | createVideoPlaylist, | ||
13 | addVideoInPlaylist | ||
14 | } from '../../../../shared/extra-utils' | ||
6 | import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' | 15 | import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' |
16 | import { VideoPlaylistPrivacy } from '@shared/models' | ||
7 | 17 | ||
8 | const expect = chai.expect | 18 | const expect = chai.expect |
9 | 19 | ||
10 | describe('Test services', function () { | 20 | describe('Test services', function () { |
11 | let server: ServerInfo = null | 21 | let server: ServerInfo = null |
22 | let playlistUUID: string | ||
12 | 23 | ||
13 | before(async function () { | 24 | before(async function () { |
14 | this.timeout(30000) | 25 | this.timeout(30000) |
@@ -16,17 +27,43 @@ describe('Test services', function () { | |||
16 | server = await flushAndRunServer(1) | 27 | server = await flushAndRunServer(1) |
17 | 28 | ||
18 | await setAccessTokensToServers([ server ]) | 29 | await setAccessTokensToServers([ server ]) |
30 | await setDefaultVideoChannel([ server ]) | ||
19 | 31 | ||
20 | const videoAttributes = { | 32 | { |
21 | name: 'my super name' | 33 | const videoAttributes = { |
34 | name: 'my super name' | ||
35 | } | ||
36 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
37 | |||
38 | const res = await getVideosList(server.url) | ||
39 | server.video = res.body.data[0] | ||
22 | } | 40 | } |
23 | await uploadVideo(server.url, server.accessToken, videoAttributes) | ||
24 | 41 | ||
25 | const res = await getVideosList(server.url) | 42 | { |
26 | server.video = res.body.data[0] | 43 | const res = await createVideoPlaylist({ |
44 | url: server.url, | ||
45 | token: server.accessToken, | ||
46 | playlistAttrs: { | ||
47 | displayName: 'The Life and Times of Scrooge McDuck', | ||
48 | privacy: VideoPlaylistPrivacy.PUBLIC, | ||
49 | videoChannelId: server.videoChannel.id | ||
50 | } | ||
51 | }) | ||
52 | |||
53 | playlistUUID = res.body.videoPlaylist.uuid | ||
54 | |||
55 | await addVideoInPlaylist({ | ||
56 | url: server.url, | ||
57 | token: server.accessToken, | ||
58 | playlistId: res.body.videoPlaylist.id, | ||
59 | elementAttrs: { | ||
60 | videoId: server.video.id | ||
61 | } | ||
62 | }) | ||
63 | } | ||
27 | }) | 64 | }) |
28 | 65 | ||
29 | it('Should have a valid oEmbed response', async function () { | 66 | it('Should have a valid oEmbed video response', async function () { |
30 | const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid | 67 | const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid |
31 | 68 | ||
32 | const res = await getOEmbed(server.url, oembedUrl) | 69 | const res = await getOEmbed(server.url, oembedUrl) |
@@ -37,7 +74,7 @@ describe('Test services', function () { | |||
37 | 74 | ||
38 | expect(res.body.html).to.equal(expectedHtml) | 75 | expect(res.body.html).to.equal(expectedHtml) |
39 | expect(res.body.title).to.equal(server.video.name) | 76 | expect(res.body.title).to.equal(server.video.name) |
40 | expect(res.body.author_name).to.equal(server.video.account.name) | 77 | expect(res.body.author_name).to.equal(server.videoChannel.displayName) |
41 | expect(res.body.width).to.equal(560) | 78 | expect(res.body.width).to.equal(560) |
42 | expect(res.body.height).to.equal(315) | 79 | expect(res.body.height).to.equal(315) |
43 | expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) | 80 | expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) |
@@ -45,6 +82,24 @@ describe('Test services', function () { | |||
45 | expect(res.body.thumbnail_height).to.equal(480) | 82 | expect(res.body.thumbnail_height).to.equal(480) |
46 | }) | 83 | }) |
47 | 84 | ||
85 | it('Should have a valid playlist oEmbed response', async function () { | ||
86 | const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/playlist/' + playlistUUID | ||
87 | |||
88 | const res = await getOEmbed(server.url, oembedUrl) | ||
89 | const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' + | ||
90 | `src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` + | ||
91 | 'frameborder="0" allowfullscreen></iframe>' | ||
92 | |||
93 | expect(res.body.html).to.equal(expectedHtml) | ||
94 | expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck') | ||
95 | expect(res.body.author_name).to.equal(server.videoChannel.displayName) | ||
96 | expect(res.body.width).to.equal(560) | ||
97 | expect(res.body.height).to.equal(315) | ||
98 | expect(res.body.thumbnail_url).exist | ||
99 | expect(res.body.thumbnail_width).to.equal(223) | ||
100 | expect(res.body.thumbnail_height).to.equal(122) | ||
101 | }) | ||
102 | |||
48 | it('Should have a valid oEmbed response with small max height query', async function () { | 103 | it('Should have a valid oEmbed response with small max height query', async function () { |
49 | const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid | 104 | const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + server.video.uuid |
50 | const format = 'json' | 105 | const format = 'json' |
@@ -58,7 +113,7 @@ describe('Test services', function () { | |||
58 | 113 | ||
59 | expect(res.body.html).to.equal(expectedHtml) | 114 | expect(res.body.html).to.equal(expectedHtml) |
60 | expect(res.body.title).to.equal(server.video.name) | 115 | expect(res.body.title).to.equal(server.video.name) |
61 | expect(res.body.author_name).to.equal(server.video.account.name) | 116 | expect(res.body.author_name).to.equal(server.videoChannel.displayName) |
62 | expect(res.body.height).to.equal(50) | 117 | expect(res.body.height).to.equal(50) |
63 | expect(res.body.width).to.equal(50) | 118 | expect(res.body.width).to.equal(50) |
64 | expect(res.body).to.not.have.property('thumbnail_url') | 119 | expect(res.body).to.not.have.property('thumbnail_url') |