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