]>
Commit | Line | Data |
---|---|---|
06a05d5f C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | createUser, | |
7 | flushTests, | |
06a05d5f C |
8 | killallServers, |
9 | makeDeleteRequest, | |
10 | makeGetRequest, | |
11 | makePostBodyRequest, | |
12 | runServer, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | userLogin | |
9639bd17 | 16 | } from '../../../../shared/utils' |
17 | import { | |
18 | checkBadCountPagination, | |
19 | checkBadSortPagination, | |
20 | checkBadStartPagination | |
21 | } from '../../../../shared/utils/requests/check-api-params' | |
06a05d5f C |
22 | |
23 | describe('Test user subscriptions API validators', function () { | |
24 | const path = '/api/v1/users/me/subscriptions' | |
25 | let server: ServerInfo | |
26 | let userAccessToken = '' | |
06a05d5f C |
27 | |
28 | // --------------------------------------------------------------- | |
29 | ||
30 | before(async function () { | |
31 | this.timeout(30000) | |
32 | ||
33 | await flushTests() | |
34 | ||
35 | server = await runServer(1) | |
36 | ||
37 | await setAccessTokensToServers([ server ]) | |
38 | ||
39 | const user = { | |
40 | username: 'user1', | |
41 | password: 'my super password' | |
42 | } | |
43 | await createUser(server.url, server.accessToken, user.username, user.password) | |
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 () { |
06a05d5f C |
148 | await makePostBodyRequest({ |
149 | url: server.url, | |
150 | path, | |
151 | token: server.accessToken, | |
8a19bee1 | 152 | fields: { uri: 'user1_channel@localhost:9001' }, |
06a05d5f C |
153 | statusCodeExpected: 204 |
154 | }) | |
155 | }) | |
156 | }) | |
157 | ||
99492dbc C |
158 | describe('When getting a subscription', function () { |
159 | it('Should fail with a non authenticated user', async function () { | |
160 | await makeGetRequest({ | |
161 | url: server.url, | |
162 | path: path + '/user1_channel@localhost:9001', | |
163 | statusCodeExpected: 401 | |
164 | }) | |
165 | }) | |
166 | ||
167 | it('Should fail with bad URIs', async function () { | |
168 | await makeGetRequest({ | |
169 | url: server.url, | |
170 | path: path + '/root', | |
171 | token: server.accessToken, | |
172 | statusCodeExpected: 400 | |
173 | }) | |
174 | ||
175 | await makeGetRequest({ | |
176 | url: server.url, | |
177 | path: path + '/root@', | |
178 | token: server.accessToken, | |
179 | statusCodeExpected: 400 | |
180 | }) | |
181 | ||
182 | await makeGetRequest({ | |
183 | url: server.url, | |
184 | path: path + '/root@hello@', | |
185 | token: server.accessToken, | |
186 | statusCodeExpected: 400 | |
187 | }) | |
188 | }) | |
189 | ||
190 | it('Should fail with an unknown subscription', async function () { | |
191 | await makeGetRequest({ | |
192 | url: server.url, | |
193 | path: path + '/root1@localhost:9001', | |
194 | token: server.accessToken, | |
195 | statusCodeExpected: 404 | |
196 | }) | |
197 | }) | |
198 | ||
199 | it('Should succeed with the correct parameters', async function () { | |
200 | await makeGetRequest({ | |
201 | url: server.url, | |
202 | path: path + '/user1_channel@localhost:9001', | |
203 | token: server.accessToken, | |
204 | statusCodeExpected: 200 | |
205 | }) | |
206 | }) | |
207 | }) | |
208 | ||
f37dc0dd C |
209 | describe('When checking if subscriptions exist', async function () { |
210 | const existPath = path + '/exist' | |
211 | ||
212 | it('Should fail with a non authenticated user', async function () { | |
213 | await makeGetRequest({ | |
214 | url: server.url, | |
215 | path: existPath, | |
216 | statusCodeExpected: 401 | |
217 | }) | |
218 | }) | |
219 | ||
220 | it('Should fail with bad URIs', async function () { | |
221 | await makeGetRequest({ | |
222 | url: server.url, | |
223 | path: existPath, | |
224 | query: { uris: 'toto' }, | |
225 | token: server.accessToken, | |
226 | statusCodeExpected: 400 | |
227 | }) | |
228 | ||
229 | await makeGetRequest({ | |
230 | url: server.url, | |
231 | path: existPath, | |
232 | query: { 'uris[]': 1 }, | |
233 | token: server.accessToken, | |
234 | statusCodeExpected: 400 | |
235 | }) | |
236 | }) | |
237 | ||
238 | it('Should succeed with the correct parameters', async function () { | |
239 | await makeGetRequest({ | |
240 | url: server.url, | |
241 | path: existPath, | |
242 | query: { 'uris[]': 'coucou@localhost:9001' }, | |
243 | token: server.accessToken, | |
244 | statusCodeExpected: 200 | |
245 | }) | |
246 | }) | |
247 | }) | |
248 | ||
06a05d5f C |
249 | describe('When removing a subscription', function () { |
250 | it('Should fail with a non authenticated user', async function () { | |
251 | await makeDeleteRequest({ | |
252 | url: server.url, | |
8a19bee1 | 253 | path: path + '/user1_channel@localhost:9001', |
06a05d5f C |
254 | statusCodeExpected: 401 |
255 | }) | |
256 | }) | |
257 | ||
258 | it('Should fail with bad URIs', async function () { | |
259 | await makeDeleteRequest({ | |
260 | url: server.url, | |
261 | path: path + '/root', | |
262 | token: server.accessToken, | |
263 | statusCodeExpected: 400 | |
264 | }) | |
265 | ||
266 | await makeDeleteRequest({ | |
267 | url: server.url, | |
268 | path: path + '/root@', | |
269 | token: server.accessToken, | |
270 | statusCodeExpected: 400 | |
271 | }) | |
272 | ||
273 | await makeDeleteRequest({ | |
274 | url: server.url, | |
275 | path: path + '/root@hello@', | |
276 | token: server.accessToken, | |
277 | statusCodeExpected: 400 | |
278 | }) | |
279 | }) | |
280 | ||
281 | it('Should fail with an unknown subscription', async function () { | |
282 | await makeDeleteRequest({ | |
283 | url: server.url, | |
284 | path: path + '/root1@localhost:9001', | |
285 | token: server.accessToken, | |
286 | statusCodeExpected: 404 | |
287 | }) | |
288 | }) | |
289 | ||
99492dbc | 290 | it('Should succeed with the correct parameters', async function () { |
06a05d5f C |
291 | await makeDeleteRequest({ |
292 | url: server.url, | |
8a19bee1 | 293 | path: path + '/user1_channel@localhost:9001', |
06a05d5f C |
294 | token: server.accessToken, |
295 | statusCodeExpected: 204 | |
296 | }) | |
297 | }) | |
298 | }) | |
299 | ||
300 | after(async function () { | |
301 | killallServers([ server ]) | |
302 | ||
303 | // Keep the logs if the test failed | |
304 | if (this['ok']) { | |
305 | await flushTests() | |
306 | } | |
307 | }) | |
308 | }) |