1 /* tslint:disable:no-unused-expression */
14 setAccessTokensToServers,
16 } from '../../../../shared/utils'
19 checkBadCountPagination,
20 checkBadSortPagination,
21 checkBadStartPagination
22 } from '../../../../shared/utils/requests/check-api-params'
23 import { waitJobs } from '../../../../shared/utils/server/jobs'
25 describe('Test user subscriptions API validators', function () {
26 const path = '/api/v1/users/me/subscriptions'
27 let server: ServerInfo
28 let userAccessToken = ''
30 // ---------------------------------------------------------------
32 before(async function () {
37 server = await runServer(1)
39 await setAccessTokensToServers([ server ])
43 password: 'my super password'
45 await createUser(server.url, server.accessToken, user.username, user.password)
46 userAccessToken = await userLogin(server, user)
49 describe('When listing my subscriptions', function () {
50 it('Should fail with a bad start pagination', async function () {
51 await checkBadStartPagination(server.url, path, server.accessToken)
54 it('Should fail with a bad count pagination', async function () {
55 await checkBadCountPagination(server.url, path, server.accessToken)
58 it('Should fail with an incorrect sort', async function () {
59 await checkBadSortPagination(server.url, path, server.accessToken)
62 it('Should fail with a non authenticated user', async function () {
63 await makeGetRequest({
66 statusCodeExpected: 401
70 it('Should succeed with the correct parameters', async function () {
71 await makeGetRequest({
74 token: userAccessToken,
75 statusCodeExpected: 200
80 describe('When listing my subscriptions videos', function () {
81 const path = '/api/v1/users/me/subscriptions/videos'
83 it('Should fail with a bad start pagination', async function () {
84 await checkBadStartPagination(server.url, path, server.accessToken)
87 it('Should fail with a bad count pagination', async function () {
88 await checkBadCountPagination(server.url, path, server.accessToken)
91 it('Should fail with an incorrect sort', async function () {
92 await checkBadSortPagination(server.url, path, server.accessToken)
95 it('Should fail with a non authenticated user', async function () {
96 await makeGetRequest({
99 statusCodeExpected: 401
103 it('Should succeed with the correct parameters', async function () {
104 await makeGetRequest({
107 token: userAccessToken,
108 statusCodeExpected: 200
113 describe('When adding a subscription', function () {
114 it('Should fail with a non authenticated user', async function () {
115 await makePostBodyRequest({
118 fields: { uri: 'user1_channel@localhost:9001' },
119 statusCodeExpected: 401
123 it('Should fail with bad URIs', async function () {
124 await makePostBodyRequest({
127 token: server.accessToken,
128 fields: { uri: 'root' },
129 statusCodeExpected: 400
132 await makePostBodyRequest({
135 token: server.accessToken,
136 fields: { uri: 'root@' },
137 statusCodeExpected: 400
140 await makePostBodyRequest({
143 token: server.accessToken,
144 fields: { uri: 'root@hello@' },
145 statusCodeExpected: 400
149 it('Should succeed with the correct parameters', async function () {
152 await makePostBodyRequest({
155 token: server.accessToken,
156 fields: { uri: 'user1_channel@localhost:9001' },
157 statusCodeExpected: 204
160 await waitJobs([ server ])
164 describe('When getting a subscription', function () {
165 it('Should fail with a non authenticated user', async function () {
166 await makeGetRequest({
168 path: path + '/user1_channel@localhost:9001',
169 statusCodeExpected: 401
173 it('Should fail with bad URIs', async function () {
174 await makeGetRequest({
176 path: path + '/root',
177 token: server.accessToken,
178 statusCodeExpected: 400
181 await makeGetRequest({
183 path: path + '/root@',
184 token: server.accessToken,
185 statusCodeExpected: 400
188 await makeGetRequest({
190 path: path + '/root@hello@',
191 token: server.accessToken,
192 statusCodeExpected: 400
196 it('Should fail with an unknown subscription', async function () {
197 await makeGetRequest({
199 path: path + '/root1@localhost:9001',
200 token: server.accessToken,
201 statusCodeExpected: 404
205 it('Should succeed with the correct parameters', async function () {
206 await makeGetRequest({
208 path: path + '/user1_channel@localhost:9001',
209 token: server.accessToken,
210 statusCodeExpected: 200
215 describe('When checking if subscriptions exist', async function () {
216 const existPath = path + '/exist'
218 it('Should fail with a non authenticated user', async function () {
219 await makeGetRequest({
222 statusCodeExpected: 401
226 it('Should fail with bad URIs', async function () {
227 await makeGetRequest({
230 query: { uris: 'toto' },
231 token: server.accessToken,
232 statusCodeExpected: 400
235 await makeGetRequest({
238 query: { 'uris[]': 1 },
239 token: server.accessToken,
240 statusCodeExpected: 400
244 it('Should succeed with the correct parameters', async function () {
245 await makeGetRequest({
248 query: { 'uris[]': 'coucou@localhost:9001' },
249 token: server.accessToken,
250 statusCodeExpected: 200
255 describe('When removing a subscription', function () {
256 it('Should fail with a non authenticated user', async function () {
257 await makeDeleteRequest({
259 path: path + '/user1_channel@localhost:9001',
260 statusCodeExpected: 401
264 it('Should fail with bad URIs', async function () {
265 await makeDeleteRequest({
267 path: path + '/root',
268 token: server.accessToken,
269 statusCodeExpected: 400
272 await makeDeleteRequest({
274 path: path + '/root@',
275 token: server.accessToken,
276 statusCodeExpected: 400
279 await makeDeleteRequest({
281 path: path + '/root@hello@',
282 token: server.accessToken,
283 statusCodeExpected: 400
287 it('Should fail with an unknown subscription', async function () {
288 await makeDeleteRequest({
290 path: path + '/root1@localhost:9001',
291 token: server.accessToken,
292 statusCodeExpected: 404
296 it('Should succeed with the correct parameters', async function () {
297 await makeDeleteRequest({
299 path: path + '/user1_channel@localhost:9001',
300 token: server.accessToken,
301 statusCodeExpected: 204
306 after(async function () {
307 killallServers([ server ])
309 // Keep the logs if the test failed