]>
Commit | Line | Data |
---|---|---|
06a05d5f C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | createUser, | |
7 | flushTests, | |
06a05d5f C |
8 | killallServers, |
9 | makeDeleteRequest, | |
10 | makeGetRequest, | |
11 | makePostBodyRequest, | |
12 | runServer, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | userLogin | |
16 | } from '../../utils' | |
17 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | |
18 | ||
19 | describe('Test user subscriptions API validators', function () { | |
20 | const path = '/api/v1/users/me/subscriptions' | |
21 | let server: ServerInfo | |
22 | let userAccessToken = '' | |
06a05d5f C |
23 | |
24 | // --------------------------------------------------------------- | |
25 | ||
26 | before(async function () { | |
27 | this.timeout(30000) | |
28 | ||
29 | await flushTests() | |
30 | ||
31 | server = await runServer(1) | |
32 | ||
33 | await setAccessTokensToServers([ server ]) | |
34 | ||
35 | const user = { | |
36 | username: 'user1', | |
37 | password: 'my super password' | |
38 | } | |
39 | await createUser(server.url, server.accessToken, user.username, user.password) | |
40 | userAccessToken = await userLogin(server, user) | |
06a05d5f C |
41 | }) |
42 | ||
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) | |
46 | }) | |
47 | ||
48 | it('Should fail with a bad count pagination', async function () { | |
49 | await checkBadCountPagination(server.url, path, server.accessToken) | |
50 | }) | |
51 | ||
52 | it('Should fail with an incorrect sort', async function () { | |
53 | await checkBadSortPagination(server.url, path, server.accessToken) | |
54 | }) | |
55 | ||
56 | it('Should fail with a non authenticated user', async function () { | |
57 | await makeGetRequest({ | |
58 | url: server.url, | |
59 | path, | |
60 | statusCodeExpected: 401 | |
61 | }) | |
62 | }) | |
63 | ||
64 | it('Should success with the correct parameters', async function () { | |
8a19bee1 | 65 | await makeGetRequest({ |
06a05d5f C |
66 | url: server.url, |
67 | path, | |
68 | token: userAccessToken, | |
69 | statusCodeExpected: 200 | |
70 | }) | |
71 | }) | |
72 | }) | |
73 | ||
74 | describe('When listing my subscriptions videos', function () { | |
75 | const path = '/api/v1/users/me/subscriptions/videos' | |
76 | ||
77 | it('Should fail with a bad start pagination', async function () { | |
78 | await checkBadStartPagination(server.url, path, server.accessToken) | |
79 | }) | |
80 | ||
81 | it('Should fail with a bad count pagination', async function () { | |
82 | await checkBadCountPagination(server.url, path, server.accessToken) | |
83 | }) | |
84 | ||
85 | it('Should fail with an incorrect sort', async function () { | |
86 | await checkBadSortPagination(server.url, path, server.accessToken) | |
87 | }) | |
88 | ||
89 | it('Should fail with a non authenticated user', async function () { | |
90 | await makeGetRequest({ | |
91 | url: server.url, | |
92 | path, | |
93 | statusCodeExpected: 401 | |
94 | }) | |
95 | }) | |
96 | ||
97 | it('Should success with the correct parameters', async function () { | |
8a19bee1 | 98 | await makeGetRequest({ |
06a05d5f C |
99 | url: server.url, |
100 | path, | |
101 | token: userAccessToken, | |
102 | statusCodeExpected: 200 | |
103 | }) | |
104 | }) | |
105 | }) | |
106 | ||
107 | describe('When adding a subscription', function () { | |
108 | it('Should fail with a non authenticated user', async function () { | |
109 | await makePostBodyRequest({ | |
110 | url: server.url, | |
111 | path, | |
8a19bee1 | 112 | fields: { uri: 'user1_channel@localhost:9001' }, |
06a05d5f C |
113 | statusCodeExpected: 401 |
114 | }) | |
115 | }) | |
116 | ||
117 | it('Should fail with bad URIs', async function () { | |
118 | await makePostBodyRequest({ | |
119 | url: server.url, | |
120 | path, | |
121 | token: server.accessToken, | |
122 | fields: { uri: 'root' }, | |
123 | statusCodeExpected: 400 | |
124 | }) | |
125 | ||
126 | await makePostBodyRequest({ | |
127 | url: server.url, | |
128 | path, | |
129 | token: server.accessToken, | |
130 | fields: { uri: 'root@' }, | |
131 | statusCodeExpected: 400 | |
132 | }) | |
133 | ||
134 | await makePostBodyRequest({ | |
135 | url: server.url, | |
136 | path, | |
137 | token: server.accessToken, | |
138 | fields: { uri: 'root@hello@' }, | |
139 | statusCodeExpected: 400 | |
140 | }) | |
141 | }) | |
142 | ||
143 | it('Should success with the correct parameters', async function () { | |
144 | await makePostBodyRequest({ | |
145 | url: server.url, | |
146 | path, | |
147 | token: server.accessToken, | |
8a19bee1 | 148 | fields: { uri: 'user1_channel@localhost:9001' }, |
06a05d5f C |
149 | statusCodeExpected: 204 |
150 | }) | |
151 | }) | |
152 | }) | |
153 | ||
154 | describe('When removing a subscription', function () { | |
155 | it('Should fail with a non authenticated user', async function () { | |
156 | await makeDeleteRequest({ | |
157 | url: server.url, | |
8a19bee1 | 158 | path: path + '/user1_channel@localhost:9001', |
06a05d5f C |
159 | statusCodeExpected: 401 |
160 | }) | |
161 | }) | |
162 | ||
163 | it('Should fail with bad URIs', async function () { | |
164 | await makeDeleteRequest({ | |
165 | url: server.url, | |
166 | path: path + '/root', | |
167 | token: server.accessToken, | |
168 | statusCodeExpected: 400 | |
169 | }) | |
170 | ||
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@hello@', | |
181 | token: server.accessToken, | |
182 | statusCodeExpected: 400 | |
183 | }) | |
184 | }) | |
185 | ||
186 | it('Should fail with an unknown subscription', async function () { | |
187 | await makeDeleteRequest({ | |
188 | url: server.url, | |
189 | path: path + '/root1@localhost:9001', | |
190 | token: server.accessToken, | |
191 | statusCodeExpected: 404 | |
192 | }) | |
193 | }) | |
194 | ||
195 | it('Should success with the correct parameters', async function () { | |
196 | await makeDeleteRequest({ | |
197 | url: server.url, | |
8a19bee1 | 198 | path: path + '/user1_channel@localhost:9001', |
06a05d5f C |
199 | token: server.accessToken, |
200 | statusCodeExpected: 204 | |
201 | }) | |
202 | }) | |
203 | }) | |
204 | ||
205 | after(async function () { | |
206 | killallServers([ server ]) | |
207 | ||
208 | // Keep the logs if the test failed | |
209 | if (this['ok']) { | |
210 | await flushTests() | |
211 | } | |
212 | }) | |
213 | }) |