]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
e2e22e40 | 2 | |
47564bbe | 3 | import * as chai from 'chai' |
e2e22e40 | 4 | import 'mocha' |
11ba2ab3 | 5 | import { |
7c3b7976 | 6 | cleanupTests, |
4cb6d457 | 7 | createUser, |
42e1ec25 | 8 | flushAndRunServer, |
42e1ec25 C |
9 | makeDeleteRequest, |
10 | makeGetRequest, | |
11 | makePostBodyRequest, | |
12 | ServerInfo, | |
13 | setAccessTokensToServers, | |
14 | uploadVideo, | |
15 | userLogin | |
94565d52 | 16 | } from '../../../../shared/extra-utils' |
9639bd17 | 17 | import { |
18 | checkBadCountPagination, | |
19 | checkBadSortPagination, | |
20 | checkBadStartPagination | |
94565d52 C |
21 | } from '../../../../shared/extra-utils/requests/check-api-params' |
22 | import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | |
e2e22e40 | 23 | |
47564bbe C |
24 | const expect = chai.expect |
25 | ||
e2e22e40 C |
26 | describe('Test video comments API validator', function () { |
27 | let pathThread: string | |
28 | let pathComment: string | |
29 | let server: ServerInfo | |
e2e22e40 | 30 | let videoUUID: string |
4cb6d457 | 31 | let userAccessToken: string |
e2e22e40 C |
32 | let commentId: number |
33 | ||
34 | // --------------------------------------------------------------- | |
35 | ||
36 | before(async function () { | |
e212f887 | 37 | this.timeout(30000) |
e2e22e40 | 38 | |
210feb6c | 39 | server = await flushAndRunServer(1) |
e2e22e40 C |
40 | |
41 | await setAccessTokensToServers([ server ]) | |
42 | ||
e2e22e40 C |
43 | { |
44 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
45 | videoUUID = res.body.video.uuid | |
46 | pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads' | |
47 | } | |
48 | ||
49 | { | |
50 | const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou') | |
51 | commentId = res.body.comment.id | |
52 | pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId | |
53 | } | |
4cb6d457 C |
54 | |
55 | { | |
56 | const user = { | |
57 | username: 'user1', | |
58 | password: 'my super password' | |
59 | } | |
1eddc9a7 | 60 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
4cb6d457 C |
61 | userAccessToken = await userLogin(server, user) |
62 | } | |
e2e22e40 C |
63 | }) |
64 | ||
65 | describe('When listing video comment threads', function () { | |
66 | it('Should fail with a bad start pagination', async function () { | |
11ba2ab3 | 67 | await checkBadStartPagination(server.url, pathThread, server.accessToken) |
e2e22e40 C |
68 | }) |
69 | ||
70 | it('Should fail with a bad count pagination', async function () { | |
11ba2ab3 | 71 | await checkBadCountPagination(server.url, pathThread, server.accessToken) |
e2e22e40 C |
72 | }) |
73 | ||
74 | it('Should fail with an incorrect sort', async function () { | |
11ba2ab3 | 75 | await checkBadSortPagination(server.url, pathThread, server.accessToken) |
e2e22e40 C |
76 | }) |
77 | ||
78 | it('Should fail with an incorrect video', async function () { | |
11ba2ab3 C |
79 | await makeGetRequest({ |
80 | url: server.url, | |
81 | path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', | |
82 | statusCodeExpected: 404 | |
83 | }) | |
e2e22e40 C |
84 | }) |
85 | }) | |
86 | ||
87 | describe('When listing comments of a thread', function () { | |
88 | it('Should fail with an incorrect video', async function () { | |
11ba2ab3 C |
89 | await makeGetRequest({ |
90 | url: server.url, | |
91 | path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, | |
92 | statusCodeExpected: 404 | |
93 | }) | |
e2e22e40 C |
94 | }) |
95 | ||
96 | it('Should fail with an incorrect thread id', async function () { | |
11ba2ab3 C |
97 | await makeGetRequest({ |
98 | url: server.url, | |
99 | path: '/api/v1/videos/' + videoUUID + '/comment-threads/156', | |
100 | statusCodeExpected: 404 | |
101 | }) | |
e2e22e40 C |
102 | }) |
103 | ||
104 | it('Should success with the correct params', async function () { | |
11ba2ab3 C |
105 | await makeGetRequest({ |
106 | url: server.url, | |
107 | path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId, | |
108 | statusCodeExpected: 200 | |
109 | }) | |
e2e22e40 C |
110 | }) |
111 | }) | |
112 | ||
113 | describe('When adding a video thread', function () { | |
114 | ||
115 | it('Should fail with a non authenticated user', async function () { | |
116 | const fields = { | |
117 | text: 'text' | |
118 | } | |
119 | await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 }) | |
120 | }) | |
121 | ||
122 | it('Should fail with nothing', async function () { | |
123 | const fields = {} | |
124 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | |
125 | }) | |
126 | ||
127 | it('Should fail with a short comment', async function () { | |
128 | const fields = { | |
53eb90c0 | 129 | text: '' |
e2e22e40 C |
130 | } |
131 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | |
132 | }) | |
133 | ||
134 | it('Should fail with a long comment', async function () { | |
135 | const fields = { | |
136 | text: 'h'.repeat(3001) | |
137 | } | |
138 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | |
139 | }) | |
140 | ||
141 | it('Should fail with an incorrect video', async function () { | |
142 | const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads' | |
143 | const fields = { | |
144 | text: 'super comment' | |
145 | } | |
146 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | |
147 | }) | |
148 | ||
149 | it('Should succeed with the correct parameters', async function () { | |
150 | const fields = { | |
151 | text: 'super comment' | |
152 | } | |
153 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 }) | |
154 | }) | |
155 | }) | |
156 | ||
157 | describe('When adding a comment to a thread', function () { | |
158 | it('Should fail with a non authenticated user', async function () { | |
159 | const fields = { | |
160 | text: 'text' | |
161 | } | |
162 | await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 }) | |
163 | }) | |
164 | ||
165 | it('Should fail with nothing', async function () { | |
166 | const fields = {} | |
167 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | |
168 | }) | |
169 | ||
170 | it('Should fail with a short comment', async function () { | |
171 | const fields = { | |
53eb90c0 | 172 | text: '' |
e2e22e40 C |
173 | } |
174 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | |
175 | }) | |
176 | ||
177 | it('Should fail with a long comment', async function () { | |
178 | const fields = { | |
179 | text: 'h'.repeat(3001) | |
180 | } | |
181 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | |
182 | }) | |
183 | ||
184 | it('Should fail with an incorrect video', async function () { | |
185 | const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId | |
186 | const fields = { | |
187 | text: 'super comment' | |
188 | } | |
189 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | |
190 | }) | |
191 | ||
192 | it('Should fail with an incorrect comment', async function () { | |
193 | const path = '/api/v1/videos/' + videoUUID + '/comments/124' | |
194 | const fields = { | |
195 | text: 'super comment' | |
196 | } | |
197 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | |
198 | }) | |
199 | ||
200 | it('Should succeed with the correct parameters', async function () { | |
201 | const fields = { | |
202 | text: 'super comment' | |
203 | } | |
204 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 }) | |
205 | }) | |
206 | }) | |
207 | ||
4cb6d457 C |
208 | describe('When removing video comments', function () { |
209 | it('Should fail with a non authenticated user', async function () { | |
210 | await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 }) | |
211 | }) | |
212 | ||
213 | it('Should fail with another user', async function () { | |
214 | await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 }) | |
215 | }) | |
216 | ||
217 | it('Should fail with an incorrect video', async function () { | |
218 | const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId | |
219 | await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) | |
220 | }) | |
221 | ||
222 | it('Should fail with an incorrect comment', async function () { | |
223 | const path = '/api/v1/videos/' + videoUUID + '/comments/124' | |
224 | await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) | |
225 | }) | |
226 | ||
227 | it('Should succeed with the correct parameters', async function () { | |
228 | await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 }) | |
229 | }) | |
230 | }) | |
231 | ||
47564bbe C |
232 | describe('When a video has comments disabled', function () { |
233 | before(async function () { | |
234 | const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) | |
235 | videoUUID = res.body.video.uuid | |
236 | pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads' | |
237 | }) | |
238 | ||
239 | it('Should return an empty thread list', async function () { | |
240 | const res = await makeGetRequest({ | |
241 | url: server.url, | |
242 | path: pathThread, | |
243 | statusCodeExpected: 200 | |
244 | }) | |
245 | expect(res.body.total).to.equal(0) | |
246 | expect(res.body.data).to.have.lengthOf(0) | |
247 | }) | |
248 | ||
249 | it('Should return an thread comments list') | |
250 | ||
251 | it('Should return conflict on thread add', async function () { | |
252 | const fields = { | |
253 | text: 'super comment' | |
254 | } | |
255 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
256 | }) | |
257 | ||
258 | it('Should return conflict on comment thread add') | |
259 | }) | |
260 | ||
7c3b7976 C |
261 | after(async function () { |
262 | await cleanupTests([ server ]) | |
e2e22e40 C |
263 | }) |
264 | }) |