]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { | |
5 | cleanupTests, | |
6 | createSingleServer, | |
7 | makeDeleteRequest, | |
8 | makeGetRequest, | |
9 | makePostBodyRequest, | |
10 | PeerTubeServer, | |
11 | setAccessTokensToServers, | |
12 | waitJobs | |
13 | } from '@shared/server-commands' | |
14 | import { HttpStatusCode } from '@shared/models' | |
15 | import { checkBadStartPagination, checkBadCountPagination, checkBadSortPagination } from '@server/tests/shared' | |
16 | ||
17 | describe('Test user subscriptions API validators', function () { | |
18 | const path = '/api/v1/users/me/subscriptions' | |
19 | let server: PeerTubeServer | |
20 | let userAccessToken = '' | |
21 | ||
22 | // --------------------------------------------------------------- | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(30000) | |
26 | ||
27 | server = await createSingleServer(1) | |
28 | ||
29 | await setAccessTokensToServers([ server ]) | |
30 | ||
31 | const user = { | |
32 | username: 'user1', | |
33 | password: 'my super password' | |
34 | } | |
35 | await server.users.create({ username: user.username, password: user.password }) | |
36 | userAccessToken = await server.login.getAccessToken(user) | |
37 | }) | |
38 | ||
39 | describe('When listing my subscriptions', function () { | |
40 | it('Should fail with a bad start pagination', async function () { | |
41 | await checkBadStartPagination(server.url, path, server.accessToken) | |
42 | }) | |
43 | ||
44 | it('Should fail with a bad count pagination', async function () { | |
45 | await checkBadCountPagination(server.url, path, server.accessToken) | |
46 | }) | |
47 | ||
48 | it('Should fail with an incorrect sort', async function () { | |
49 | await checkBadSortPagination(server.url, path, server.accessToken) | |
50 | }) | |
51 | ||
52 | it('Should fail with a non authenticated user', async function () { | |
53 | await makeGetRequest({ | |
54 | url: server.url, | |
55 | path, | |
56 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
57 | }) | |
58 | }) | |
59 | ||
60 | it('Should succeed with the correct parameters', async function () { | |
61 | await makeGetRequest({ | |
62 | url: server.url, | |
63 | path, | |
64 | token: userAccessToken, | |
65 | expectedStatus: HttpStatusCode.OK_200 | |
66 | }) | |
67 | }) | |
68 | }) | |
69 | ||
70 | describe('When listing my subscriptions videos', function () { | |
71 | const path = '/api/v1/users/me/subscriptions/videos' | |
72 | ||
73 | it('Should fail with a bad start pagination', async function () { | |
74 | await checkBadStartPagination(server.url, path, server.accessToken) | |
75 | }) | |
76 | ||
77 | it('Should fail with a bad count pagination', async function () { | |
78 | await checkBadCountPagination(server.url, path, server.accessToken) | |
79 | }) | |
80 | ||
81 | it('Should fail with an incorrect sort', async function () { | |
82 | await checkBadSortPagination(server.url, path, server.accessToken) | |
83 | }) | |
84 | ||
85 | it('Should fail with a non authenticated user', async function () { | |
86 | await makeGetRequest({ | |
87 | url: server.url, | |
88 | path, | |
89 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
90 | }) | |
91 | }) | |
92 | ||
93 | it('Should succeed with the correct parameters', async function () { | |
94 | await makeGetRequest({ | |
95 | url: server.url, | |
96 | path, | |
97 | token: userAccessToken, | |
98 | expectedStatus: HttpStatusCode.OK_200 | |
99 | }) | |
100 | }) | |
101 | }) | |
102 | ||
103 | describe('When adding a subscription', function () { | |
104 | it('Should fail with a non authenticated user', async function () { | |
105 | await makePostBodyRequest({ | |
106 | url: server.url, | |
107 | path, | |
108 | fields: { uri: 'user1_channel@localhost:' + server.port }, | |
109 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
110 | }) | |
111 | }) | |
112 | ||
113 | it('Should fail with bad URIs', async function () { | |
114 | await makePostBodyRequest({ | |
115 | url: server.url, | |
116 | path, | |
117 | token: server.accessToken, | |
118 | fields: { uri: 'root' }, | |
119 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
120 | }) | |
121 | ||
122 | await makePostBodyRequest({ | |
123 | url: server.url, | |
124 | path, | |
125 | token: server.accessToken, | |
126 | fields: { uri: 'root@' }, | |
127 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
128 | }) | |
129 | ||
130 | await makePostBodyRequest({ | |
131 | url: server.url, | |
132 | path, | |
133 | token: server.accessToken, | |
134 | fields: { uri: 'root@hello@' }, | |
135 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
136 | }) | |
137 | }) | |
138 | ||
139 | it('Should succeed with the correct parameters', async function () { | |
140 | this.timeout(20000) | |
141 | ||
142 | await makePostBodyRequest({ | |
143 | url: server.url, | |
144 | path, | |
145 | token: server.accessToken, | |
146 | fields: { uri: 'user1_channel@localhost:' + server.port }, | |
147 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
148 | }) | |
149 | ||
150 | await waitJobs([ server ]) | |
151 | }) | |
152 | }) | |
153 | ||
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:' + server.port, | |
159 | expectedStatus: HttpStatusCode.UNAUTHORIZED_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 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
169 | }) | |
170 | ||
171 | await makeGetRequest({ | |
172 | url: server.url, | |
173 | path: path + '/root@', | |
174 | token: server.accessToken, | |
175 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
176 | }) | |
177 | ||
178 | await makeGetRequest({ | |
179 | url: server.url, | |
180 | path: path + '/root@hello@', | |
181 | token: server.accessToken, | |
182 | expectedStatus: HttpStatusCode.BAD_REQUEST_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:' + server.port, | |
190 | token: server.accessToken, | |
191 | expectedStatus: HttpStatusCode.NOT_FOUND_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:' + server.port, | |
199 | token: server.accessToken, | |
200 | expectedStatus: HttpStatusCode.OK_200 | |
201 | }) | |
202 | }) | |
203 | }) | |
204 | ||
205 | describe('When checking if subscriptions exist', 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 | expectedStatus: HttpStatusCode.UNAUTHORIZED_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 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
223 | }) | |
224 | ||
225 | await makeGetRequest({ | |
226 | url: server.url, | |
227 | path: existPath, | |
228 | query: { 'uris[]': 1 }, | |
229 | token: server.accessToken, | |
230 | expectedStatus: HttpStatusCode.BAD_REQUEST_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:' + server.port }, | |
239 | token: server.accessToken, | |
240 | expectedStatus: HttpStatusCode.OK_200 | |
241 | }) | |
242 | }) | |
243 | }) | |
244 | ||
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, | |
249 | path: path + '/user1_channel@localhost:' + server.port, | |
250 | expectedStatus: HttpStatusCode.UNAUTHORIZED_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 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
260 | }) | |
261 | ||
262 | await makeDeleteRequest({ | |
263 | url: server.url, | |
264 | path: path + '/root@', | |
265 | token: server.accessToken, | |
266 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
267 | }) | |
268 | ||
269 | await makeDeleteRequest({ | |
270 | url: server.url, | |
271 | path: path + '/root@hello@', | |
272 | token: server.accessToken, | |
273 | expectedStatus: HttpStatusCode.BAD_REQUEST_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:' + server.port, | |
281 | token: server.accessToken, | |
282 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
283 | }) | |
284 | }) | |
285 | ||
286 | it('Should succeed with the correct parameters', async function () { | |
287 | await makeDeleteRequest({ | |
288 | url: server.url, | |
289 | path: path + '/user1_channel@localhost:' + server.port, | |
290 | token: server.accessToken, | |
291 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
292 | }) | |
293 | }) | |
294 | }) | |
295 | ||
296 | after(async function () { | |
297 | await cleanupTests([ server ]) | |
298 | }) | |
299 | }) |