aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/user-subscriptions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/user-subscriptions.ts')
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts80
1 files changed, 37 insertions, 43 deletions
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 538201647..624069c80 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -1,30 +1,24 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import { 4import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
6 cleanupTests, 8 cleanupTests,
7 createUser, 9 createSingleServer,
8 flushAndRunServer,
9 makeDeleteRequest, 10 makeDeleteRequest,
10 makeGetRequest, 11 makeGetRequest,
11 makePostBodyRequest, 12 makePostBodyRequest,
12 ServerInfo, 13 PeerTubeServer,
13 setAccessTokensToServers, 14 setAccessTokensToServers,
14 userLogin 15 waitJobs
15} from '../../../../shared/extra-utils' 16} from '@shared/extra-utils'
16 17import { HttpStatusCode } from '@shared/models'
17import {
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
24 18
25describe('Test user subscriptions API validators', function () { 19describe('Test user subscriptions API validators', function () {
26 const path = '/api/v1/users/me/subscriptions' 20 const path = '/api/v1/users/me/subscriptions'
27 let server: ServerInfo 21 let server: PeerTubeServer
28 let userAccessToken = '' 22 let userAccessToken = ''
29 23
30 // --------------------------------------------------------------- 24 // ---------------------------------------------------------------
@@ -32,7 +26,7 @@ describe('Test user subscriptions API validators', function () {
32 before(async function () { 26 before(async function () {
33 this.timeout(30000) 27 this.timeout(30000)
34 28
35 server = await flushAndRunServer(1) 29 server = await createSingleServer(1)
36 30
37 await setAccessTokensToServers([ server ]) 31 await setAccessTokensToServers([ server ])
38 32
@@ -40,8 +34,8 @@ describe('Test user subscriptions API validators', function () {
40 username: 'user1', 34 username: 'user1',
41 password: 'my super password' 35 password: 'my super password'
42 } 36 }
43 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 37 await server.users.create({ username: user.username, password: user.password })
44 userAccessToken = await userLogin(server, user) 38 userAccessToken = await server.login.getAccessToken(user)
45 }) 39 })
46 40
47 describe('When listing my subscriptions', function () { 41 describe('When listing my subscriptions', function () {
@@ -61,7 +55,7 @@ describe('Test user subscriptions API validators', function () {
61 await makeGetRequest({ 55 await makeGetRequest({
62 url: server.url, 56 url: server.url,
63 path, 57 path,
64 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 58 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
65 }) 59 })
66 }) 60 })
67 61
@@ -70,7 +64,7 @@ describe('Test user subscriptions API validators', function () {
70 url: server.url, 64 url: server.url,
71 path, 65 path,
72 token: userAccessToken, 66 token: userAccessToken,
73 statusCodeExpected: HttpStatusCode.OK_200 67 expectedStatus: HttpStatusCode.OK_200
74 }) 68 })
75 }) 69 })
76 }) 70 })
@@ -94,7 +88,7 @@ describe('Test user subscriptions API validators', function () {
94 await makeGetRequest({ 88 await makeGetRequest({
95 url: server.url, 89 url: server.url,
96 path, 90 path,
97 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 91 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
98 }) 92 })
99 }) 93 })
100 94
@@ -103,7 +97,7 @@ describe('Test user subscriptions API validators', function () {
103 url: server.url, 97 url: server.url,
104 path, 98 path,
105 token: userAccessToken, 99 token: userAccessToken,
106 statusCodeExpected: HttpStatusCode.OK_200 100 expectedStatus: HttpStatusCode.OK_200
107 }) 101 })
108 }) 102 })
109 }) 103 })
@@ -114,7 +108,7 @@ describe('Test user subscriptions API validators', function () {
114 url: server.url, 108 url: server.url,
115 path, 109 path,
116 fields: { uri: 'user1_channel@localhost:' + server.port }, 110 fields: { uri: 'user1_channel@localhost:' + server.port },
117 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 111 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
118 }) 112 })
119 }) 113 })
120 114
@@ -124,7 +118,7 @@ describe('Test user subscriptions API validators', function () {
124 path, 118 path,
125 token: server.accessToken, 119 token: server.accessToken,
126 fields: { uri: 'root' }, 120 fields: { uri: 'root' },
127 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 121 expectedStatus: HttpStatusCode.BAD_REQUEST_400
128 }) 122 })
129 123
130 await makePostBodyRequest({ 124 await makePostBodyRequest({
@@ -132,7 +126,7 @@ describe('Test user subscriptions API validators', function () {
132 path, 126 path,
133 token: server.accessToken, 127 token: server.accessToken,
134 fields: { uri: 'root@' }, 128 fields: { uri: 'root@' },
135 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 129 expectedStatus: HttpStatusCode.BAD_REQUEST_400
136 }) 130 })
137 131
138 await makePostBodyRequest({ 132 await makePostBodyRequest({
@@ -140,7 +134,7 @@ describe('Test user subscriptions API validators', function () {
140 path, 134 path,
141 token: server.accessToken, 135 token: server.accessToken,
142 fields: { uri: 'root@hello@' }, 136 fields: { uri: 'root@hello@' },
143 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 137 expectedStatus: HttpStatusCode.BAD_REQUEST_400
144 }) 138 })
145 }) 139 })
146 140
@@ -152,7 +146,7 @@ describe('Test user subscriptions API validators', function () {
152 path, 146 path,
153 token: server.accessToken, 147 token: server.accessToken,
154 fields: { uri: 'user1_channel@localhost:' + server.port }, 148 fields: { uri: 'user1_channel@localhost:' + server.port },
155 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 149 expectedStatus: HttpStatusCode.NO_CONTENT_204
156 }) 150 })
157 151
158 await waitJobs([ server ]) 152 await waitJobs([ server ])
@@ -164,7 +158,7 @@ describe('Test user subscriptions API validators', function () {
164 await makeGetRequest({ 158 await makeGetRequest({
165 url: server.url, 159 url: server.url,
166 path: path + '/user1_channel@localhost:' + server.port, 160 path: path + '/user1_channel@localhost:' + server.port,
167 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 161 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
168 }) 162 })
169 }) 163 })
170 164
@@ -173,21 +167,21 @@ describe('Test user subscriptions API validators', function () {
173 url: server.url, 167 url: server.url,
174 path: path + '/root', 168 path: path + '/root',
175 token: server.accessToken, 169 token: server.accessToken,
176 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 170 expectedStatus: HttpStatusCode.BAD_REQUEST_400
177 }) 171 })
178 172
179 await makeGetRequest({ 173 await makeGetRequest({
180 url: server.url, 174 url: server.url,
181 path: path + '/root@', 175 path: path + '/root@',
182 token: server.accessToken, 176 token: server.accessToken,
183 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 177 expectedStatus: HttpStatusCode.BAD_REQUEST_400
184 }) 178 })
185 179
186 await makeGetRequest({ 180 await makeGetRequest({
187 url: server.url, 181 url: server.url,
188 path: path + '/root@hello@', 182 path: path + '/root@hello@',
189 token: server.accessToken, 183 token: server.accessToken,
190 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 184 expectedStatus: HttpStatusCode.BAD_REQUEST_400
191 }) 185 })
192 }) 186 })
193 187
@@ -196,7 +190,7 @@ describe('Test user subscriptions API validators', function () {
196 url: server.url, 190 url: server.url,
197 path: path + '/root1@localhost:' + server.port, 191 path: path + '/root1@localhost:' + server.port,
198 token: server.accessToken, 192 token: server.accessToken,
199 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 193 expectedStatus: HttpStatusCode.NOT_FOUND_404
200 }) 194 })
201 }) 195 })
202 196
@@ -205,7 +199,7 @@ describe('Test user subscriptions API validators', function () {
205 url: server.url, 199 url: server.url,
206 path: path + '/user1_channel@localhost:' + server.port, 200 path: path + '/user1_channel@localhost:' + server.port,
207 token: server.accessToken, 201 token: server.accessToken,
208 statusCodeExpected: HttpStatusCode.OK_200 202 expectedStatus: HttpStatusCode.OK_200
209 }) 203 })
210 }) 204 })
211 }) 205 })
@@ -217,7 +211,7 @@ describe('Test user subscriptions API validators', function () {
217 await makeGetRequest({ 211 await makeGetRequest({
218 url: server.url, 212 url: server.url,
219 path: existPath, 213 path: existPath,
220 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 214 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
221 }) 215 })
222 }) 216 })
223 217
@@ -227,7 +221,7 @@ describe('Test user subscriptions API validators', function () {
227 path: existPath, 221 path: existPath,
228 query: { uris: 'toto' }, 222 query: { uris: 'toto' },
229 token: server.accessToken, 223 token: server.accessToken,
230 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 224 expectedStatus: HttpStatusCode.BAD_REQUEST_400
231 }) 225 })
232 226
233 await makeGetRequest({ 227 await makeGetRequest({
@@ -235,7 +229,7 @@ describe('Test user subscriptions API validators', function () {
235 path: existPath, 229 path: existPath,
236 query: { 'uris[]': 1 }, 230 query: { 'uris[]': 1 },
237 token: server.accessToken, 231 token: server.accessToken,
238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 232 expectedStatus: HttpStatusCode.BAD_REQUEST_400
239 }) 233 })
240 }) 234 })
241 235
@@ -245,7 +239,7 @@ describe('Test user subscriptions API validators', function () {
245 path: existPath, 239 path: existPath,
246 query: { 'uris[]': 'coucou@localhost:' + server.port }, 240 query: { 'uris[]': 'coucou@localhost:' + server.port },
247 token: server.accessToken, 241 token: server.accessToken,
248 statusCodeExpected: HttpStatusCode.OK_200 242 expectedStatus: HttpStatusCode.OK_200
249 }) 243 })
250 }) 244 })
251 }) 245 })
@@ -255,7 +249,7 @@ describe('Test user subscriptions API validators', function () {
255 await makeDeleteRequest({ 249 await makeDeleteRequest({
256 url: server.url, 250 url: server.url,
257 path: path + '/user1_channel@localhost:' + server.port, 251 path: path + '/user1_channel@localhost:' + server.port,
258 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 252 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
259 }) 253 })
260 }) 254 })
261 255
@@ -264,21 +258,21 @@ describe('Test user subscriptions API validators', function () {
264 url: server.url, 258 url: server.url,
265 path: path + '/root', 259 path: path + '/root',
266 token: server.accessToken, 260 token: server.accessToken,
267 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 261 expectedStatus: HttpStatusCode.BAD_REQUEST_400
268 }) 262 })
269 263
270 await makeDeleteRequest({ 264 await makeDeleteRequest({
271 url: server.url, 265 url: server.url,
272 path: path + '/root@', 266 path: path + '/root@',
273 token: server.accessToken, 267 token: server.accessToken,
274 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 268 expectedStatus: HttpStatusCode.BAD_REQUEST_400
275 }) 269 })
276 270
277 await makeDeleteRequest({ 271 await makeDeleteRequest({
278 url: server.url, 272 url: server.url,
279 path: path + '/root@hello@', 273 path: path + '/root@hello@',
280 token: server.accessToken, 274 token: server.accessToken,
281 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 275 expectedStatus: HttpStatusCode.BAD_REQUEST_400
282 }) 276 })
283 }) 277 })
284 278
@@ -287,7 +281,7 @@ describe('Test user subscriptions API validators', function () {
287 url: server.url, 281 url: server.url,
288 path: path + '/root1@localhost:' + server.port, 282 path: path + '/root1@localhost:' + server.port,
289 token: server.accessToken, 283 token: server.accessToken,
290 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 284 expectedStatus: HttpStatusCode.NOT_FOUND_404
291 }) 285 })
292 }) 286 })
293 287
@@ -296,7 +290,7 @@ describe('Test user subscriptions API validators', function () {
296 url: server.url, 290 url: server.url,
297 path: path + '/user1_channel@localhost:' + server.port, 291 path: path + '/user1_channel@localhost:' + server.port,
298 token: server.accessToken, 292 token: server.accessToken,
299 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 293 expectedStatus: HttpStatusCode.NO_CONTENT_204
300 }) 294 })
301 }) 295 })
302 }) 296 })