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