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 removing a subscription', function () {
206 it('Should fail with a non authenticated user', async function () {
207 await makeDeleteRequest({
209 path: path + '/user1_channel@localhost:9001',
210 statusCodeExpected: 401
214 it('Should fail with bad URIs', async function () {
215 await makeDeleteRequest({
217 path: path + '/root',
218 token: server.accessToken,
219 statusCodeExpected: 400
222 await makeDeleteRequest({
224 path: path + '/root@',
225 token: server.accessToken,
226 statusCodeExpected: 400
229 await makeDeleteRequest({
231 path: path + '/root@hello@',
232 token: server.accessToken,
233 statusCodeExpected: 400
237 it('Should fail with an unknown subscription', async function () {
238 await makeDeleteRequest({
240 path: path + '/root1@localhost:9001',
241 token: server.accessToken,
242 statusCodeExpected: 404
246 it('Should succeed with the correct parameters', async function () {
247 await makeDeleteRequest({
249 path: path + '/user1_channel@localhost:9001',
250 token: server.accessToken,
251 statusCodeExpected: 204
256 after(async function () {
257 killallServers([ server ])
259 // Keep the logs if the test failed