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