1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
13 import { HttpStatusCode } from '@shared/models'
14 import { checkBadStartPagination, checkBadCountPagination, checkBadSortPagination } from '@server/tests/shared'
16 describe('Test user subscriptions API validators', function () {
17 const path = '/api/v1/users/me/subscriptions'
18 let server: PeerTubeServer
19 let userAccessToken = ''
21 // ---------------------------------------------------------------
23 before(async function () {
26 server = await createSingleServer(1)
28 await setAccessTokensToServers([ server ])
32 password: 'my super password'
34 await server.users.create({ username: user.username, password: user.password })
35 userAccessToken = await server.login.getAccessToken(user)
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)
43 it('Should fail with a bad count pagination', async function () {
44 await checkBadCountPagination(server.url, path, server.accessToken)
47 it('Should fail with an incorrect sort', async function () {
48 await checkBadSortPagination(server.url, path, server.accessToken)
51 it('Should fail with a non authenticated user', async function () {
52 await makeGetRequest({
55 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
59 it('Should succeed with the correct parameters', async function () {
60 await makeGetRequest({
63 token: userAccessToken,
64 expectedStatus: HttpStatusCode.OK_200
69 describe('When listing my subscriptions videos', function () {
70 const path = '/api/v1/users/me/subscriptions/videos'
72 it('Should fail with a bad start pagination', async function () {
73 await checkBadStartPagination(server.url, path, server.accessToken)
76 it('Should fail with a bad count pagination', async function () {
77 await checkBadCountPagination(server.url, path, server.accessToken)
80 it('Should fail with an incorrect sort', async function () {
81 await checkBadSortPagination(server.url, path, server.accessToken)
84 it('Should fail with a non authenticated user', async function () {
85 await makeGetRequest({
88 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
92 it('Should succeed with the correct parameters', async function () {
93 await makeGetRequest({
96 token: userAccessToken,
97 expectedStatus: HttpStatusCode.OK_200
102 describe('When adding a subscription', function () {
103 it('Should fail with a non authenticated user', async function () {
104 await makePostBodyRequest({
107 fields: { uri: 'user1_channel@' + server.host },
108 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
112 it('Should fail with bad URIs', async function () {
113 await makePostBodyRequest({
116 token: server.accessToken,
117 fields: { uri: 'root' },
118 expectedStatus: HttpStatusCode.BAD_REQUEST_400
121 await makePostBodyRequest({
124 token: server.accessToken,
125 fields: { uri: 'root@' },
126 expectedStatus: HttpStatusCode.BAD_REQUEST_400
129 await makePostBodyRequest({
132 token: server.accessToken,
133 fields: { uri: 'root@hello@' },
134 expectedStatus: HttpStatusCode.BAD_REQUEST_400
138 it('Should succeed with the correct parameters', async function () {
141 await makePostBodyRequest({
144 token: server.accessToken,
145 fields: { uri: 'user1_channel@' + server.host },
146 expectedStatus: HttpStatusCode.NO_CONTENT_204
149 await waitJobs([ server ])
153 describe('When getting a subscription', function () {
154 it('Should fail with a non authenticated user', async function () {
155 await makeGetRequest({
157 path: path + '/user1_channel@' + server.host,
158 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
162 it('Should fail with bad URIs', async function () {
163 await makeGetRequest({
165 path: path + '/root',
166 token: server.accessToken,
167 expectedStatus: HttpStatusCode.BAD_REQUEST_400
170 await makeGetRequest({
172 path: path + '/root@',
173 token: server.accessToken,
174 expectedStatus: HttpStatusCode.BAD_REQUEST_400
177 await makeGetRequest({
179 path: path + '/root@hello@',
180 token: server.accessToken,
181 expectedStatus: HttpStatusCode.BAD_REQUEST_400
185 it('Should fail with an unknown subscription', async function () {
186 await makeGetRequest({
188 path: path + '/root1@' + server.host,
189 token: server.accessToken,
190 expectedStatus: HttpStatusCode.NOT_FOUND_404
194 it('Should succeed with the correct parameters', async function () {
195 await makeGetRequest({
197 path: path + '/user1_channel@' + server.host,
198 token: server.accessToken,
199 expectedStatus: HttpStatusCode.OK_200
204 describe('When checking if subscriptions exist', function () {
205 const existPath = path + '/exist'
207 it('Should fail with a non authenticated user', async function () {
208 await makeGetRequest({
211 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
215 it('Should fail with bad URIs', async function () {
216 await makeGetRequest({
219 query: { uris: 'toto' },
220 token: server.accessToken,
221 expectedStatus: HttpStatusCode.BAD_REQUEST_400
224 await makeGetRequest({
227 query: { 'uris[]': 1 },
228 token: server.accessToken,
229 expectedStatus: HttpStatusCode.BAD_REQUEST_400
233 it('Should succeed with the correct parameters', async function () {
234 await makeGetRequest({
237 query: { 'uris[]': 'coucou@' + server.host },
238 token: server.accessToken,
239 expectedStatus: HttpStatusCode.OK_200
244 describe('When removing a subscription', function () {
245 it('Should fail with a non authenticated user', async function () {
246 await makeDeleteRequest({
248 path: path + '/user1_channel@' + server.host,
249 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
253 it('Should fail with bad URIs', async function () {
254 await makeDeleteRequest({
256 path: path + '/root',
257 token: server.accessToken,
258 expectedStatus: HttpStatusCode.BAD_REQUEST_400
261 await makeDeleteRequest({
263 path: path + '/root@',
264 token: server.accessToken,
265 expectedStatus: HttpStatusCode.BAD_REQUEST_400
268 await makeDeleteRequest({
270 path: path + '/root@hello@',
271 token: server.accessToken,
272 expectedStatus: HttpStatusCode.BAD_REQUEST_400
276 it('Should fail with an unknown subscription', async function () {
277 await makeDeleteRequest({
279 path: path + '/root1@' + server.host,
280 token: server.accessToken,
281 expectedStatus: HttpStatusCode.NOT_FOUND_404
285 it('Should succeed with the correct parameters', async function () {
286 await makeDeleteRequest({
288 path: path + '/user1_channel@' + server.host,
289 token: server.accessToken,
290 expectedStatus: HttpStatusCode.NO_CONTENT_204
295 after(async function () {
296 await cleanupTests([ server ])