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