1 /* tslint:disable:no-unused-expression */
14 setAccessTokensToServers,
17 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
19 describe('Test user subscriptions API validators', function () {
20 const path = '/api/v1/users/me/subscriptions'
21 let server: ServerInfo
22 let userAccessToken = ''
24 // ---------------------------------------------------------------
26 before(async function () {
31 server = await runServer(1)
33 await setAccessTokensToServers([ server ])
37 password: 'my super password'
39 await createUser(server.url, server.accessToken, user.username, user.password)
40 userAccessToken = await userLogin(server, user)
43 describe('When listing my subscriptions', function () {
44 it('Should fail with a bad start pagination', async function () {
45 await checkBadStartPagination(server.url, path, server.accessToken)
48 it('Should fail with a bad count pagination', async function () {
49 await checkBadCountPagination(server.url, path, server.accessToken)
52 it('Should fail with an incorrect sort', async function () {
53 await checkBadSortPagination(server.url, path, server.accessToken)
56 it('Should fail with a non authenticated user', async function () {
57 await makeGetRequest({
60 statusCodeExpected: 401
64 it('Should succeed with the correct parameters', async function () {
65 await makeGetRequest({
68 token: userAccessToken,
69 statusCodeExpected: 200
74 describe('When listing my subscriptions videos', function () {
75 const path = '/api/v1/users/me/subscriptions/videos'
77 it('Should fail with a bad start pagination', async function () {
78 await checkBadStartPagination(server.url, path, server.accessToken)
81 it('Should fail with a bad count pagination', async function () {
82 await checkBadCountPagination(server.url, path, server.accessToken)
85 it('Should fail with an incorrect sort', async function () {
86 await checkBadSortPagination(server.url, path, server.accessToken)
89 it('Should fail with a non authenticated user', async function () {
90 await makeGetRequest({
93 statusCodeExpected: 401
97 it('Should succeed with the correct parameters', async function () {
98 await makeGetRequest({
101 token: userAccessToken,
102 statusCodeExpected: 200
107 describe('When adding a subscription', function () {
108 it('Should fail with a non authenticated user', async function () {
109 await makePostBodyRequest({
112 fields: { uri: 'user1_channel@localhost:9001' },
113 statusCodeExpected: 401
117 it('Should fail with bad URIs', async function () {
118 await makePostBodyRequest({
121 token: server.accessToken,
122 fields: { uri: 'root' },
123 statusCodeExpected: 400
126 await makePostBodyRequest({
129 token: server.accessToken,
130 fields: { uri: 'root@' },
131 statusCodeExpected: 400
134 await makePostBodyRequest({
137 token: server.accessToken,
138 fields: { uri: 'root@hello@' },
139 statusCodeExpected: 400
143 it('Should succeed with the correct parameters', async function () {
144 await makePostBodyRequest({
147 token: server.accessToken,
148 fields: { uri: 'user1_channel@localhost:9001' },
149 statusCodeExpected: 204
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:9001',
159 statusCodeExpected: 401
163 it('Should fail with bad URIs', async function () {
164 await makeGetRequest({
166 path: path + '/root',
167 token: server.accessToken,
168 statusCodeExpected: 400
171 await makeGetRequest({
173 path: path + '/root@',
174 token: server.accessToken,
175 statusCodeExpected: 400
178 await makeGetRequest({
180 path: path + '/root@hello@',
181 token: server.accessToken,
182 statusCodeExpected: 400
186 it('Should fail with an unknown subscription', async function () {
187 await makeGetRequest({
189 path: path + '/root1@localhost:9001',
190 token: server.accessToken,
191 statusCodeExpected: 404
195 it('Should succeed with the correct parameters', async function () {
196 await makeGetRequest({
198 path: path + '/user1_channel@localhost:9001',
199 token: server.accessToken,
200 statusCodeExpected: 200
205 describe('When checking if subscriptions exist', async function () {
206 const existPath = path + '/exist'
208 it('Should fail with a non authenticated user', async function () {
209 await makeGetRequest({
212 statusCodeExpected: 401
216 it('Should fail with bad URIs', async function () {
217 await makeGetRequest({
220 query: { uris: 'toto' },
221 token: server.accessToken,
222 statusCodeExpected: 400
225 await makeGetRequest({
228 query: { 'uris[]': 1 },
229 token: server.accessToken,
230 statusCodeExpected: 400
234 it('Should succeed with the correct parameters', async function () {
235 await makeGetRequest({
238 query: { 'uris[]': 'coucou@localhost:9001' },
239 token: server.accessToken,
240 statusCodeExpected: 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:9001',
250 statusCodeExpected: 401
254 it('Should fail with bad URIs', async function () {
255 await makeDeleteRequest({
257 path: path + '/root',
258 token: server.accessToken,
259 statusCodeExpected: 400
262 await makeDeleteRequest({
264 path: path + '/root@',
265 token: server.accessToken,
266 statusCodeExpected: 400
269 await makeDeleteRequest({
271 path: path + '/root@hello@',
272 token: server.accessToken,
273 statusCodeExpected: 400
277 it('Should fail with an unknown subscription', async function () {
278 await makeDeleteRequest({
280 path: path + '/root1@localhost:9001',
281 token: server.accessToken,
282 statusCodeExpected: 404
286 it('Should succeed with the correct parameters', async function () {
287 await makeDeleteRequest({
289 path: path + '/user1_channel@localhost:9001',
290 token: server.accessToken,
291 statusCodeExpected: 204
296 after(async function () {
297 killallServers([ server ])
299 // Keep the logs if the test failed