1 /* tslint:disable:no-unused-expression */
14 setAccessTokensToServers,
17 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
18 import { waitJobs } from '../../utils/server/jobs'
20 describe('Test user subscriptions API validators', function () {
21 const path = '/api/v1/users/me/subscriptions'
22 let server: ServerInfo
23 let userAccessToken = ''
25 // ---------------------------------------------------------------
27 before(async function () {
32 server = await runServer(1)
34 await setAccessTokensToServers([ server ])
38 password: 'my super password'
40 await createUser(server.url, server.accessToken, user.username, user.password)
41 userAccessToken = await userLogin(server, user)
44 describe('When listing my subscriptions', function () {
45 it('Should fail with a bad start pagination', async function () {
46 await checkBadStartPagination(server.url, path, server.accessToken)
49 it('Should fail with a bad count pagination', async function () {
50 await checkBadCountPagination(server.url, path, server.accessToken)
53 it('Should fail with an incorrect sort', async function () {
54 await checkBadSortPagination(server.url, path, server.accessToken)
57 it('Should fail with a non authenticated user', async function () {
58 await makeGetRequest({
61 statusCodeExpected: 401
65 it('Should succeed with the correct parameters', async function () {
66 await makeGetRequest({
69 token: userAccessToken,
70 statusCodeExpected: 200
75 describe('When listing my subscriptions videos', function () {
76 const path = '/api/v1/users/me/subscriptions/videos'
78 it('Should fail with a bad start pagination', async function () {
79 await checkBadStartPagination(server.url, path, server.accessToken)
82 it('Should fail with a bad count pagination', async function () {
83 await checkBadCountPagination(server.url, path, server.accessToken)
86 it('Should fail with an incorrect sort', async function () {
87 await checkBadSortPagination(server.url, path, server.accessToken)
90 it('Should fail with a non authenticated user', async function () {
91 await makeGetRequest({
94 statusCodeExpected: 401
98 it('Should succeed with the correct parameters', async function () {
99 await makeGetRequest({
102 token: userAccessToken,
103 statusCodeExpected: 200
108 describe('When adding a subscription', function () {
109 it('Should fail with a non authenticated user', async function () {
110 await makePostBodyRequest({
113 fields: { uri: 'user1_channel@localhost:9001' },
114 statusCodeExpected: 401
118 it('Should fail with bad URIs', async function () {
119 await makePostBodyRequest({
122 token: server.accessToken,
123 fields: { uri: 'root' },
124 statusCodeExpected: 400
127 await makePostBodyRequest({
130 token: server.accessToken,
131 fields: { uri: 'root@' },
132 statusCodeExpected: 400
135 await makePostBodyRequest({
138 token: server.accessToken,
139 fields: { uri: 'root@hello@' },
140 statusCodeExpected: 400
144 it('Should succeed with the correct parameters', async function () {
147 await makePostBodyRequest({
150 token: server.accessToken,
151 fields: { uri: 'user1_channel@localhost:9001' },
152 statusCodeExpected: 204
155 await waitJobs([ server ])
159 describe('When getting a subscription', function () {
160 it('Should fail with a non authenticated user', async function () {
161 await makeGetRequest({
163 path: path + '/user1_channel@localhost:9001',
164 statusCodeExpected: 401
168 it('Should fail with bad URIs', async function () {
169 await makeGetRequest({
171 path: path + '/root',
172 token: server.accessToken,
173 statusCodeExpected: 400
176 await makeGetRequest({
178 path: path + '/root@',
179 token: server.accessToken,
180 statusCodeExpected: 400
183 await makeGetRequest({
185 path: path + '/root@hello@',
186 token: server.accessToken,
187 statusCodeExpected: 400
191 it('Should fail with an unknown subscription', async function () {
192 await makeGetRequest({
194 path: path + '/root1@localhost:9001',
195 token: server.accessToken,
196 statusCodeExpected: 404
200 it('Should succeed with the correct parameters', async function () {
201 await makeGetRequest({
203 path: path + '/user1_channel@localhost:9001',
204 token: server.accessToken,
205 statusCodeExpected: 200
210 describe('When checking if subscriptions exist', async function () {
211 const existPath = path + '/exist'
213 it('Should fail with a non authenticated user', async function () {
214 await makeGetRequest({
217 statusCodeExpected: 401
221 it('Should fail with bad URIs', async function () {
222 await makeGetRequest({
225 query: { uris: 'toto' },
226 token: server.accessToken,
227 statusCodeExpected: 400
230 await makeGetRequest({
233 query: { 'uris[]': 1 },
234 token: server.accessToken,
235 statusCodeExpected: 400
239 it('Should succeed with the correct parameters', async function () {
240 await makeGetRequest({
243 query: { 'uris[]': 'coucou@localhost:9001' },
244 token: server.accessToken,
245 statusCodeExpected: 200
250 describe('When removing a subscription', function () {
251 it('Should fail with a non authenticated user', async function () {
252 await makeDeleteRequest({
254 path: path + '/user1_channel@localhost:9001',
255 statusCodeExpected: 401
259 it('Should fail with bad URIs', async function () {
260 await makeDeleteRequest({
262 path: path + '/root',
263 token: server.accessToken,
264 statusCodeExpected: 400
267 await makeDeleteRequest({
269 path: path + '/root@',
270 token: server.accessToken,
271 statusCodeExpected: 400
274 await makeDeleteRequest({
276 path: path + '/root@hello@',
277 token: server.accessToken,
278 statusCodeExpected: 400
282 it('Should fail with an unknown subscription', async function () {
283 await makeDeleteRequest({
285 path: path + '/root1@localhost:9001',
286 token: server.accessToken,
287 statusCodeExpected: 404
291 it('Should succeed with the correct parameters', async function () {
292 await makeDeleteRequest({
294 path: path + '/user1_channel@localhost:9001',
295 token: server.accessToken,
296 statusCodeExpected: 204
301 after(async function () {
302 killallServers([ server ])
304 // Keep the logs if the test failed