]>
Commit | Line | Data |
---|---|---|
9a27cdc2 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
9a27cdc2 C |
3 | import 'mocha' |
4 | ||
5 | import { | |
eec63bbc C |
6 | createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, |
7 | userLogin | |
9a27cdc2 | 8 | } from '../../utils' |
eec63bbc | 9 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
9a27cdc2 C |
10 | |
11 | describe('Test server follows API validators', function () { | |
12 | let server: ServerInfo | |
13 | ||
14 | // --------------------------------------------------------------- | |
15 | ||
16 | before(async function () { | |
e212f887 | 17 | this.timeout(30000) |
9a27cdc2 C |
18 | |
19 | await flushTests() | |
20 | server = await runServer(1) | |
21 | ||
22 | await setAccessTokensToServers([ server ]) | |
23 | }) | |
24 | ||
25 | describe('When managing following', function () { | |
26 | let userAccessToken = null | |
27 | ||
28 | before(async function () { | |
eec63bbc | 29 | const user = { |
9a27cdc2 C |
30 | username: 'user1', |
31 | password: 'password' | |
32 | } | |
33 | ||
eec63bbc C |
34 | await createUser(server.url, server.accessToken, user.username, user.password) |
35 | userAccessToken = await userLogin(server, user) | |
9a27cdc2 C |
36 | }) |
37 | ||
38 | describe('When adding follows', function () { | |
39 | const path = '/api/v1/server/following' | |
9a27cdc2 C |
40 | |
41 | it('Should fail without hosts', async function () { | |
eec63bbc C |
42 | await makePostBodyRequest({ |
43 | url: server.url, | |
44 | path, | |
45 | token: server.accessToken, | |
46 | statusCodeExpected: 400 | |
47 | }) | |
9a27cdc2 C |
48 | }) |
49 | ||
50 | it('Should fail if hosts is not an array', async function () { | |
eec63bbc C |
51 | await makePostBodyRequest({ |
52 | url: server.url, | |
53 | path, | |
54 | token: server.accessToken, | |
55 | fields: { hosts: 'localhost:9002' }, | |
56 | statusCodeExpected: 400 | |
57 | }) | |
9a27cdc2 C |
58 | }) |
59 | ||
60 | it('Should fail if the array is not composed by hosts', async function () { | |
eec63bbc C |
61 | await makePostBodyRequest({ |
62 | url: server.url, | |
63 | path, | |
64 | fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, | |
65 | token: server.accessToken, | |
66 | statusCodeExpected: 400 | |
67 | }) | |
9a27cdc2 C |
68 | }) |
69 | ||
70 | it('Should fail if the array is composed with http schemes', async function () { | |
eec63bbc C |
71 | await makePostBodyRequest({ |
72 | url: server.url, | |
73 | path, | |
74 | fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, | |
75 | token: server.accessToken, | |
76 | statusCodeExpected: 400 | |
77 | }) | |
9a27cdc2 C |
78 | }) |
79 | ||
80 | it('Should fail if hosts are not unique', async function () { | |
eec63bbc C |
81 | await makePostBodyRequest({ |
82 | url: server.url, | |
83 | path, | |
84 | fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, | |
85 | token: server.accessToken, | |
86 | statusCodeExpected: 400 | |
87 | }) | |
9a27cdc2 C |
88 | }) |
89 | ||
90 | it('Should fail with an invalid token', async function () { | |
eec63bbc C |
91 | await makePostBodyRequest({ |
92 | url: server.url, | |
93 | path, | |
94 | fields: { hosts: [ 'localhost:9002' ] }, | |
95 | token: 'fake_token', | |
96 | statusCodeExpected: 401 | |
97 | }) | |
9a27cdc2 C |
98 | }) |
99 | ||
100 | it('Should fail if the user is not an administrator', async function () { | |
eec63bbc C |
101 | await makePostBodyRequest({ |
102 | url: server.url, | |
103 | path, | |
104 | fields: { hosts: [ 'localhost:9002' ] }, | |
105 | token: userAccessToken, | |
106 | statusCodeExpected: 403 | |
107 | }) | |
9a27cdc2 C |
108 | }) |
109 | }) | |
110 | ||
111 | describe('When listing followings', function () { | |
112 | const path = '/api/v1/server/following' | |
113 | ||
114 | it('Should fail with a bad start pagination', async function () { | |
eec63bbc | 115 | await checkBadStartPagination(server.url, path) |
9a27cdc2 C |
116 | }) |
117 | ||
118 | it('Should fail with a bad count pagination', async function () { | |
eec63bbc | 119 | await checkBadCountPagination(server.url, path) |
9a27cdc2 C |
120 | }) |
121 | ||
122 | it('Should fail with an incorrect sort', async function () { | |
eec63bbc | 123 | await checkBadSortPagination(server.url, path) |
9a27cdc2 C |
124 | }) |
125 | }) | |
126 | ||
127 | describe('When listing followers', function () { | |
128 | const path = '/api/v1/server/followers' | |
129 | ||
130 | it('Should fail with a bad start pagination', async function () { | |
eec63bbc | 131 | await checkBadStartPagination(server.url, path) |
9a27cdc2 C |
132 | }) |
133 | ||
134 | it('Should fail with a bad count pagination', async function () { | |
eec63bbc | 135 | await checkBadCountPagination(server.url, path) |
9a27cdc2 C |
136 | }) |
137 | ||
138 | it('Should fail with an incorrect sort', async function () { | |
eec63bbc | 139 | await checkBadSortPagination(server.url, path) |
9a27cdc2 C |
140 | }) |
141 | }) | |
142 | ||
143 | describe('When removing following', function () { | |
0f91ae62 C |
144 | const path = '/api/v1/server/following' |
145 | ||
146 | it('Should fail with an invalid token', async function () { | |
eec63bbc C |
147 | await makeDeleteRequest({ |
148 | url: server.url, | |
149 | path: path + '/localhost:9002', | |
150 | token: 'fake_token', | |
151 | statusCodeExpected: 401 | |
152 | }) | |
0f91ae62 C |
153 | }) |
154 | ||
155 | it('Should fail if the user is not an administrator', async function () { | |
eec63bbc C |
156 | await makeDeleteRequest({ |
157 | url: server.url, | |
158 | path: path + '/localhost:9002', | |
159 | token: userAccessToken, | |
160 | statusCodeExpected: 403 | |
161 | }) | |
162 | }) | |
163 | ||
164 | it('Should fail if we do not follow this server', async function () { | |
165 | await makeDeleteRequest({ | |
166 | url: server.url, | |
167 | path: path + '/example.com', | |
168 | token: server.accessToken, | |
169 | statusCodeExpected: 404 | |
170 | }) | |
171 | }) | |
172 | ||
173 | it('Should succeed with the correct parameters', async function () { | |
174 | await makeDeleteRequest({ | |
175 | url: server.url, | |
176 | path: path + '/localhost:9002', | |
177 | token: server.accessToken, | |
178 | statusCodeExpected: 404 | |
179 | }) | |
0f91ae62 | 180 | }) |
9a27cdc2 C |
181 | }) |
182 | }) | |
183 | ||
184 | after(async function () { | |
185 | killallServers([ server ]) | |
186 | ||
187 | // Keep the logs if the test failed | |
188 | if (this['ok']) { | |
189 | await flushTests() | |
190 | } | |
191 | }) | |
192 | }) |