1 /* tslint:disable:no-unused-expression */
14 setAccessTokensToServers,
16 } from '../../../../shared/utils'
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21 } from '../../../../shared/utils/requests/check-api-params'
23 describe('Test user subscriptions API validators', function () {
24 const path = '/api/v1/users/me/subscriptions'
25 let server: ServerInfo
26 let userAccessToken = ''
28 // ---------------------------------------------------------------
30 before(async function () {
35 server = await runServer(1)
37 await setAccessTokensToServers([ server ])
41 password: 'my super password'
43 await createUser(server.url, server.accessToken, user.username, user.password)
44 userAccessToken = await userLogin(server, user)
47 describe('When listing my subscriptions', function () {
48 it('Should fail with a bad start pagination', async function () {
49 await checkBadStartPagination(server.url, path, server.accessToken)
52 it('Should fail with a bad count pagination', async function () {
53 await checkBadCountPagination(server.url, path, server.accessToken)
56 it('Should fail with an incorrect sort', async function () {
57 await checkBadSortPagination(server.url, path, server.accessToken)
60 it('Should fail with a non authenticated user', async function () {
61 await makeGetRequest({
64 statusCodeExpected: 401
68 it('Should succeed with the correct parameters', async function () {
69 await makeGetRequest({
72 token: userAccessToken,
73 statusCodeExpected: 200
78 describe('When listing my subscriptions videos', function () {
79 const path = '/api/v1/users/me/subscriptions/videos'
81 it('Should fail with a bad start pagination', async function () {
82 await checkBadStartPagination(server.url, path, server.accessToken)
85 it('Should fail with a bad count pagination', async function () {
86 await checkBadCountPagination(server.url, path, server.accessToken)
89 it('Should fail with an incorrect sort', async function () {
90 await checkBadSortPagination(server.url, path, server.accessToken)
93 it('Should fail with a non authenticated user', async function () {
94 await makeGetRequest({
97 statusCodeExpected: 401
101 it('Should succeed with the correct parameters', async function () {
102 await makeGetRequest({
105 token: userAccessToken,
106 statusCodeExpected: 200
111 describe('When adding a subscription', function () {
112 it('Should fail with a non authenticated user', async function () {
113 await makePostBodyRequest({
116 fields: { uri: 'user1_channel@localhost:9001' },
117 statusCodeExpected: 401
121 it('Should fail with bad URIs', async function () {
122 await makePostBodyRequest({
125 token: server.accessToken,
126 fields: { uri: 'root' },
127 statusCodeExpected: 400
130 await makePostBodyRequest({
133 token: server.accessToken,
134 fields: { uri: 'root@' },
135 statusCodeExpected: 400
138 await makePostBodyRequest({
141 token: server.accessToken,
142 fields: { uri: 'root@hello@' },
143 statusCodeExpected: 400
147 it('Should succeed with the correct parameters', async function () {
148 await makePostBodyRequest({
151 token: server.accessToken,
152 fields: { uri: 'user1_channel@localhost:9001' },
153 statusCodeExpected: 204
158 describe('When getting a subscription', function () {
159 it('Should fail with a non authenticated user', async function () {
160 await makeGetRequest({
162 path: path + '/user1_channel@localhost:9001',
163 statusCodeExpected: 401
167 it('Should fail with bad URIs', async function () {
168 await makeGetRequest({
170 path: path + '/root',
171 token: server.accessToken,
172 statusCodeExpected: 400
175 await makeGetRequest({
177 path: path + '/root@',
178 token: server.accessToken,
179 statusCodeExpected: 400
182 await makeGetRequest({
184 path: path + '/root@hello@',
185 token: server.accessToken,
186 statusCodeExpected: 400
190 it('Should fail with an unknown subscription', async function () {
191 await makeGetRequest({
193 path: path + '/root1@localhost:9001',
194 token: server.accessToken,
195 statusCodeExpected: 404
199 it('Should succeed with the correct parameters', async function () {
200 await makeGetRequest({
202 path: path + '/user1_channel@localhost:9001',
203 token: server.accessToken,
204 statusCodeExpected: 200
209 describe('When checking if subscriptions exist', async function () {
210 const existPath = path + '/exist'
212 it('Should fail with a non authenticated user', async function () {
213 await makeGetRequest({
216 statusCodeExpected: 401
220 it('Should fail with bad URIs', async function () {
221 await makeGetRequest({
224 query: { uris: 'toto' },
225 token: server.accessToken,
226 statusCodeExpected: 400
229 await makeGetRequest({
232 query: { 'uris[]': 1 },
233 token: server.accessToken,
234 statusCodeExpected: 400
238 it('Should succeed with the correct parameters', async function () {
239 await makeGetRequest({
242 query: { 'uris[]': 'coucou@localhost:9001' },
243 token: server.accessToken,
244 statusCodeExpected: 200
249 describe('When removing a subscription', function () {
250 it('Should fail with a non authenticated user', async function () {
251 await makeDeleteRequest({
253 path: path + '/user1_channel@localhost:9001',
254 statusCodeExpected: 401
258 it('Should fail with bad URIs', async function () {
259 await makeDeleteRequest({
261 path: path + '/root',
262 token: server.accessToken,
263 statusCodeExpected: 400
266 await makeDeleteRequest({
268 path: path + '/root@',
269 token: server.accessToken,
270 statusCodeExpected: 400
273 await makeDeleteRequest({
275 path: path + '/root@hello@',
276 token: server.accessToken,
277 statusCodeExpected: 400
281 it('Should fail with an unknown subscription', async function () {
282 await makeDeleteRequest({
284 path: path + '/root1@localhost:9001',
285 token: server.accessToken,
286 statusCodeExpected: 404
290 it('Should succeed with the correct parameters', async function () {
291 await makeDeleteRequest({
293 path: path + '/user1_channel@localhost:9001',
294 token: server.accessToken,
295 statusCodeExpected: 204
300 after(async function () {
301 killallServers([ server ])
303 // Keep the logs if the test failed