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