1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { HttpStatusCode } from '@shared/models'
6 buildAbsoluteFixturePath,
13 setAccessTokensToServers
14 } from '@shared/extra-utils'
15 import { VideoCreateResult } from '@shared/models'
17 describe('Test video captions API validator', function () {
18 const path = '/api/v1/videos/'
20 let server: PeerTubeServer
21 let userAccessToken: string
22 let video: VideoCreateResult
24 // ---------------------------------------------------------------
26 before(async function () {
29 server = await createSingleServer(1)
31 await setAccessTokensToServers([ server ])
33 video = await server.videos.upload()
38 password: 'my super password'
40 await server.users.create({ username: user.username, password: user.password })
41 userAccessToken = await server.login.getAccessToken(user)
45 describe('When adding video caption', function () {
48 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
51 it('Should fail without a valid uuid', async function () {
52 await makeUploadRequest({
55 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
56 token: server.accessToken,
62 it('Should fail with an unknown id', async function () {
63 await makeUploadRequest({
66 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
67 token: server.accessToken,
74 it('Should fail with a missing language in path', async function () {
75 const captionPath = path + video.uuid + '/captions'
76 await makeUploadRequest({
80 token: server.accessToken,
86 it('Should fail with an unknown language', async function () {
87 const captionPath = path + video.uuid + '/captions/15'
88 await makeUploadRequest({
92 token: server.accessToken,
98 it('Should fail without access token', async function () {
99 const captionPath = path + video.uuid + '/captions/fr'
100 await makeUploadRequest({
106 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
110 it('Should fail with a bad access token', async function () {
111 const captionPath = path + video.uuid + '/captions/fr'
112 await makeUploadRequest({
119 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
123 // We accept any file now
124 // it('Should fail with an invalid captionfile extension', async function () {
125 // const attaches = {
126 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
129 // const captionPath = path + video.uuid + '/captions/fr'
130 // await makeUploadRequest({
133 // path: captionPath,
134 // token: server.accessToken,
137 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
141 // We don't check the extension yet
142 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
143 // await createVideoCaption({
145 // accessToken: server.accessToken,
147 // videoId: video.uuid,
148 // fixture: 'subtitle-bad.txt',
149 // mimeType: 'application/octet-stream',
150 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
154 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
155 await server.captions.createVideoCaption({
158 fixture: 'subtitle-good.srt',
159 mimeType: 'application/octet-stream'
163 // We don't check the file validity yet
164 // it('Should fail with an invalid captionfile srt', async function () {
165 // const attaches = {
166 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
169 // const captionPath = path + video.uuid + '/captions/fr'
170 // await makeUploadRequest({
173 // path: captionPath,
174 // token: server.accessToken,
177 // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500
181 it('Should success with the correct parameters', async function () {
182 const captionPath = path + video.uuid + '/captions/fr'
183 await makeUploadRequest({
187 token: server.accessToken,
190 expectedStatus: HttpStatusCode.NO_CONTENT_204
195 describe('When listing video captions', function () {
196 it('Should fail without a valid uuid', async function () {
197 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
200 it('Should fail with an unknown id', async function () {
201 await makeGetRequest({
203 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
204 expectedStatus: HttpStatusCode.NOT_FOUND_404
208 it('Should success with the correct parameters', async function () {
209 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 })
213 describe('When deleting video caption', function () {
214 it('Should fail without a valid uuid', async function () {
215 await makeDeleteRequest({
217 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
218 token: server.accessToken
222 it('Should fail with an unknown id', async function () {
223 await makeDeleteRequest({
225 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
226 token: server.accessToken,
227 expectedStatus: HttpStatusCode.NOT_FOUND_404
231 it('Should fail with an invalid language', async function () {
232 await makeDeleteRequest({
234 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
235 token: server.accessToken
239 it('Should fail with a missing language', async function () {
240 const captionPath = path + video.shortUUID + '/captions'
241 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
244 it('Should fail with an unknown language', async function () {
245 const captionPath = path + video.shortUUID + '/captions/15'
246 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
249 it('Should fail without access token', async function () {
250 const captionPath = path + video.shortUUID + '/captions/fr'
251 await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
254 it('Should fail with a bad access token', async function () {
255 const captionPath = path + video.shortUUID + '/captions/fr'
256 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
259 it('Should fail with another user', async function () {
260 const captionPath = path + video.shortUUID + '/captions/fr'
261 await makeDeleteRequest({
264 token: userAccessToken,
265 expectedStatus: HttpStatusCode.FORBIDDEN_403
269 it('Should success with the correct parameters', async function () {
270 const captionPath = path + video.shortUUID + '/captions/fr'
271 await makeDeleteRequest({
274 token: server.accessToken,
275 expectedStatus: HttpStatusCode.NO_CONTENT_204
280 after(async function () {
281 await cleanupTests([ server ])