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