aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts220
2 files changed, 221 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 03fdd5c4e..777acbb0f 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -12,3 +12,4 @@ import './video-comments'
12import './videos' 12import './videos'
13import './video-imports' 13import './video-imports'
14import './search' 14import './search'
15import './user-subscriptions'
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
new file mode 100644
index 000000000..9f7d15b27
--- /dev/null
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -0,0 +1,220 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 flushTests,
8 getMyUserInformation,
9 killallServers,
10 makeDeleteRequest,
11 makeGetRequest,
12 makePostBodyRequest,
13 runServer,
14 ServerInfo,
15 setAccessTokensToServers,
16 userLogin
17} from '../../utils'
18import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
19
20describe('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
25
26 // ---------------------------------------------------------------
27
28 before(async function () {
29 this.timeout(30000)
30
31 await flushTests()
32
33 server = await runServer(1)
34
35 await setAccessTokensToServers([ server ])
36
37 const user = {
38 username: 'user1',
39 password: 'my super password'
40 }
41 await createUser(server.url, server.accessToken, user.username, user.password)
42 userAccessToken = await userLogin(server, user)
43
44 {
45 const res = await getMyUserInformation(server.url, server.accessToken)
46 userChannelUUID = res.body.videoChannels[ 0 ].uuid
47 }
48 })
49
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)
53 })
54
55 it('Should fail with a bad count pagination', async function () {
56 await checkBadCountPagination(server.url, path, server.accessToken)
57 })
58
59 it('Should fail with an incorrect sort', async function () {
60 await checkBadSortPagination(server.url, path, server.accessToken)
61 })
62
63 it('Should fail with a non authenticated user', async function () {
64 await makeGetRequest({
65 url: server.url,
66 path,
67 statusCodeExpected: 401
68 })
69 })
70
71 it('Should success with the correct parameters', async function () {
72 await await makeGetRequest({
73 url: server.url,
74 path,
75 token: userAccessToken,
76 statusCodeExpected: 200
77 })
78 })
79 })
80
81 describe('When listing my subscriptions videos', function () {
82 const path = '/api/v1/users/me/subscriptions/videos'
83
84 it('Should fail with a bad start pagination', async function () {
85 await checkBadStartPagination(server.url, path, server.accessToken)
86 })
87
88 it('Should fail with a bad count pagination', async function () {
89 await checkBadCountPagination(server.url, path, server.accessToken)
90 })
91
92 it('Should fail with an incorrect sort', async function () {
93 await checkBadSortPagination(server.url, path, server.accessToken)
94 })
95
96 it('Should fail with a non authenticated user', async function () {
97 await makeGetRequest({
98 url: server.url,
99 path,
100 statusCodeExpected: 401
101 })
102 })
103
104 it('Should success with the correct parameters', async function () {
105 await await makeGetRequest({
106 url: server.url,
107 path,
108 token: userAccessToken,
109 statusCodeExpected: 200
110 })
111 })
112 })
113
114 describe('When adding a subscription', function () {
115 it('Should fail with a non authenticated user', async function () {
116 await makePostBodyRequest({
117 url: server.url,
118 path,
119 fields: { uri: userChannelUUID + '@localhost:9001' },
120 statusCodeExpected: 401
121 })
122 })
123
124 it('Should fail with bad URIs', async function () {
125 await makePostBodyRequest({
126 url: server.url,
127 path,
128 token: server.accessToken,
129 fields: { uri: 'root' },
130 statusCodeExpected: 400
131 })
132
133 await makePostBodyRequest({
134 url: server.url,
135 path,
136 token: server.accessToken,
137 fields: { uri: 'root@' },
138 statusCodeExpected: 400
139 })
140
141 await makePostBodyRequest({
142 url: server.url,
143 path,
144 token: server.accessToken,
145 fields: { uri: 'root@hello@' },
146 statusCodeExpected: 400
147 })
148 })
149
150 it('Should success with the correct parameters', async function () {
151 await makePostBodyRequest({
152 url: server.url,
153 path,
154 token: server.accessToken,
155 fields: { uri: userChannelUUID + '@localhost:9001' },
156 statusCodeExpected: 204
157 })
158 })
159 })
160
161 describe('When removing a subscription', function () {
162 it('Should fail with a non authenticated user', async function () {
163 await makeDeleteRequest({
164 url: server.url,
165 path: path + '/' + userChannelUUID + '@localhost:9001',
166 statusCodeExpected: 401
167 })
168 })
169
170 it('Should fail with bad URIs', async function () {
171 await makeDeleteRequest({
172 url: server.url,
173 path: path + '/root',
174 token: server.accessToken,
175 statusCodeExpected: 400
176 })
177
178 await makeDeleteRequest({
179 url: server.url,
180 path: path + '/root@',
181 token: server.accessToken,
182 statusCodeExpected: 400
183 })
184
185 await makeDeleteRequest({
186 url: server.url,
187 path: path + '/root@hello@',
188 token: server.accessToken,
189 statusCodeExpected: 400
190 })
191 })
192
193 it('Should fail with an unknown subscription', async function () {
194 await makeDeleteRequest({
195 url: server.url,
196 path: path + '/root1@localhost:9001',
197 token: server.accessToken,
198 statusCodeExpected: 404
199 })
200 })
201
202 it('Should success with the correct parameters', async function () {
203 await makeDeleteRequest({
204 url: server.url,
205 path: path + '/' + userChannelUUID + '@localhost:9001',
206 token: server.accessToken,
207 statusCodeExpected: 204
208 })
209 })
210 })
211
212 after(async function () {
213 killallServers([ server ])
214
215 // Keep the logs if the test failed
216 if (this['ok']) {
217 await flushTests()
218 }
219 })
220})