]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/services.ts
Fix s3 mock cleanup
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / services.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
d8755eed 2
b3d9dedc 3import { HttpStatusCode, VideoCreateResult, VideoPlaylistCreateResult, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
9639bd17 4import {
7c3b7976 5 cleanupTests,
254d3579 6 createSingleServer,
7c3b7976 7 makeGetRequest,
254d3579 8 PeerTubeServer,
9639bd17 9 setAccessTokensToServers,
d23dd9fb 10 setDefaultVideoChannel
bf54587a 11} from '@shared/server-commands'
d8755eed
C
12
13describe('Test services API validators', function () {
254d3579 14 let server: PeerTubeServer
6fad8e51 15 let playlistUUID: string
d8755eed 16
b3d9dedc
C
17 let privateVideo: VideoCreateResult
18 let unlistedVideo: VideoCreateResult
19
20 let privatePlaylist: VideoPlaylistCreateResult
21 let unlistedPlaylist: VideoPlaylistCreateResult
22
d8755eed
C
23 // ---------------------------------------------------------------
24
25 before(async function () {
26 this.timeout(60000)
27
254d3579 28 server = await createSingleServer(1)
d8755eed 29 await setAccessTokensToServers([ server ])
6fad8e51
C
30 await setDefaultVideoChannel([ server ])
31
83903cb6 32 server.store.videoCreated = await server.videos.upload({ attributes: { name: 'my super name' } })
6fad8e51 33
b3d9dedc
C
34 privateVideo = await server.videos.quickUpload({ name: 'private', privacy: VideoPrivacy.PRIVATE })
35 unlistedVideo = await server.videos.quickUpload({ name: 'unlisted', privacy: VideoPrivacy.UNLISTED })
36
6fad8e51 37 {
89d241a7 38 const created = await server.playlists.create({
e6346d59 39 attributes: {
6fad8e51
C
40 displayName: 'super playlist',
41 privacy: VideoPlaylistPrivacy.PUBLIC,
89d241a7 42 videoChannelId: server.store.channel.id
6fad8e51
C
43 }
44 })
45
e6346d59 46 playlistUUID = created.uuid
b3d9dedc
C
47
48 privatePlaylist = await server.playlists.create({
49 attributes: {
50 displayName: 'private',
51 privacy: VideoPlaylistPrivacy.PRIVATE,
52 videoChannelId: server.store.channel.id
53 }
54 })
55
56 unlistedPlaylist = await server.playlists.create({
57 attributes: {
58 displayName: 'unlisted',
59 privacy: VideoPlaylistPrivacy.UNLISTED,
60 videoChannelId: server.store.channel.id
61 }
62 })
6fad8e51 63 }
d8755eed
C
64 })
65
66 describe('Test oEmbed API validators', function () {
d8755eed
C
67
68 it('Should fail with an invalid url', async function () {
69 const embedUrl = 'hello.com'
331128ed 70 await checkParamEmbed(server, embedUrl)
d8755eed
C
71 })
72
73 it('Should fail with an invalid host', async function () {
83903cb6 74 const embedUrl = 'http://hello.com/videos/watch/' + server.store.videoCreated.uuid
331128ed 75 await checkParamEmbed(server, embedUrl)
d8755eed
C
76 })
77
6fad8e51 78 it('Should fail with an invalid element id', async function () {
2732eeff 79 const embedUrl = `${server.url}/videos/watch/blabla`
331128ed 80 await checkParamEmbed(server, embedUrl)
d8755eed
C
81 })
82
6fad8e51 83 it('Should fail with an unknown element', async function () {
2732eeff 84 const embedUrl = `${server.url}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
2d53be02 85 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404)
d8755eed
C
86 })
87
88 it('Should fail with an invalid path', async function () {
2732eeff 89 const embedUrl = `${server.url}/videos/watchs/${server.store.videoCreated.uuid}`
d8755eed 90
331128ed 91 await checkParamEmbed(server, embedUrl)
d8755eed
C
92 })
93
94 it('Should fail with an invalid max height', async function () {
2732eeff 95 const embedUrl = `${server.url}/videos/watch/${server.store.videoCreated.uuid}`
d8755eed 96
2d53be02 97 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
d8755eed
C
98 })
99
100 it('Should fail with an invalid max width', async function () {
2732eeff 101 const embedUrl = `${server.url}/videos/watch/${server.store.videoCreated.uuid}`
d8755eed 102
2d53be02 103 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
d8755eed
C
104 })
105
106 it('Should fail with an invalid format', async function () {
2732eeff 107 const embedUrl = `${server.url}/videos/watch/${server.store.videoCreated.uuid}`
d8755eed 108
2d53be02 109 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
d8755eed
C
110 })
111
112 it('Should fail with a non supported format', async function () {
2732eeff 113 const embedUrl = `${server.url}/videos/watch/${server.store.videoCreated.uuid}`
d8755eed 114
2d53be02 115 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
331128ed
C
116 })
117
b3d9dedc 118 it('Should fail with a private video', async function () {
2732eeff 119 const embedUrl = `${server.url}/videos/watch/${privateVideo.uuid}`
b3d9dedc
C
120
121 await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403)
122 })
123
124 it('Should fail with an unlisted video with the int id', async function () {
2732eeff 125 const embedUrl = `${server.url}/videos/watch/${unlistedVideo.id}`
b3d9dedc
C
126
127 await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403)
128 })
129
130 it('Should succeed with an unlisted video using the uuid id', async function () {
131 for (const uuid of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) {
2732eeff 132 const embedUrl = `${server.url}/videos/watch/${uuid}`
b3d9dedc
C
133
134 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200)
135 }
136 })
137
138 it('Should fail with a private playlist', async function () {
2732eeff 139 const embedUrl = `${server.url}/videos/watch/playlist/${privatePlaylist.uuid}`
b3d9dedc
C
140
141 await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403)
142 })
143
144 it('Should fail with an unlisted playlist using the int id', async function () {
2732eeff 145 const embedUrl = `${server.url}/videos/watch/playlist/${unlistedPlaylist.id}`
b3d9dedc
C
146
147 await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403)
148 })
149
150 it('Should succeed with an unlisted playlist using the uuid id', async function () {
151 for (const uuid of [ unlistedPlaylist.uuid, unlistedPlaylist.shortUUID ]) {
2732eeff 152 const embedUrl = `${server.url}/videos/watch/playlist/${uuid}`
b3d9dedc
C
153
154 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200)
155 }
156 })
157
6fad8e51 158 it('Should succeed with the correct params with a video', async function () {
2732eeff 159 const embedUrl = `${server.url}/videos/watch/${server.store.videoCreated.uuid}`
331128ed
C
160 const query = {
161 format: 'json',
162 maxheight: 400,
163 maxwidth: 400
164 }
165
2d53be02 166 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
d8755eed 167 })
6fad8e51
C
168
169 it('Should succeed with the correct params with a playlist', async function () {
2732eeff 170 const embedUrl = `${server.url}/videos/watch/playlist/${playlistUUID}`
6fad8e51
C
171 const query = {
172 format: 'json',
173 maxheight: 400,
174 maxwidth: 400
175 }
176
2d53be02 177 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
6fad8e51 178 })
d8755eed
C
179 })
180
7c3b7976
C
181 after(async function () {
182 await cleanupTests([ server ])
d8755eed
C
183 })
184})
331128ed 185
c0e8b12e 186function checkParamEmbed (server: PeerTubeServer, embedUrl: string, expectedStatus = HttpStatusCode.BAD_REQUEST_400, query = {}) {
331128ed
C
187 const path = '/services/oembed'
188
189 return makeGetRequest({
190 url: server.url,
191 path,
192 query: Object.assign(query, { url: embedUrl }),
c0e8b12e 193 expectedStatus
331128ed
C
194 })
195}