]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | cleanupTests, | |
7 | createUser, | |
8 | flushAndRunServer, | |
9 | makeDeleteRequest, | |
10 | makeGetRequest, | |
11 | makePostBodyRequest, | |
12 | ServerInfo, | |
13 | setAccessTokensToServers, | |
14 | userLogin | |
15 | } from '../../../../shared/extra-utils' | |
16 | ||
17 | import { | |
18 | checkBadCountPagination, | |
19 | checkBadSortPagination, | |
20 | checkBadStartPagination | |
21 | } from '../../../../shared/extra-utils/requests/check-api-params' | |
22 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
23 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
24 | ||
25 | describe('Test user subscriptions API validators', function () { | |
26 | const path = '/api/v1/users/me/subscriptions' | |
27 | let server: ServerInfo | |
28 | let userAccessToken = '' | |
29 | ||
30 | // --------------------------------------------------------------- | |
31 | ||
32 | before(async function () { | |
33 | this.timeout(30000) | |
34 | ||
35 | server = await flushAndRunServer(1) | |
36 | ||
37 | await setAccessTokensToServers([ server ]) | |
38 | ||
39 | const user = { | |
40 | username: 'user1', | |
41 | password: 'my super password' | |
42 | } | |
43 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
44 | userAccessToken = await userLogin(server, user) | |
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: HttpStatusCode.UNAUTHORIZED_401 | |
65 | }) | |
66 | }) | |
67 | ||
68 | it('Should succeed with the correct parameters', async function () { | |
69 | await makeGetRequest({ | |
70 | url: server.url, | |
71 | path, | |
72 | token: userAccessToken, | |
73 | statusCodeExpected: HttpStatusCode.OK_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: HttpStatusCode.UNAUTHORIZED_401 | |
98 | }) | |
99 | }) | |
100 | ||
101 | it('Should succeed with the correct parameters', async function () { | |
102 | await makeGetRequest({ | |
103 | url: server.url, | |
104 | path, | |
105 | token: userAccessToken, | |
106 | statusCodeExpected: HttpStatusCode.OK_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, | |
116 | fields: { uri: 'user1_channel@localhost:' + server.port }, | |
117 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_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: HttpStatusCode.BAD_REQUEST_400 | |
128 | }) | |
129 | ||
130 | await makePostBodyRequest({ | |
131 | url: server.url, | |
132 | path, | |
133 | token: server.accessToken, | |
134 | fields: { uri: 'root@' }, | |
135 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
136 | }) | |
137 | ||
138 | await makePostBodyRequest({ | |
139 | url: server.url, | |
140 | path, | |
141 | token: server.accessToken, | |
142 | fields: { uri: 'root@hello@' }, | |
143 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
144 | }) | |
145 | }) | |
146 | ||
147 | it('Should succeed with the correct parameters', async function () { | |
148 | this.timeout(20000) | |
149 | ||
150 | await makePostBodyRequest({ | |
151 | url: server.url, | |
152 | path, | |
153 | token: server.accessToken, | |
154 | fields: { uri: 'user1_channel@localhost:' + server.port }, | |
155 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
156 | }) | |
157 | ||
158 | await waitJobs([ server ]) | |
159 | }) | |
160 | }) | |
161 | ||
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:' + server.port, | |
167 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_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: HttpStatusCode.BAD_REQUEST_400 | |
177 | }) | |
178 | ||
179 | await makeGetRequest({ | |
180 | url: server.url, | |
181 | path: path + '/root@', | |
182 | token: server.accessToken, | |
183 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
184 | }) | |
185 | ||
186 | await makeGetRequest({ | |
187 | url: server.url, | |
188 | path: path + '/root@hello@', | |
189 | token: server.accessToken, | |
190 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_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:' + server.port, | |
198 | token: server.accessToken, | |
199 | statusCodeExpected: HttpStatusCode.NOT_FOUND_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:' + server.port, | |
207 | token: server.accessToken, | |
208 | statusCodeExpected: HttpStatusCode.OK_200 | |
209 | }) | |
210 | }) | |
211 | }) | |
212 | ||
213 | describe('When checking if subscriptions exist', function () { | |
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: HttpStatusCode.UNAUTHORIZED_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: HttpStatusCode.BAD_REQUEST_400 | |
231 | }) | |
232 | ||
233 | await makeGetRequest({ | |
234 | url: server.url, | |
235 | path: existPath, | |
236 | query: { 'uris[]': 1 }, | |
237 | token: server.accessToken, | |
238 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_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:' + server.port }, | |
247 | token: server.accessToken, | |
248 | statusCodeExpected: HttpStatusCode.OK_200 | |
249 | }) | |
250 | }) | |
251 | }) | |
252 | ||
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, | |
257 | path: path + '/user1_channel@localhost:' + server.port, | |
258 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_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: HttpStatusCode.BAD_REQUEST_400 | |
268 | }) | |
269 | ||
270 | await makeDeleteRequest({ | |
271 | url: server.url, | |
272 | path: path + '/root@', | |
273 | token: server.accessToken, | |
274 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
275 | }) | |
276 | ||
277 | await makeDeleteRequest({ | |
278 | url: server.url, | |
279 | path: path + '/root@hello@', | |
280 | token: server.accessToken, | |
281 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_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:' + server.port, | |
289 | token: server.accessToken, | |
290 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
291 | }) | |
292 | }) | |
293 | ||
294 | it('Should succeed with the correct parameters', async function () { | |
295 | await makeDeleteRequest({ | |
296 | url: server.url, | |
297 | path: path + '/user1_channel@localhost:' + server.port, | |
298 | token: server.accessToken, | |
299 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
300 | }) | |
301 | }) | |
302 | }) | |
303 | ||
304 | after(async function () { | |
305 | await cleanupTests([ server ]) | |
306 | }) | |
307 | }) |