1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
12 setAccessTokensToServers
13 } from '../../../../shared/extra-utils'
16 checkBadCountPagination,
17 checkBadSortPagination,
18 checkBadStartPagination
19 } from '../../../../shared/extra-utils/requests/check-api-params'
20 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 describe('Test user subscriptions API validators', function () {
24 const path = '/api/v1/users/me/subscriptions'
25 let server: PeerTubeServer
26 let userAccessToken = ''
28 // ---------------------------------------------------------------
30 before(async function () {
33 server = await createSingleServer(1)
35 await setAccessTokensToServers([ server ])
39 password: 'my super password'
41 await server.users.create({ username: user.username, password: user.password })
42 userAccessToken = await server.login.getAccessToken(user)
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)
50 it('Should fail with a bad count pagination', async function () {
51 await checkBadCountPagination(server.url, path, server.accessToken)
54 it('Should fail with an incorrect sort', async function () {
55 await checkBadSortPagination(server.url, path, server.accessToken)
58 it('Should fail with a non authenticated user', async function () {
59 await makeGetRequest({
62 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
66 it('Should succeed with the correct parameters', async function () {
67 await makeGetRequest({
70 token: userAccessToken,
71 statusCodeExpected: HttpStatusCode.OK_200
76 describe('When listing my subscriptions videos', function () {
77 const path = '/api/v1/users/me/subscriptions/videos'
79 it('Should fail with a bad start pagination', async function () {
80 await checkBadStartPagination(server.url, path, server.accessToken)
83 it('Should fail with a bad count pagination', async function () {
84 await checkBadCountPagination(server.url, path, server.accessToken)
87 it('Should fail with an incorrect sort', async function () {
88 await checkBadSortPagination(server.url, path, server.accessToken)
91 it('Should fail with a non authenticated user', async function () {
92 await makeGetRequest({
95 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
99 it('Should succeed with the correct parameters', async function () {
100 await makeGetRequest({
103 token: userAccessToken,
104 statusCodeExpected: HttpStatusCode.OK_200
109 describe('When adding a subscription', function () {
110 it('Should fail with a non authenticated user', async function () {
111 await makePostBodyRequest({
114 fields: { uri: 'user1_channel@localhost:' + server.port },
115 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
119 it('Should fail with bad URIs', async function () {
120 await makePostBodyRequest({
123 token: server.accessToken,
124 fields: { uri: 'root' },
125 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
128 await makePostBodyRequest({
131 token: server.accessToken,
132 fields: { uri: 'root@' },
133 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
136 await makePostBodyRequest({
139 token: server.accessToken,
140 fields: { uri: 'root@hello@' },
141 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
145 it('Should succeed with the correct parameters', async function () {
148 await makePostBodyRequest({
151 token: server.accessToken,
152 fields: { uri: 'user1_channel@localhost:' + server.port },
153 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
156 await waitJobs([ server ])
160 describe('When getting a subscription', function () {
161 it('Should fail with a non authenticated user', async function () {
162 await makeGetRequest({
164 path: path + '/user1_channel@localhost:' + server.port,
165 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
169 it('Should fail with bad URIs', async function () {
170 await makeGetRequest({
172 path: path + '/root',
173 token: server.accessToken,
174 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
177 await makeGetRequest({
179 path: path + '/root@',
180 token: server.accessToken,
181 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
184 await makeGetRequest({
186 path: path + '/root@hello@',
187 token: server.accessToken,
188 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
192 it('Should fail with an unknown subscription', async function () {
193 await makeGetRequest({
195 path: path + '/root1@localhost:' + server.port,
196 token: server.accessToken,
197 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
201 it('Should succeed with the correct parameters', async function () {
202 await makeGetRequest({
204 path: path + '/user1_channel@localhost:' + server.port,
205 token: server.accessToken,
206 statusCodeExpected: HttpStatusCode.OK_200
211 describe('When checking if subscriptions exist', function () {
212 const existPath = path + '/exist'
214 it('Should fail with a non authenticated user', async function () {
215 await makeGetRequest({
218 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
222 it('Should fail with bad URIs', async function () {
223 await makeGetRequest({
226 query: { uris: 'toto' },
227 token: server.accessToken,
228 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
231 await makeGetRequest({
234 query: { 'uris[]': 1 },
235 token: server.accessToken,
236 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
240 it('Should succeed with the correct parameters', async function () {
241 await makeGetRequest({
244 query: { 'uris[]': 'coucou@localhost:' + server.port },
245 token: server.accessToken,
246 statusCodeExpected: HttpStatusCode.OK_200
251 describe('When removing a subscription', function () {
252 it('Should fail with a non authenticated user', async function () {
253 await makeDeleteRequest({
255 path: path + '/user1_channel@localhost:' + server.port,
256 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
260 it('Should fail with bad URIs', async function () {
261 await makeDeleteRequest({
263 path: path + '/root',
264 token: server.accessToken,
265 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
268 await makeDeleteRequest({
270 path: path + '/root@',
271 token: server.accessToken,
272 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
275 await makeDeleteRequest({
277 path: path + '/root@hello@',
278 token: server.accessToken,
279 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
283 it('Should fail with an unknown subscription', async function () {
284 await makeDeleteRequest({
286 path: path + '/root1@localhost:' + server.port,
287 token: server.accessToken,
288 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
292 it('Should succeed with the correct parameters', async function () {
293 await makeDeleteRequest({
295 path: path + '/user1_channel@localhost:' + server.port,
296 token: server.accessToken,
297 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
302 after(async function () {
303 await cleanupTests([ server ])