aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/api/check-params
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-08-28 10:55:04 +0200
committerChocobozzz <me@florianbigard.com>2023-08-28 16:17:31 +0200
commit77b70702d2193d78bf6fbd07f0fc7335e34957f8 (patch)
tree1a0aed540054286c9a8b10c4890cc0f718e00458 /packages/tests/src/api/check-params
parent7113f32a87bd6b2868154fed20bde1a1633c190e (diff)
downloadPeerTube-77b70702d2193d78bf6fbd07f0fc7335e34957f8.tar.gz
PeerTube-77b70702d2193d78bf6fbd07f0fc7335e34957f8.tar.zst
PeerTube-77b70702d2193d78bf6fbd07f0fc7335e34957f8.zip
Add video chapters support
Diffstat (limited to 'packages/tests/src/api/check-params')
-rw-r--r--packages/tests/src/api/check-params/index.ts1
-rw-r--r--packages/tests/src/api/check-params/video-captions.ts23
-rw-r--r--packages/tests/src/api/check-params/video-chapters.ts172
3 files changed, 187 insertions, 9 deletions
diff --git a/packages/tests/src/api/check-params/index.ts b/packages/tests/src/api/check-params/index.ts
index ed5fe6b06..d7867e8a5 100644
--- a/packages/tests/src/api/check-params/index.ts
+++ b/packages/tests/src/api/check-params/index.ts
@@ -30,6 +30,7 @@ import './video-blacklist.js'
30import './video-captions.js' 30import './video-captions.js'
31import './video-channel-syncs.js' 31import './video-channel-syncs.js'
32import './video-channels.js' 32import './video-channels.js'
33import './video-chapters.js'
33import './video-comments.js' 34import './video-comments.js'
34import './video-files.js' 35import './video-files.js'
35import './video-imports.js' 36import './video-imports.js'
diff --git a/packages/tests/src/api/check-params/video-captions.ts b/packages/tests/src/api/check-params/video-captions.ts
index 4150b095f..ac4e85068 100644
--- a/packages/tests/src/api/check-params/video-captions.ts
+++ b/packages/tests/src/api/check-params/video-captions.ts
@@ -31,15 +31,7 @@ describe('Test video captions API validator', function () {
31 31
32 video = await server.videos.upload() 32 video = await server.videos.upload()
33 privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } }) 33 privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } })
34 34 userAccessToken = await server.users.generateUserAndToken('user1')
35 {
36 const user = {
37 username: 'user1',
38 password: 'my super password'
39 }
40 await server.users.create({ username: user.username, password: user.password })
41 userAccessToken = await server.login.getAccessToken(user)
42 }
43 }) 35 })
44 36
45 describe('When adding video caption', function () { 37 describe('When adding video caption', function () {
@@ -120,6 +112,19 @@ describe('Test video captions API validator', function () {
120 }) 112 })
121 }) 113 })
122 114
115 it('Should fail with another user token', async function () {
116 const captionPath = path + video.uuid + '/captions/fr'
117 await makeUploadRequest({
118 method: 'PUT',
119 url: server.url,
120 path: captionPath,
121 token: userAccessToken,
122 fields,
123 attaches,
124 expectedStatus: HttpStatusCode.FORBIDDEN_403
125 })
126 })
127
123 // We accept any file now 128 // We accept any file now
124 // it('Should fail with an invalid captionfile extension', async function () { 129 // it('Should fail with an invalid captionfile extension', async function () {
125 // const attaches = { 130 // const attaches = {
diff --git a/packages/tests/src/api/check-params/video-chapters.ts b/packages/tests/src/api/check-params/video-chapters.ts
new file mode 100644
index 000000000..c59f88e79
--- /dev/null
+++ b/packages/tests/src/api/check-params/video-chapters.ts
@@ -0,0 +1,172 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { HttpStatusCode, Video, VideoCreateResult, VideoPrivacy } from '@peertube/peertube-models'
4import {
5 PeerTubeServer,
6 cleanupTests,
7 createSingleServer,
8 setAccessTokensToServers,
9 setDefaultVideoChannel
10} from '@peertube/peertube-server-commands'
11
12describe('Test videos chapters API validator', function () {
13 let server: PeerTubeServer
14 let video: VideoCreateResult
15 let live: Video
16 let privateVideo: VideoCreateResult
17 let userAccessToken: string
18
19 // ---------------------------------------------------------------
20
21 before(async function () {
22 this.timeout(30000)
23
24 server = await createSingleServer(1)
25
26 await setAccessTokensToServers([ server ])
27 await setDefaultVideoChannel([ server ])
28
29 video = await server.videos.upload()
30 privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } })
31 userAccessToken = await server.users.generateUserAndToken('user1')
32
33 await server.config.enableLive({ allowReplay: false })
34
35 const res = await server.live.quickCreate({ saveReplay: false, permanentLive: false })
36 live = res.video
37 })
38
39 describe('When updating chapters', function () {
40
41 it('Should fail without a valid uuid', async function () {
42 await server.chapters.update({ videoId: '4da6fd', chapters: [], expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
43 })
44
45 it('Should fail with an unknown id', async function () {
46 await server.chapters.update({
47 videoId: 'ce0801ef-7124-48df-9b22-b473ace78797',
48 chapters: [],
49 expectedStatus: HttpStatusCode.NOT_FOUND_404
50 })
51 })
52
53 it('Should fail without access token', async function () {
54 await server.chapters.update({
55 videoId: video.id,
56 chapters: [],
57 token: null,
58 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
59 })
60 })
61
62 it('Should fail with a bad access token', async function () {
63 await server.chapters.update({
64 videoId: video.id,
65 chapters: [],
66 token: 'toto',
67 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
68 })
69 })
70
71 it('Should fail with a another user access token', async function () {
72 await server.chapters.update({
73 videoId: video.id,
74 chapters: [],
75 token: userAccessToken,
76 expectedStatus: HttpStatusCode.FORBIDDEN_403
77 })
78 })
79
80 it('Should fail with a wrong chapters param', async function () {
81 await server.chapters.update({
82 videoId: video.id,
83 chapters: 'hello' as any,
84 expectedStatus: HttpStatusCode.BAD_REQUEST_400
85 })
86 })
87
88 it('Should fail with a bad chapter title', async function () {
89 await server.chapters.update({
90 videoId: video.id,
91 chapters: [ { title: 'hello', timecode: 21 }, { title: '', timecode: 21 } ],
92 expectedStatus: HttpStatusCode.BAD_REQUEST_400
93 })
94
95 await server.chapters.update({
96 videoId: video.id,
97 chapters: [ { title: 'hello', timecode: 21 }, { title: 'a'.repeat(150), timecode: 21 } ],
98 expectedStatus: HttpStatusCode.BAD_REQUEST_400
99 })
100 })
101
102 it('Should fail with a bad timecode', async function () {
103 await server.chapters.update({
104 videoId: video.id,
105 chapters: [ { title: 'hello', timecode: 21 }, { title: 'title', timecode: -5 } ],
106 expectedStatus: HttpStatusCode.BAD_REQUEST_400
107 })
108
109 await server.chapters.update({
110 videoId: video.id,
111 chapters: [ { title: 'hello', timecode: 21 }, { title: 'title', timecode: 'hi' as any } ],
112 expectedStatus: HttpStatusCode.BAD_REQUEST_400
113 })
114 })
115
116 it('Should fail with non unique timecodes', async function () {
117 await server.chapters.update({
118 videoId: video.id,
119 chapters: [ { title: 'hello', timecode: 21 }, { title: 'title', timecode: 22 }, { title: 'hello', timecode: 21 } ],
120 expectedStatus: HttpStatusCode.BAD_REQUEST_400
121 })
122 })
123
124 it('Should fail to create chapters on a live', async function () {
125 await server.chapters.update({
126 videoId: live.id,
127 chapters: [],
128 expectedStatus: HttpStatusCode.BAD_REQUEST_400
129 })
130 })
131
132 it('Should succeed with the correct params', async function () {
133 await server.chapters.update({
134 videoId: video.id,
135 chapters: []
136 })
137
138 await server.chapters.update({
139 videoId: video.id,
140 chapters: [ { title: 'hello', timecode: 21 }, { title: 'hello 2', timecode: 35 } ]
141 })
142 })
143 })
144
145 describe('When listing chapters', function () {
146
147 it('Should fail without a valid uuid', async function () {
148 await server.chapters.list({ videoId: '4da6fd', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
149 })
150
151 it('Should fail with an unknown id', async function () {
152 await server.chapters.list({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
153 })
154
155 it('Should not list private chapters to anyone', async function () {
156 await server.chapters.list({ videoId: privateVideo.uuid, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
157 })
158
159 it('Should not list private chapters to another user', async function () {
160 await server.chapters.list({ videoId: privateVideo.uuid, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
161 })
162
163 it('Should list chapters', async function () {
164 await server.chapters.list({ videoId: privateVideo.uuid })
165 await server.chapters.list({ videoId: video.uuid })
166 })
167 })
168
169 after(async function () {
170 await cleanupTests([ server ])
171 })
172})