1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
14 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { HttpStatusCode } from '@shared/models'
19 describe('Test user subscriptions API validators', function () {
20 const path = '/api/v1/users/me/subscriptions'
21 let server: PeerTubeServer
22 let userAccessToken = ''
24 // ---------------------------------------------------------------
26 before(async function () {
29 server = await createSingleServer(1)
31 await setAccessTokensToServers([ server ])
35 password: 'my super password'
37 await server.users.create({ username: user.username, password: user.password })
38 userAccessToken = await server.login.getAccessToken(user)
41 describe('When listing my subscriptions', function () {
42 it('Should fail with a bad start pagination', async function () {
43 await checkBadStartPagination(server.url, path, server.accessToken)
46 it('Should fail with a bad count pagination', async function () {
47 await checkBadCountPagination(server.url, path, server.accessToken)
50 it('Should fail with an incorrect sort', async function () {
51 await checkBadSortPagination(server.url, path, server.accessToken)
54 it('Should fail with a non authenticated user', async function () {
55 await makeGetRequest({
58 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
62 it('Should succeed with the correct parameters', async function () {
63 await makeGetRequest({
66 token: userAccessToken,
67 expectedStatus: HttpStatusCode.OK_200
72 describe('When listing my subscriptions videos', function () {
73 const path = '/api/v1/users/me/subscriptions/videos'
75 it('Should fail with a bad start pagination', async function () {
76 await checkBadStartPagination(server.url, path, server.accessToken)
79 it('Should fail with a bad count pagination', async function () {
80 await checkBadCountPagination(server.url, path, server.accessToken)
83 it('Should fail with an incorrect sort', async function () {
84 await checkBadSortPagination(server.url, path, server.accessToken)
87 it('Should fail with a non authenticated user', async function () {
88 await makeGetRequest({
91 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
95 it('Should succeed with the correct parameters', async function () {
96 await makeGetRequest({
99 token: userAccessToken,
100 expectedStatus: HttpStatusCode.OK_200
105 describe('When adding a subscription', function () {
106 it('Should fail with a non authenticated user', async function () {
107 await makePostBodyRequest({
110 fields: { uri: 'user1_channel@localhost:' + server.port },
111 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
115 it('Should fail with bad URIs', async function () {
116 await makePostBodyRequest({
119 token: server.accessToken,
120 fields: { uri: 'root' },
121 expectedStatus: HttpStatusCode.BAD_REQUEST_400
124 await makePostBodyRequest({
127 token: server.accessToken,
128 fields: { uri: 'root@' },
129 expectedStatus: HttpStatusCode.BAD_REQUEST_400
132 await makePostBodyRequest({
135 token: server.accessToken,
136 fields: { uri: 'root@hello@' },
137 expectedStatus: HttpStatusCode.BAD_REQUEST_400
141 it('Should succeed with the correct parameters', async function () {
144 await makePostBodyRequest({
147 token: server.accessToken,
148 fields: { uri: 'user1_channel@localhost:' + server.port },
149 expectedStatus: HttpStatusCode.NO_CONTENT_204
152 await waitJobs([ server ])
156 describe('When getting a subscription', function () {
157 it('Should fail with a non authenticated user', async function () {
158 await makeGetRequest({
160 path: path + '/user1_channel@localhost:' + server.port,
161 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
165 it('Should fail with bad URIs', async function () {
166 await makeGetRequest({
168 path: path + '/root',
169 token: server.accessToken,
170 expectedStatus: HttpStatusCode.BAD_REQUEST_400
173 await makeGetRequest({
175 path: path + '/root@',
176 token: server.accessToken,
177 expectedStatus: HttpStatusCode.BAD_REQUEST_400
180 await makeGetRequest({
182 path: path + '/root@hello@',
183 token: server.accessToken,
184 expectedStatus: HttpStatusCode.BAD_REQUEST_400
188 it('Should fail with an unknown subscription', async function () {
189 await makeGetRequest({
191 path: path + '/root1@localhost:' + server.port,
192 token: server.accessToken,
193 expectedStatus: HttpStatusCode.NOT_FOUND_404
197 it('Should succeed with the correct parameters', async function () {
198 await makeGetRequest({
200 path: path + '/user1_channel@localhost:' + server.port,
201 token: server.accessToken,
202 expectedStatus: HttpStatusCode.OK_200
207 describe('When checking if subscriptions exist', function () {
208 const existPath = path + '/exist'
210 it('Should fail with a non authenticated user', async function () {
211 await makeGetRequest({
214 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
218 it('Should fail with bad URIs', async function () {
219 await makeGetRequest({
222 query: { uris: 'toto' },
223 token: server.accessToken,
224 expectedStatus: HttpStatusCode.BAD_REQUEST_400
227 await makeGetRequest({
230 query: { 'uris[]': 1 },
231 token: server.accessToken,
232 expectedStatus: HttpStatusCode.BAD_REQUEST_400
236 it('Should succeed with the correct parameters', async function () {
237 await makeGetRequest({
240 query: { 'uris[]': 'coucou@localhost:' + server.port },
241 token: server.accessToken,
242 expectedStatus: HttpStatusCode.OK_200
247 describe('When removing a subscription', function () {
248 it('Should fail with a non authenticated user', async function () {
249 await makeDeleteRequest({
251 path: path + '/user1_channel@localhost:' + server.port,
252 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
256 it('Should fail with bad URIs', async function () {
257 await makeDeleteRequest({
259 path: path + '/root',
260 token: server.accessToken,
261 expectedStatus: HttpStatusCode.BAD_REQUEST_400
264 await makeDeleteRequest({
266 path: path + '/root@',
267 token: server.accessToken,
268 expectedStatus: HttpStatusCode.BAD_REQUEST_400
271 await makeDeleteRequest({
273 path: path + '/root@hello@',
274 token: server.accessToken,
275 expectedStatus: HttpStatusCode.BAD_REQUEST_400
279 it('Should fail with an unknown subscription', async function () {
280 await makeDeleteRequest({
282 path: path + '/root1@localhost:' + server.port,
283 token: server.accessToken,
284 expectedStatus: HttpStatusCode.NOT_FOUND_404
288 it('Should succeed with the correct parameters', async function () {
289 await makeDeleteRequest({
291 path: path + '/user1_channel@localhost:' + server.port,
292 token: server.accessToken,
293 expectedStatus: HttpStatusCode.NO_CONTENT_204
298 after(async function () {
299 await cleanupTests([ server ])