]>
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 | |
16 | } from '../../utils' | |
17 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | |
18 | ||
19 | describe('Test user subscriptions API validators', function () { | |
20 | const path = '/api/v1/users/me/subscriptions' | |
21 | let server: ServerInfo | |
22 | let userAccessToken = '' | |
06a05d5f C |
23 | |
24 | // --------------------------------------------------------------- | |
25 | ||
26 | before(async function () { | |
27 | this.timeout(30000) | |
28 | ||
29 | await flushTests() | |
30 | ||
31 | server = await runServer(1) | |
32 | ||
33 | await setAccessTokensToServers([ server ]) | |
34 | ||
35 | const user = { | |
36 | username: 'user1', | |
37 | password: 'my super password' | |
38 | } | |
39 | await createUser(server.url, server.accessToken, user.username, user.password) | |
40 | userAccessToken = await userLogin(server, user) | |
06a05d5f C |
41 | }) |
42 | ||
43 | describe('When listing my subscriptions', function () { | |
44 | it('Should fail with a bad start pagination', async function () { | |
45 | await checkBadStartPagination(server.url, path, server.accessToken) | |
46 | }) | |
47 | ||
48 | it('Should fail with a bad count pagination', async function () { | |
49 | await checkBadCountPagination(server.url, path, server.accessToken) | |
50 | }) | |
51 | ||
52 | it('Should fail with an incorrect sort', async function () { | |
53 | await checkBadSortPagination(server.url, path, server.accessToken) | |
54 | }) | |
55 | ||
56 | it('Should fail with a non authenticated user', async function () { | |
57 | await makeGetRequest({ | |
58 | url: server.url, | |
59 | path, | |
60 | statusCodeExpected: 401 | |
61 | }) | |
62 | }) | |
63 | ||
99492dbc | 64 | it('Should succeed with the correct parameters', async function () { |
8a19bee1 | 65 | await makeGetRequest({ |
06a05d5f C |
66 | url: server.url, |
67 | path, | |
68 | token: userAccessToken, | |
69 | statusCodeExpected: 200 | |
70 | }) | |
71 | }) | |
72 | }) | |
73 | ||
74 | describe('When listing my subscriptions videos', function () { | |
75 | const path = '/api/v1/users/me/subscriptions/videos' | |
76 | ||
77 | it('Should fail with a bad start pagination', async function () { | |
78 | await checkBadStartPagination(server.url, path, server.accessToken) | |
79 | }) | |
80 | ||
81 | it('Should fail with a bad count pagination', async function () { | |
82 | await checkBadCountPagination(server.url, path, server.accessToken) | |
83 | }) | |
84 | ||
85 | it('Should fail with an incorrect sort', async function () { | |
86 | await checkBadSortPagination(server.url, path, server.accessToken) | |
87 | }) | |
88 | ||
89 | it('Should fail with a non authenticated user', async function () { | |
90 | await makeGetRequest({ | |
91 | url: server.url, | |
92 | path, | |
93 | statusCodeExpected: 401 | |
94 | }) | |
95 | }) | |
96 | ||
99492dbc | 97 | it('Should succeed with the correct parameters', async function () { |
8a19bee1 | 98 | await makeGetRequest({ |
06a05d5f C |
99 | url: server.url, |
100 | path, | |
101 | token: userAccessToken, | |
102 | statusCodeExpected: 200 | |
103 | }) | |
104 | }) | |
105 | }) | |
106 | ||
107 | describe('When adding a subscription', function () { | |
108 | it('Should fail with a non authenticated user', async function () { | |
109 | await makePostBodyRequest({ | |
110 | url: server.url, | |
111 | path, | |
8a19bee1 | 112 | fields: { uri: 'user1_channel@localhost:9001' }, |
06a05d5f C |
113 | statusCodeExpected: 401 |
114 | }) | |
115 | }) | |
116 | ||
117 | it('Should fail with bad URIs', async function () { | |
118 | await makePostBodyRequest({ | |
119 | url: server.url, | |
120 | path, | |
121 | token: server.accessToken, | |
122 | fields: { uri: 'root' }, | |
123 | statusCodeExpected: 400 | |
124 | }) | |
125 | ||
126 | await makePostBodyRequest({ | |
127 | url: server.url, | |
128 | path, | |
129 | token: server.accessToken, | |
130 | fields: { uri: 'root@' }, | |
131 | statusCodeExpected: 400 | |
132 | }) | |
133 | ||
134 | await makePostBodyRequest({ | |
135 | url: server.url, | |
136 | path, | |
137 | token: server.accessToken, | |
138 | fields: { uri: 'root@hello@' }, | |
139 | statusCodeExpected: 400 | |
140 | }) | |
141 | }) | |
142 | ||
99492dbc | 143 | it('Should succeed with the correct parameters', async function () { |
06a05d5f C |
144 | await makePostBodyRequest({ |
145 | url: server.url, | |
146 | path, | |
147 | token: server.accessToken, | |
8a19bee1 | 148 | fields: { uri: 'user1_channel@localhost:9001' }, |
06a05d5f C |
149 | statusCodeExpected: 204 |
150 | }) | |
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, | |
158 | path: path + '/user1_channel@localhost:9001', | |
159 | statusCodeExpected: 401 | |
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, | |
168 | statusCodeExpected: 400 | |
169 | }) | |
170 | ||
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@hello@', | |
181 | token: server.accessToken, | |
182 | statusCodeExpected: 400 | |
183 | }) | |
184 | }) | |
185 | ||
186 | it('Should fail with an unknown subscription', async function () { | |
187 | await makeGetRequest({ | |
188 | url: server.url, | |
189 | path: path + '/root1@localhost:9001', | |
190 | token: server.accessToken, | |
191 | statusCodeExpected: 404 | |
192 | }) | |
193 | }) | |
194 | ||
195 | it('Should succeed with the correct parameters', async function () { | |
196 | await makeGetRequest({ | |
197 | url: server.url, | |
198 | path: path + '/user1_channel@localhost:9001', | |
199 | token: server.accessToken, | |
200 | statusCodeExpected: 200 | |
201 | }) | |
202 | }) | |
203 | }) | |
204 | ||
f37dc0dd C |
205 | describe('When checking if subscriptions exist', async function () { |
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, | |
212 | statusCodeExpected: 401 | |
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, | |
222 | statusCodeExpected: 400 | |
223 | }) | |
224 | ||
225 | await makeGetRequest({ | |
226 | url: server.url, | |
227 | path: existPath, | |
228 | query: { 'uris[]': 1 }, | |
229 | token: server.accessToken, | |
230 | statusCodeExpected: 400 | |
231 | }) | |
232 | }) | |
233 | ||
234 | it('Should succeed with the correct parameters', async function () { | |
235 | await makeGetRequest({ | |
236 | url: server.url, | |
237 | path: existPath, | |
238 | query: { 'uris[]': 'coucou@localhost:9001' }, | |
239 | token: server.accessToken, | |
240 | statusCodeExpected: 200 | |
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, | |
8a19bee1 | 249 | path: path + '/user1_channel@localhost:9001', |
06a05d5f C |
250 | statusCodeExpected: 401 |
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, | |
259 | statusCodeExpected: 400 | |
260 | }) | |
261 | ||
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@hello@', | |
272 | token: server.accessToken, | |
273 | statusCodeExpected: 400 | |
274 | }) | |
275 | }) | |
276 | ||
277 | it('Should fail with an unknown subscription', async function () { | |
278 | await makeDeleteRequest({ | |
279 | url: server.url, | |
280 | path: path + '/root1@localhost:9001', | |
281 | token: server.accessToken, | |
282 | statusCodeExpected: 404 | |
283 | }) | |
284 | }) | |
285 | ||
99492dbc | 286 | it('Should succeed with the correct parameters', async function () { |
06a05d5f C |
287 | await makeDeleteRequest({ |
288 | url: server.url, | |
8a19bee1 | 289 | path: path + '/user1_channel@localhost:9001', |
06a05d5f C |
290 | token: server.accessToken, |
291 | statusCodeExpected: 204 | |
292 | }) | |
293 | }) | |
294 | }) | |
295 | ||
296 | after(async function () { | |
297 | killallServers([ server ]) | |
298 | ||
299 | // Keep the logs if the test failed | |
300 | if (this['ok']) { | |
301 | await flushTests() | |
302 | } | |
303 | }) | |
304 | }) |