1 /* tslint:disable:no-unused-expression */
15 setAccessTokensToServers,
18 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
20 describe('Test user subscriptions API validators', function () {
21 const path = '/api/v1/users/me/subscriptions'
22 let server: ServerInfo
23 let userAccessToken = ''
24 let userChannelUUID: string
26 // ---------------------------------------------------------------
28 before(async function () {
33 server = await runServer(1)
35 await setAccessTokensToServers([ server ])
39 password: 'my super password'
41 await createUser(server.url, server.accessToken, user.username, user.password)
42 userAccessToken = await userLogin(server, user)
45 const res = await getMyUserInformation(server.url, server.accessToken)
46 userChannelUUID = res.body.videoChannels[ 0 ].uuid
50 describe('When listing my subscriptions', function () {
51 it('Should fail with a bad start pagination', async function () {
52 await checkBadStartPagination(server.url, path, server.accessToken)
55 it('Should fail with a bad count pagination', async function () {
56 await checkBadCountPagination(server.url, path, server.accessToken)
59 it('Should fail with an incorrect sort', async function () {
60 await checkBadSortPagination(server.url, path, server.accessToken)
63 it('Should fail with a non authenticated user', async function () {
64 await makeGetRequest({
67 statusCodeExpected: 401
71 it('Should success with the correct parameters', async function () {
72 await await makeGetRequest({
75 token: userAccessToken,
76 statusCodeExpected: 200
81 describe('When listing my subscriptions videos', function () {
82 const path = '/api/v1/users/me/subscriptions/videos'
84 it('Should fail with a bad start pagination', async function () {
85 await checkBadStartPagination(server.url, path, server.accessToken)
88 it('Should fail with a bad count pagination', async function () {
89 await checkBadCountPagination(server.url, path, server.accessToken)
92 it('Should fail with an incorrect sort', async function () {
93 await checkBadSortPagination(server.url, path, server.accessToken)
96 it('Should fail with a non authenticated user', async function () {
97 await makeGetRequest({
100 statusCodeExpected: 401
104 it('Should success with the correct parameters', async function () {
105 await await makeGetRequest({
108 token: userAccessToken,
109 statusCodeExpected: 200
114 describe('When adding a subscription', function () {
115 it('Should fail with a non authenticated user', async function () {
116 await makePostBodyRequest({
119 fields: { uri: userChannelUUID + '@localhost:9001' },
120 statusCodeExpected: 401
124 it('Should fail with bad URIs', async function () {
125 await makePostBodyRequest({
128 token: server.accessToken,
129 fields: { uri: 'root' },
130 statusCodeExpected: 400
133 await makePostBodyRequest({
136 token: server.accessToken,
137 fields: { uri: 'root@' },
138 statusCodeExpected: 400
141 await makePostBodyRequest({
144 token: server.accessToken,
145 fields: { uri: 'root@hello@' },
146 statusCodeExpected: 400
150 it('Should success with the correct parameters', async function () {
151 await makePostBodyRequest({
154 token: server.accessToken,
155 fields: { uri: userChannelUUID + '@localhost:9001' },
156 statusCodeExpected: 204
161 describe('When removing a subscription', function () {
162 it('Should fail with a non authenticated user', async function () {
163 await makeDeleteRequest({
165 path: path + '/' + userChannelUUID + '@localhost:9001',
166 statusCodeExpected: 401
170 it('Should fail with bad URIs', async function () {
171 await makeDeleteRequest({
173 path: path + '/root',
174 token: server.accessToken,
175 statusCodeExpected: 400
178 await makeDeleteRequest({
180 path: path + '/root@',
181 token: server.accessToken,
182 statusCodeExpected: 400
185 await makeDeleteRequest({
187 path: path + '/root@hello@',
188 token: server.accessToken,
189 statusCodeExpected: 400
193 it('Should fail with an unknown subscription', async function () {
194 await makeDeleteRequest({
196 path: path + '/root1@localhost:9001',
197 token: server.accessToken,
198 statusCodeExpected: 404
202 it('Should success with the correct parameters', async function () {
203 await makeDeleteRequest({
205 path: path + '/' + userChannelUUID + '@localhost:9001',
206 token: server.accessToken,
207 statusCodeExpected: 204
212 after(async function () {
213 killallServers([ server ])
215 // Keep the logs if the test failed