1 /* tslint:disable:no-unused-expression */
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'
24 describe('Test user subscriptions API validators', function () {
25 const path = '/api/v1/users/me/subscriptions'
26 let server: ServerInfo
27 let userAccessToken = ''
29 // ---------------------------------------------------------------
31 before(async function () {
34 server = await flushAndRunServer(1)
36 await setAccessTokensToServers([ server ])
40 password: 'my super password'
42 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
43 userAccessToken = await userLogin(server, user)
46 describe('When listing my subscriptions', function () {
47 it('Should fail with a bad start pagination', async function () {
48 await checkBadStartPagination(server.url, path, server.accessToken)
51 it('Should fail with a bad count pagination', async function () {
52 await checkBadCountPagination(server.url, path, server.accessToken)
55 it('Should fail with an incorrect sort', async function () {
56 await checkBadSortPagination(server.url, path, server.accessToken)
59 it('Should fail with a non authenticated user', async function () {
60 await makeGetRequest({
63 statusCodeExpected: 401
67 it('Should succeed with the correct parameters', async function () {
68 await makeGetRequest({
71 token: userAccessToken,
72 statusCodeExpected: 200
77 describe('When listing my subscriptions videos', function () {
78 const path = '/api/v1/users/me/subscriptions/videos'
80 it('Should fail with a bad start pagination', async function () {
81 await checkBadStartPagination(server.url, path, server.accessToken)
84 it('Should fail with a bad count pagination', async function () {
85 await checkBadCountPagination(server.url, path, server.accessToken)
88 it('Should fail with an incorrect sort', async function () {
89 await checkBadSortPagination(server.url, path, server.accessToken)
92 it('Should fail with a non authenticated user', async function () {
93 await makeGetRequest({
96 statusCodeExpected: 401
100 it('Should succeed with the correct parameters', async function () {
101 await makeGetRequest({
104 token: userAccessToken,
105 statusCodeExpected: 200
110 describe('When adding a subscription', function () {
111 it('Should fail with a non authenticated user', async function () {
112 await makePostBodyRequest({
115 fields: { uri: 'user1_channel@localhost:' + server.port },
116 statusCodeExpected: 401
120 it('Should fail with bad URIs', async function () {
121 await makePostBodyRequest({
124 token: server.accessToken,
125 fields: { uri: 'root' },
126 statusCodeExpected: 400
129 await makePostBodyRequest({
132 token: server.accessToken,
133 fields: { uri: 'root@' },
134 statusCodeExpected: 400
137 await makePostBodyRequest({
140 token: server.accessToken,
141 fields: { uri: 'root@hello@' },
142 statusCodeExpected: 400
146 it('Should succeed with the correct parameters', async function () {
149 await makePostBodyRequest({
152 token: server.accessToken,
153 fields: { uri: 'user1_channel@localhost:' + server.port },
154 statusCodeExpected: 204
157 await waitJobs([ server ])
161 describe('When getting a subscription', function () {
162 it('Should fail with a non authenticated user', async function () {
163 await makeGetRequest({
165 path: path + '/user1_channel@localhost:' + server.port,
166 statusCodeExpected: 401
170 it('Should fail with bad URIs', async function () {
171 await makeGetRequest({
173 path: path + '/root',
174 token: server.accessToken,
175 statusCodeExpected: 400
178 await makeGetRequest({
180 path: path + '/root@',
181 token: server.accessToken,
182 statusCodeExpected: 400
185 await makeGetRequest({
187 path: path + '/root@hello@',
188 token: server.accessToken,
189 statusCodeExpected: 400
193 it('Should fail with an unknown subscription', async function () {
194 await makeGetRequest({
196 path: path + '/root1@localhost:' + server.port,
197 token: server.accessToken,
198 statusCodeExpected: 404
202 it('Should succeed with the correct parameters', async function () {
203 await makeGetRequest({
205 path: path + '/user1_channel@localhost:' + server.port,
206 token: server.accessToken,
207 statusCodeExpected: 200
212 describe('When checking if subscriptions exist', function () {
213 const existPath = path + '/exist'
215 it('Should fail with a non authenticated user', async function () {
216 await makeGetRequest({
219 statusCodeExpected: 401
223 it('Should fail with bad URIs', async function () {
224 await makeGetRequest({
227 query: { uris: 'toto' },
228 token: server.accessToken,
229 statusCodeExpected: 400
232 await makeGetRequest({
235 query: { 'uris[]': 1 },
236 token: server.accessToken,
237 statusCodeExpected: 400
241 it('Should succeed with the correct parameters', async function () {
242 await makeGetRequest({
245 query: { 'uris[]': 'coucou@localhost:' + server.port },
246 token: server.accessToken,
247 statusCodeExpected: 200
252 describe('When removing a subscription', function () {
253 it('Should fail with a non authenticated user', async function () {
254 await makeDeleteRequest({
256 path: path + '/user1_channel@localhost:' + server.port,
257 statusCodeExpected: 401
261 it('Should fail with bad URIs', async function () {
262 await makeDeleteRequest({
264 path: path + '/root',
265 token: server.accessToken,
266 statusCodeExpected: 400
269 await makeDeleteRequest({
271 path: path + '/root@',
272 token: server.accessToken,
273 statusCodeExpected: 400
276 await makeDeleteRequest({
278 path: path + '/root@hello@',
279 token: server.accessToken,
280 statusCodeExpected: 400
284 it('Should fail with an unknown subscription', async function () {
285 await makeDeleteRequest({
287 path: path + '/root1@localhost:' + server.port,
288 token: server.accessToken,
289 statusCodeExpected: 404
293 it('Should succeed with the correct parameters', async function () {
294 await makeDeleteRequest({
296 path: path + '/user1_channel@localhost:' + server.port,
297 token: server.accessToken,
298 statusCodeExpected: 204
303 after(async function () {
304 await cleanupTests([ server ])