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