1 /* tslint:disable:no-unused-expression */
3 import * as request from 'supertest'
11 loginAndGetAccessToken,
12 setAccessTokensToServers,
17 describe('Test server follows API validators', function () {
18 let server: ServerInfo
20 // ---------------------------------------------------------------
22 before(async function () {
26 server = await runServer(1)
28 await setAccessTokensToServers([ server ])
31 describe('When managing following', function () {
32 let userAccessToken = null
34 before(async function () {
35 await createUser(server.url, server.accessToken, 'user1', 'password')
41 userAccessToken = await loginAndGetAccessToken(server)
44 describe('When adding follows', function () {
45 const path = '/api/v1/server/following'
47 hosts: [ 'localhost:9002' ]
50 it('Should fail without hosts', async function () {
51 await request(server.url)
53 .set('Authorization', 'Bearer ' + server.accessToken)
54 .set('Accept', 'application/json')
58 it('Should fail if hosts is not an array', async function () {
59 await request(server.url)
61 .send({ hosts: 'localhost:9002' })
62 .set('Authorization', 'Bearer ' + server.accessToken)
63 .set('Accept', 'application/json')
67 it('Should fail if the array is not composed by hosts', async function () {
68 await request(server.url)
70 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
71 .set('Authorization', 'Bearer ' + server.accessToken)
72 .set('Accept', 'application/json')
76 it('Should fail if the array is composed with http schemes', async function () {
77 await request(server.url)
79 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
80 .set('Authorization', 'Bearer ' + server.accessToken)
81 .set('Accept', 'application/json')
85 it('Should fail if hosts are not unique', async function () {
86 await request(server.url)
88 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
89 .set('Authorization', 'Bearer ' + server.accessToken)
90 .set('Accept', 'application/json')
94 it('Should fail with an invalid token', async function () {
95 await request(server.url)
98 .set('Authorization', 'Bearer fake_token')
99 .set('Accept', 'application/json')
103 it('Should fail if the user is not an administrator', async function () {
104 await request(server.url)
107 .set('Authorization', 'Bearer ' + userAccessToken)
108 .set('Accept', 'application/json')
113 describe('When listing followings', function () {
114 const path = '/api/v1/server/following'
116 it('Should fail with a bad start pagination', async function () {
117 await request(server.url)
119 .query({ start: 'hello' })
120 .set('Accept', 'application/json')
124 it('Should fail with a bad count pagination', async function () {
125 await request(server.url)
127 .query({ count: 'hello' })
128 .set('Accept', 'application/json')
132 it('Should fail with an incorrect sort', async function () {
133 await request(server.url)
135 .query({ sort: 'hello' })
136 .set('Accept', 'application/json')
141 describe('When listing followers', function () {
142 const path = '/api/v1/server/followers'
144 it('Should fail with a bad start pagination', async function () {
145 await request(server.url)
147 .query({ start: 'hello' })
148 .set('Accept', 'application/json')
152 it('Should fail with a bad count pagination', async function () {
153 await request(server.url)
155 .query({ count: 'hello' })
156 .set('Accept', 'application/json')
160 it('Should fail with an incorrect sort', async function () {
161 await request(server.url)
163 .query({ sort: 'hello' })
164 .set('Accept', 'application/json')
169 describe('When removing following', function () {
170 // it('Should fail with an invalid token', async function () {
171 // await request(server.url)
172 // .delete(path + '/1')
173 // .set('Authorization', 'Bearer faketoken')
174 // .set('Accept', 'application/json')
178 // it('Should fail if the user is not an administrator', async function () {
179 // await request(server.url)
180 // .delete(path + '/1')
181 // .set('Authorization', 'Bearer ' + userAccessToken)
182 // .set('Accept', 'application/json')
186 // it('Should fail with an undefined id', async function () {
187 // await request(server.url)
188 // .delete(path + '/' + undefined)
189 // .set('Authorization', 'Bearer ' + server.accessToken)
190 // .set('Accept', 'application/json')
194 // it('Should fail with an invalid id', async function () {
195 // await request(server.url)
196 // .delete(path + '/foobar')
197 // .set('Authorization', 'Bearer ' + server.accessToken)
198 // .set('Accept', 'application/json')
202 // it('Should fail we do not follow this server', async function () {
203 // await request(server.url)
204 // .delete(path + '/-1')
205 // .set('Authorization', 'Bearer ' + server.accessToken)
206 // .set('Accept', 'application/json')
210 // it('Should succeed with the correct parameters')
214 after(async function () {
215 killallServers([ server ])
217 // Keep the logs if the test failed