1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 buildAbsoluteFixturePath,
12 setAccessTokensToServers
13 } from '@shared/extra-utils'
14 import { HttpStatusCode, VideoCreateResult } from '@shared/models'
16 describe('Test video captions API validator', function () {
17 const path = '/api/v1/videos/'
19 let server: PeerTubeServer
20 let userAccessToken: string
21 let video: VideoCreateResult
23 // ---------------------------------------------------------------
25 before(async function () {
28 server = await createSingleServer(1)
30 await setAccessTokensToServers([ server ])
32 video = await server.videos.upload()
37 password: 'my super password'
39 await server.users.create({ username: user.username, password: user.password })
40 userAccessToken = await server.login.getAccessToken(user)
44 describe('When adding video caption', function () {
47 captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt')
50 it('Should fail without a valid uuid', async function () {
51 await makeUploadRequest({
54 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
55 token: server.accessToken,
61 it('Should fail with an unknown id', async function () {
62 await makeUploadRequest({
65 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
66 token: server.accessToken,
73 it('Should fail with a missing language in path', async function () {
74 const captionPath = path + video.uuid + '/captions'
75 await makeUploadRequest({
79 token: server.accessToken,
85 it('Should fail with an unknown language', async function () {
86 const captionPath = path + video.uuid + '/captions/15'
87 await makeUploadRequest({
91 token: server.accessToken,
97 it('Should fail without access token', async function () {
98 const captionPath = path + video.uuid + '/captions/fr'
99 await makeUploadRequest({
105 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
109 it('Should fail with a bad access token', async function () {
110 const captionPath = path + video.uuid + '/captions/fr'
111 await makeUploadRequest({
118 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
122 // We accept any file now
123 // it('Should fail with an invalid captionfile extension', async function () {
124 // const attaches = {
125 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt')
128 // const captionPath = path + video.uuid + '/captions/fr'
129 // await makeUploadRequest({
132 // path: captionPath,
133 // token: server.accessToken,
136 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
140 // We don't check the extension yet
141 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
142 // await createVideoCaption({
144 // accessToken: server.accessToken,
146 // videoId: video.uuid,
147 // fixture: 'subtitle-bad.txt',
148 // mimeType: 'application/octet-stream',
149 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
153 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
154 await server.captions.add({
157 fixture: 'subtitle-good.srt',
158 mimeType: 'application/octet-stream'
162 // We don't check the file validity yet
163 // it('Should fail with an invalid captionfile srt', async function () {
164 // const attaches = {
165 // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt')
168 // const captionPath = path + video.uuid + '/captions/fr'
169 // await makeUploadRequest({
172 // path: captionPath,
173 // token: server.accessToken,
176 // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500
180 it('Should success with the correct parameters', async function () {
181 const captionPath = path + video.uuid + '/captions/fr'
182 await makeUploadRequest({
186 token: server.accessToken,
189 expectedStatus: HttpStatusCode.NO_CONTENT_204
194 describe('When listing video captions', function () {
195 it('Should fail without a valid uuid', async function () {
196 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' })
199 it('Should fail with an unknown id', async function () {
200 await makeGetRequest({
202 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
203 expectedStatus: HttpStatusCode.NOT_FOUND_404
207 it('Should success with the correct parameters', async function () {
208 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 })
212 describe('When deleting video caption', function () {
213 it('Should fail without a valid uuid', async function () {
214 await makeDeleteRequest({
216 path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr',
217 token: server.accessToken
221 it('Should fail with an unknown id', async function () {
222 await makeDeleteRequest({
224 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
225 token: server.accessToken,
226 expectedStatus: HttpStatusCode.NOT_FOUND_404
230 it('Should fail with an invalid language', async function () {
231 await makeDeleteRequest({
233 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16',
234 token: server.accessToken
238 it('Should fail with a missing language', async function () {
239 const captionPath = path + video.shortUUID + '/captions'
240 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
243 it('Should fail with an unknown language', async function () {
244 const captionPath = path + video.shortUUID + '/captions/15'
245 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken })
248 it('Should fail without access token', async function () {
249 const captionPath = path + video.shortUUID + '/captions/fr'
250 await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
253 it('Should fail with a bad access token', async function () {
254 const captionPath = path + video.shortUUID + '/captions/fr'
255 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
258 it('Should fail with another user', async function () {
259 const captionPath = path + video.shortUUID + '/captions/fr'
260 await makeDeleteRequest({
263 token: userAccessToken,
264 expectedStatus: HttpStatusCode.FORBIDDEN_403
268 it('Should success with the correct parameters', async function () {
269 const captionPath = path + video.shortUUID + '/captions/fr'
270 await makeDeleteRequest({
273 token: server.accessToken,
274 expectedStatus: HttpStatusCode.NO_CONTENT_204
279 after(async function () {
280 await cleanupTests([ server ])