]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
d8755eed | 2 | |
d8755eed | 3 | import 'mocha' |
9639bd17 | 4 | import { |
7c3b7976 | 5 | cleanupTests, |
254d3579 | 6 | createSingleServer, |
7c3b7976 | 7 | makeGetRequest, |
254d3579 | 8 | PeerTubeServer, |
9639bd17 | 9 | setAccessTokensToServers, |
d23dd9fb C |
10 | setDefaultVideoChannel |
11 | } from '@shared/extra-utils' | |
4c7e60bc | 12 | import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' |
d8755eed C |
13 | |
14 | describe('Test services API validators', function () { | |
254d3579 | 15 | let server: PeerTubeServer |
6fad8e51 | 16 | let playlistUUID: string |
d8755eed C |
17 | |
18 | // --------------------------------------------------------------- | |
19 | ||
20 | before(async function () { | |
21 | this.timeout(60000) | |
22 | ||
254d3579 | 23 | server = await createSingleServer(1) |
d8755eed | 24 | await setAccessTokensToServers([ server ]) |
6fad8e51 C |
25 | await setDefaultVideoChannel([ server ]) |
26 | ||
83903cb6 | 27 | server.store.videoCreated = await server.videos.upload({ attributes: { name: 'my super name' } }) |
6fad8e51 C |
28 | |
29 | { | |
89d241a7 | 30 | const created = await server.playlists.create({ |
e6346d59 | 31 | attributes: { |
6fad8e51 C |
32 | displayName: 'super playlist', |
33 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 34 | videoChannelId: server.store.channel.id |
6fad8e51 C |
35 | } |
36 | }) | |
37 | ||
e6346d59 | 38 | playlistUUID = created.uuid |
6fad8e51 | 39 | } |
d8755eed C |
40 | }) |
41 | ||
42 | describe('Test oEmbed API validators', function () { | |
d8755eed C |
43 | |
44 | it('Should fail with an invalid url', async function () { | |
45 | const embedUrl = 'hello.com' | |
331128ed | 46 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
47 | }) |
48 | ||
49 | it('Should fail with an invalid host', async function () { | |
83903cb6 | 50 | const embedUrl = 'http://hello.com/videos/watch/' + server.store.videoCreated.uuid |
331128ed | 51 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
52 | }) |
53 | ||
6fad8e51 | 54 | it('Should fail with an invalid element id', async function () { |
7c3b7976 | 55 | const embedUrl = `http://localhost:${server.port}/videos/watch/blabla` |
331128ed | 56 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
57 | }) |
58 | ||
6fad8e51 | 59 | it('Should fail with an unknown element', async function () { |
7c3b7976 | 60 | const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` |
2d53be02 | 61 | await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404) |
d8755eed C |
62 | }) |
63 | ||
64 | it('Should fail with an invalid path', async function () { | |
83903cb6 | 65 | const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.videoCreated.uuid}` |
d8755eed | 66 | |
331128ed | 67 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
68 | }) |
69 | ||
70 | it('Should fail with an invalid max height', async function () { | |
83903cb6 | 71 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
d8755eed | 72 | |
2d53be02 | 73 | await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' }) |
d8755eed C |
74 | }) |
75 | ||
76 | it('Should fail with an invalid max width', async function () { | |
83903cb6 | 77 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
d8755eed | 78 | |
2d53be02 | 79 | await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' }) |
d8755eed C |
80 | }) |
81 | ||
82 | it('Should fail with an invalid format', async function () { | |
83903cb6 | 83 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
d8755eed | 84 | |
2d53be02 | 85 | await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' }) |
d8755eed C |
86 | }) |
87 | ||
88 | it('Should fail with a non supported format', async function () { | |
83903cb6 | 89 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
d8755eed | 90 | |
2d53be02 | 91 | await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' }) |
331128ed C |
92 | }) |
93 | ||
6fad8e51 | 94 | it('Should succeed with the correct params with a video', async function () { |
83903cb6 | 95 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
331128ed C |
96 | const query = { |
97 | format: 'json', | |
98 | maxheight: 400, | |
99 | maxwidth: 400 | |
100 | } | |
101 | ||
2d53be02 | 102 | await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query) |
d8755eed | 103 | }) |
6fad8e51 C |
104 | |
105 | it('Should succeed with the correct params with a playlist', async function () { | |
106 | const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}` | |
107 | const query = { | |
108 | format: 'json', | |
109 | maxheight: 400, | |
110 | maxwidth: 400 | |
111 | } | |
112 | ||
2d53be02 | 113 | await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query) |
6fad8e51 | 114 | }) |
d8755eed C |
115 | }) |
116 | ||
7c3b7976 C |
117 | after(async function () { |
118 | await cleanupTests([ server ]) | |
d8755eed C |
119 | }) |
120 | }) | |
331128ed | 121 | |
c0e8b12e | 122 | function checkParamEmbed (server: PeerTubeServer, embedUrl: string, expectedStatus = HttpStatusCode.BAD_REQUEST_400, query = {}) { |
331128ed C |
123 | const path = '/services/oembed' |
124 | ||
125 | return makeGetRequest({ | |
126 | url: server.url, | |
127 | path, | |
128 | query: Object.assign(query, { url: embedUrl }), | |
c0e8b12e | 129 | expectedStatus |
331128ed C |
130 | }) |
131 | } |