1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
13 setAccessTokensToServers,
15 } from '../../../../shared/extra-utils'
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'
25 describe('Test user subscriptions API validators', function () {
26 const path = '/api/v1/users/me/subscriptions'
27 let server: ServerInfo
28 let userAccessToken = ''
30 // ---------------------------------------------------------------
32 before(async function () {
35 server = await flushAndRunServer(1)
37 await setAccessTokensToServers([ server ])
41 password: 'my super password'
43 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
44 userAccessToken = await userLogin(server, user)
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)
52 it('Should fail with a bad count pagination', async function () {
53 await checkBadCountPagination(server.url, path, server.accessToken)
56 it('Should fail with an incorrect sort', async function () {
57 await checkBadSortPagination(server.url, path, server.accessToken)
60 it('Should fail with a non authenticated user', async function () {
61 await makeGetRequest({
64 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
68 it('Should succeed with the correct parameters', async function () {
69 await makeGetRequest({
72 token: userAccessToken,
73 statusCodeExpected: HttpStatusCode.OK_200
78 describe('When listing my subscriptions videos', function () {
79 const path = '/api/v1/users/me/subscriptions/videos'
81 it('Should fail with a bad start pagination', async function () {
82 await checkBadStartPagination(server.url, path, server.accessToken)
85 it('Should fail with a bad count pagination', async function () {
86 await checkBadCountPagination(server.url, path, server.accessToken)
89 it('Should fail with an incorrect sort', async function () {
90 await checkBadSortPagination(server.url, path, server.accessToken)
93 it('Should fail with a non authenticated user', async function () {
94 await makeGetRequest({
97 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
101 it('Should succeed with the correct parameters', async function () {
102 await makeGetRequest({
105 token: userAccessToken,
106 statusCodeExpected: HttpStatusCode.OK_200
111 describe('When adding a subscription', function () {
112 it('Should fail with a non authenticated user', async function () {
113 await makePostBodyRequest({
116 fields: { uri: 'user1_channel@localhost:' + server.port },
117 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
121 it('Should fail with bad URIs', async function () {
122 await makePostBodyRequest({
125 token: server.accessToken,
126 fields: { uri: 'root' },
127 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
130 await makePostBodyRequest({
133 token: server.accessToken,
134 fields: { uri: 'root@' },
135 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
138 await makePostBodyRequest({
141 token: server.accessToken,
142 fields: { uri: 'root@hello@' },
143 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
147 it('Should succeed with the correct parameters', async function () {
150 await makePostBodyRequest({
153 token: server.accessToken,
154 fields: { uri: 'user1_channel@localhost:' + server.port },
155 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
158 await waitJobs([ server ])
162 describe('When getting a subscription', function () {
163 it('Should fail with a non authenticated user', async function () {
164 await makeGetRequest({
166 path: path + '/user1_channel@localhost:' + server.port,
167 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
171 it('Should fail with bad URIs', async function () {
172 await makeGetRequest({
174 path: path + '/root',
175 token: server.accessToken,
176 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
179 await makeGetRequest({
181 path: path + '/root@',
182 token: server.accessToken,
183 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
186 await makeGetRequest({
188 path: path + '/root@hello@',
189 token: server.accessToken,
190 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
194 it('Should fail with an unknown subscription', async function () {
195 await makeGetRequest({
197 path: path + '/root1@localhost:' + server.port,
198 token: server.accessToken,
199 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
203 it('Should succeed with the correct parameters', async function () {
204 await makeGetRequest({
206 path: path + '/user1_channel@localhost:' + server.port,
207 token: server.accessToken,
208 statusCodeExpected: HttpStatusCode.OK_200
213 describe('When checking if subscriptions exist', function () {
214 const existPath = path + '/exist'
216 it('Should fail with a non authenticated user', async function () {
217 await makeGetRequest({
220 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
224 it('Should fail with bad URIs', async function () {
225 await makeGetRequest({
228 query: { uris: 'toto' },
229 token: server.accessToken,
230 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
233 await makeGetRequest({
236 query: { 'uris[]': 1 },
237 token: server.accessToken,
238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
242 it('Should succeed with the correct parameters', async function () {
243 await makeGetRequest({
246 query: { 'uris[]': 'coucou@localhost:' + server.port },
247 token: server.accessToken,
248 statusCodeExpected: HttpStatusCode.OK_200
253 describe('When removing a subscription', function () {
254 it('Should fail with a non authenticated user', async function () {
255 await makeDeleteRequest({
257 path: path + '/user1_channel@localhost:' + server.port,
258 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
262 it('Should fail with bad URIs', async function () {
263 await makeDeleteRequest({
265 path: path + '/root',
266 token: server.accessToken,
267 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
270 await makeDeleteRequest({
272 path: path + '/root@',
273 token: server.accessToken,
274 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
277 await makeDeleteRequest({
279 path: path + '/root@hello@',
280 token: server.accessToken,
281 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
285 it('Should fail with an unknown subscription', async function () {
286 await makeDeleteRequest({
288 path: path + '/root1@localhost:' + server.port,
289 token: server.accessToken,
290 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
294 it('Should succeed with the correct parameters', async function () {
295 await makeDeleteRequest({
297 path: path + '/user1_channel@localhost:' + server.port,
298 token: server.accessToken,
299 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
304 after(async function () {
305 await cleanupTests([ server ])