]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/user-subscriptions.ts
Generate random uuid for video files
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / user-subscriptions.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
06a05d5f
C
2
3import 'mocha'
06a05d5f 4import {
c0e8b12e
C
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
7c3b7976 8 cleanupTests,
254d3579 9 createSingleServer,
06a05d5f
C
10 makeDeleteRequest,
11 makeGetRequest,
12 makePostBodyRequest,
254d3579 13 PeerTubeServer,
c0e8b12e
C
14 setAccessTokensToServers,
15 waitJobs
16} from '@shared/extra-utils'
17import { HttpStatusCode } from '@shared/models'
06a05d5f
C
18
19describe('Test user subscriptions API validators', function () {
20 const path = '/api/v1/users/me/subscriptions'
254d3579 21 let server: PeerTubeServer
06a05d5f 22 let userAccessToken = ''
06a05d5f
C
23
24 // ---------------------------------------------------------------
25
26 before(async function () {
27 this.timeout(30000)
28
254d3579 29 server = await createSingleServer(1)
06a05d5f
C
30
31 await setAccessTokensToServers([ server ])
32
33 const user = {
34 username: 'user1',
35 password: 'my super password'
36 }
89d241a7
C
37 await server.users.create({ username: user.username, password: user.password })
38 userAccessToken = await server.login.getAccessToken(user)
06a05d5f
C
39 })
40
41 describe('When listing my subscriptions', function () {
42 it('Should fail with a bad start pagination', async function () {
43 await checkBadStartPagination(server.url, path, server.accessToken)
44 })
45
46 it('Should fail with a bad count pagination', async function () {
47 await checkBadCountPagination(server.url, path, server.accessToken)
48 })
49
50 it('Should fail with an incorrect sort', async function () {
51 await checkBadSortPagination(server.url, path, server.accessToken)
52 })
53
54 it('Should fail with a non authenticated user', async function () {
55 await makeGetRequest({
56 url: server.url,
57 path,
c0e8b12e 58 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
06a05d5f
C
59 })
60 })
61
99492dbc 62 it('Should succeed with the correct parameters', async function () {
8a19bee1 63 await makeGetRequest({
06a05d5f
C
64 url: server.url,
65 path,
66 token: userAccessToken,
c0e8b12e 67 expectedStatus: HttpStatusCode.OK_200
06a05d5f
C
68 })
69 })
70 })
71
72 describe('When listing my subscriptions videos', function () {
73 const path = '/api/v1/users/me/subscriptions/videos'
74
75 it('Should fail with a bad start pagination', async function () {
76 await checkBadStartPagination(server.url, path, server.accessToken)
77 })
78
79 it('Should fail with a bad count pagination', async function () {
80 await checkBadCountPagination(server.url, path, server.accessToken)
81 })
82
83 it('Should fail with an incorrect sort', async function () {
84 await checkBadSortPagination(server.url, path, server.accessToken)
85 })
86
87 it('Should fail with a non authenticated user', async function () {
88 await makeGetRequest({
89 url: server.url,
90 path,
c0e8b12e 91 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
06a05d5f
C
92 })
93 })
94
99492dbc 95 it('Should succeed with the correct parameters', async function () {
8a19bee1 96 await makeGetRequest({
06a05d5f
C
97 url: server.url,
98 path,
99 token: userAccessToken,
c0e8b12e 100 expectedStatus: HttpStatusCode.OK_200
06a05d5f
C
101 })
102 })
103 })
104
105 describe('When adding a subscription', function () {
106 it('Should fail with a non authenticated user', async function () {
107 await makePostBodyRequest({
108 url: server.url,
109 path,
7c3b7976 110 fields: { uri: 'user1_channel@localhost:' + server.port },
c0e8b12e 111 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
06a05d5f
C
112 })
113 })
114
115 it('Should fail with bad URIs', async function () {
116 await makePostBodyRequest({
117 url: server.url,
118 path,
119 token: server.accessToken,
120 fields: { uri: 'root' },
c0e8b12e 121 expectedStatus: HttpStatusCode.BAD_REQUEST_400
06a05d5f
C
122 })
123
124 await makePostBodyRequest({
125 url: server.url,
126 path,
127 token: server.accessToken,
128 fields: { uri: 'root@' },
c0e8b12e 129 expectedStatus: HttpStatusCode.BAD_REQUEST_400
06a05d5f
C
130 })
131
132 await makePostBodyRequest({
133 url: server.url,
134 path,
135 token: server.accessToken,
136 fields: { uri: 'root@hello@' },
c0e8b12e 137 expectedStatus: HttpStatusCode.BAD_REQUEST_400
06a05d5f
C
138 })
139 })
140
99492dbc 141 it('Should succeed with the correct parameters', async function () {
8d1fa36a
C
142 this.timeout(20000)
143
06a05d5f
C
144 await makePostBodyRequest({
145 url: server.url,
146 path,
147 token: server.accessToken,
7c3b7976 148 fields: { uri: 'user1_channel@localhost:' + server.port },
c0e8b12e 149 expectedStatus: HttpStatusCode.NO_CONTENT_204
06a05d5f 150 })
8d1fa36a
C
151
152 await waitJobs([ server ])
06a05d5f
C
153 })
154 })
155
99492dbc
C
156 describe('When getting a subscription', function () {
157 it('Should fail with a non authenticated user', async function () {
158 await makeGetRequest({
159 url: server.url,
7c3b7976 160 path: path + '/user1_channel@localhost:' + server.port,
c0e8b12e 161 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
99492dbc
C
162 })
163 })
164
165 it('Should fail with bad URIs', async function () {
166 await makeGetRequest({
167 url: server.url,
168 path: path + '/root',
169 token: server.accessToken,
c0e8b12e 170 expectedStatus: HttpStatusCode.BAD_REQUEST_400
99492dbc
C
171 })
172
173 await makeGetRequest({
174 url: server.url,
175 path: path + '/root@',
176 token: server.accessToken,
c0e8b12e 177 expectedStatus: HttpStatusCode.BAD_REQUEST_400
99492dbc
C
178 })
179
180 await makeGetRequest({
181 url: server.url,
182 path: path + '/root@hello@',
183 token: server.accessToken,
c0e8b12e 184 expectedStatus: HttpStatusCode.BAD_REQUEST_400
99492dbc
C
185 })
186 })
187
188 it('Should fail with an unknown subscription', async function () {
189 await makeGetRequest({
190 url: server.url,
7c3b7976 191 path: path + '/root1@localhost:' + server.port,
99492dbc 192 token: server.accessToken,
c0e8b12e 193 expectedStatus: HttpStatusCode.NOT_FOUND_404
99492dbc
C
194 })
195 })
196
197 it('Should succeed with the correct parameters', async function () {
198 await makeGetRequest({
199 url: server.url,
7c3b7976 200 path: path + '/user1_channel@localhost:' + server.port,
99492dbc 201 token: server.accessToken,
c0e8b12e 202 expectedStatus: HttpStatusCode.OK_200
99492dbc
C
203 })
204 })
205 })
206
9b39106d 207 describe('When checking if subscriptions exist', function () {
f37dc0dd
C
208 const existPath = path + '/exist'
209
210 it('Should fail with a non authenticated user', async function () {
211 await makeGetRequest({
212 url: server.url,
213 path: existPath,
c0e8b12e 214 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
f37dc0dd
C
215 })
216 })
217
218 it('Should fail with bad URIs', async function () {
219 await makeGetRequest({
220 url: server.url,
221 path: existPath,
222 query: { uris: 'toto' },
223 token: server.accessToken,
c0e8b12e 224 expectedStatus: HttpStatusCode.BAD_REQUEST_400
f37dc0dd
C
225 })
226
227 await makeGetRequest({
228 url: server.url,
229 path: existPath,
230 query: { 'uris[]': 1 },
231 token: server.accessToken,
c0e8b12e 232 expectedStatus: HttpStatusCode.BAD_REQUEST_400
f37dc0dd
C
233 })
234 })
235
236 it('Should succeed with the correct parameters', async function () {
237 await makeGetRequest({
238 url: server.url,
239 path: existPath,
7c3b7976 240 query: { 'uris[]': 'coucou@localhost:' + server.port },
f37dc0dd 241 token: server.accessToken,
c0e8b12e 242 expectedStatus: HttpStatusCode.OK_200
f37dc0dd
C
243 })
244 })
245 })
246
06a05d5f
C
247 describe('When removing a subscription', function () {
248 it('Should fail with a non authenticated user', async function () {
249 await makeDeleteRequest({
250 url: server.url,
7c3b7976 251 path: path + '/user1_channel@localhost:' + server.port,
c0e8b12e 252 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
06a05d5f
C
253 })
254 })
255
256 it('Should fail with bad URIs', async function () {
257 await makeDeleteRequest({
258 url: server.url,
259 path: path + '/root',
260 token: server.accessToken,
c0e8b12e 261 expectedStatus: HttpStatusCode.BAD_REQUEST_400
06a05d5f
C
262 })
263
264 await makeDeleteRequest({
265 url: server.url,
266 path: path + '/root@',
267 token: server.accessToken,
c0e8b12e 268 expectedStatus: HttpStatusCode.BAD_REQUEST_400
06a05d5f
C
269 })
270
271 await makeDeleteRequest({
272 url: server.url,
273 path: path + '/root@hello@',
274 token: server.accessToken,
c0e8b12e 275 expectedStatus: HttpStatusCode.BAD_REQUEST_400
06a05d5f
C
276 })
277 })
278
279 it('Should fail with an unknown subscription', async function () {
280 await makeDeleteRequest({
281 url: server.url,
7c3b7976 282 path: path + '/root1@localhost:' + server.port,
06a05d5f 283 token: server.accessToken,
c0e8b12e 284 expectedStatus: HttpStatusCode.NOT_FOUND_404
06a05d5f
C
285 })
286 })
287
99492dbc 288 it('Should succeed with the correct parameters', async function () {
06a05d5f
C
289 await makeDeleteRequest({
290 url: server.url,
7c3b7976 291 path: path + '/user1_channel@localhost:' + server.port,
06a05d5f 292 token: server.accessToken,
c0e8b12e 293 expectedStatus: HttpStatusCode.NO_CONTENT_204
06a05d5f
C
294 })
295 })
296 })
297
7c3b7976
C
298 after(async function () {
299 await cleanupTests([ server ])
06a05d5f
C
300 })
301})