1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
11 setAccessTokensToServers,
13 } from '@shared/server-commands'
14 import { HttpStatusCode } from '@shared/models'
15 import { checkBadStartPagination, checkBadCountPagination, checkBadSortPagination } from '@server/tests/shared'
17 describe('Test user subscriptions API validators', function () {
18 const path = '/api/v1/users/me/subscriptions'
19 let server: PeerTubeServer
20 let userAccessToken = ''
22 // ---------------------------------------------------------------
24 before(async function () {
27 server = await createSingleServer(1)
29 await setAccessTokensToServers([ server ])
33 password: 'my super password'
35 await server.users.create({ username: user.username, password: user.password })
36 userAccessToken = await server.login.getAccessToken(user)
39 describe('When listing my subscriptions', function () {
40 it('Should fail with a bad start pagination', async function () {
41 await checkBadStartPagination(server.url, path, server.accessToken)
44 it('Should fail with a bad count pagination', async function () {
45 await checkBadCountPagination(server.url, path, server.accessToken)
48 it('Should fail with an incorrect sort', async function () {
49 await checkBadSortPagination(server.url, path, server.accessToken)
52 it('Should fail with a non authenticated user', async function () {
53 await makeGetRequest({
56 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
60 it('Should succeed with the correct parameters', async function () {
61 await makeGetRequest({
64 token: userAccessToken,
65 expectedStatus: HttpStatusCode.OK_200
70 describe('When listing my subscriptions videos', function () {
71 const path = '/api/v1/users/me/subscriptions/videos'
73 it('Should fail with a bad start pagination', async function () {
74 await checkBadStartPagination(server.url, path, server.accessToken)
77 it('Should fail with a bad count pagination', async function () {
78 await checkBadCountPagination(server.url, path, server.accessToken)
81 it('Should fail with an incorrect sort', async function () {
82 await checkBadSortPagination(server.url, path, server.accessToken)
85 it('Should fail with a non authenticated user', async function () {
86 await makeGetRequest({
89 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
93 it('Should succeed with the correct parameters', async function () {
94 await makeGetRequest({
97 token: userAccessToken,
98 expectedStatus: HttpStatusCode.OK_200
103 describe('When adding a subscription', function () {
104 it('Should fail with a non authenticated user', async function () {
105 await makePostBodyRequest({
108 fields: { uri: 'user1_channel@localhost:' + server.port },
109 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
113 it('Should fail with bad URIs', async function () {
114 await makePostBodyRequest({
117 token: server.accessToken,
118 fields: { uri: 'root' },
119 expectedStatus: HttpStatusCode.BAD_REQUEST_400
122 await makePostBodyRequest({
125 token: server.accessToken,
126 fields: { uri: 'root@' },
127 expectedStatus: HttpStatusCode.BAD_REQUEST_400
130 await makePostBodyRequest({
133 token: server.accessToken,
134 fields: { uri: 'root@hello@' },
135 expectedStatus: HttpStatusCode.BAD_REQUEST_400
139 it('Should succeed with the correct parameters', async function () {
142 await makePostBodyRequest({
145 token: server.accessToken,
146 fields: { uri: 'user1_channel@localhost:' + server.port },
147 expectedStatus: HttpStatusCode.NO_CONTENT_204
150 await waitJobs([ server ])
154 describe('When getting a subscription', function () {
155 it('Should fail with a non authenticated user', async function () {
156 await makeGetRequest({
158 path: path + '/user1_channel@localhost:' + server.port,
159 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
163 it('Should fail with bad URIs', async function () {
164 await makeGetRequest({
166 path: path + '/root',
167 token: server.accessToken,
168 expectedStatus: HttpStatusCode.BAD_REQUEST_400
171 await makeGetRequest({
173 path: path + '/root@',
174 token: server.accessToken,
175 expectedStatus: HttpStatusCode.BAD_REQUEST_400
178 await makeGetRequest({
180 path: path + '/root@hello@',
181 token: server.accessToken,
182 expectedStatus: HttpStatusCode.BAD_REQUEST_400
186 it('Should fail with an unknown subscription', async function () {
187 await makeGetRequest({
189 path: path + '/root1@localhost:' + server.port,
190 token: server.accessToken,
191 expectedStatus: HttpStatusCode.NOT_FOUND_404
195 it('Should succeed with the correct parameters', async function () {
196 await makeGetRequest({
198 path: path + '/user1_channel@localhost:' + server.port,
199 token: server.accessToken,
200 expectedStatus: HttpStatusCode.OK_200
205 describe('When checking if subscriptions exist', function () {
206 const existPath = path + '/exist'
208 it('Should fail with a non authenticated user', async function () {
209 await makeGetRequest({
212 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
216 it('Should fail with bad URIs', async function () {
217 await makeGetRequest({
220 query: { uris: 'toto' },
221 token: server.accessToken,
222 expectedStatus: HttpStatusCode.BAD_REQUEST_400
225 await makeGetRequest({
228 query: { 'uris[]': 1 },
229 token: server.accessToken,
230 expectedStatus: HttpStatusCode.BAD_REQUEST_400
234 it('Should succeed with the correct parameters', async function () {
235 await makeGetRequest({
238 query: { 'uris[]': 'coucou@localhost:' + server.port },
239 token: server.accessToken,
240 expectedStatus: HttpStatusCode.OK_200
245 describe('When removing a subscription', function () {
246 it('Should fail with a non authenticated user', async function () {
247 await makeDeleteRequest({
249 path: path + '/user1_channel@localhost:' + server.port,
250 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
254 it('Should fail with bad URIs', async function () {
255 await makeDeleteRequest({
257 path: path + '/root',
258 token: server.accessToken,
259 expectedStatus: HttpStatusCode.BAD_REQUEST_400
262 await makeDeleteRequest({
264 path: path + '/root@',
265 token: server.accessToken,
266 expectedStatus: HttpStatusCode.BAD_REQUEST_400
269 await makeDeleteRequest({
271 path: path + '/root@hello@',
272 token: server.accessToken,
273 expectedStatus: HttpStatusCode.BAD_REQUEST_400
277 it('Should fail with an unknown subscription', async function () {
278 await makeDeleteRequest({
280 path: path + '/root1@localhost:' + server.port,
281 token: server.accessToken,
282 expectedStatus: HttpStatusCode.NOT_FOUND_404
286 it('Should succeed with the correct parameters', async function () {
287 await makeDeleteRequest({
289 path: path + '/user1_channel@localhost:' + server.port,
290 token: server.accessToken,
291 expectedStatus: HttpStatusCode.NO_CONTENT_204
296 after(async function () {
297 await cleanupTests([ server ])