1 /* tslint:disable:no-unused-expression */
4 import * as request from 'supertest'
10 loginAndGetAccessToken,
13 setAccessTokensToServers
16 describe('Test server follows API validators', function () {
17 let server: ServerInfo
19 // ---------------------------------------------------------------
21 before(async function () {
25 server = await runServer(1)
27 await setAccessTokensToServers([ server ])
30 describe('When managing following', function () {
31 let userAccessToken = null
33 before(async function () {
34 await createUser(server.url, server.accessToken, 'user1', 'password')
40 userAccessToken = await loginAndGetAccessToken(server)
43 describe('When adding follows', function () {
44 const path = '/api/v1/server/following'
46 hosts: [ 'localhost:9002' ]
49 it('Should fail without hosts', async function () {
50 await request(server.url)
52 .set('Authorization', 'Bearer ' + server.accessToken)
53 .set('Accept', 'application/json')
57 it('Should fail if hosts is not an array', async function () {
58 await request(server.url)
60 .send({ hosts: 'localhost:9002' })
61 .set('Authorization', 'Bearer ' + server.accessToken)
62 .set('Accept', 'application/json')
66 it('Should fail if the array is not composed by hosts', async function () {
67 await request(server.url)
69 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
70 .set('Authorization', 'Bearer ' + server.accessToken)
71 .set('Accept', 'application/json')
75 it('Should fail if the array is composed with http schemes', async function () {
76 await request(server.url)
78 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
79 .set('Authorization', 'Bearer ' + server.accessToken)
80 .set('Accept', 'application/json')
84 it('Should fail if hosts are not unique', async function () {
85 await request(server.url)
87 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
88 .set('Authorization', 'Bearer ' + server.accessToken)
89 .set('Accept', 'application/json')
93 it('Should fail with an invalid token', async function () {
94 await request(server.url)
97 .set('Authorization', 'Bearer fake_token')
98 .set('Accept', 'application/json')
102 it('Should fail if the user is not an administrator', async function () {
103 await request(server.url)
106 .set('Authorization', 'Bearer ' + userAccessToken)
107 .set('Accept', 'application/json')
112 describe('When listing followings', function () {
113 const path = '/api/v1/server/following'
115 it('Should fail with a bad start pagination', async function () {
116 await request(server.url)
118 .query({ start: 'hello' })
119 .set('Accept', 'application/json')
123 it('Should fail with a bad count pagination', async function () {
124 await request(server.url)
126 .query({ count: 'hello' })
127 .set('Accept', 'application/json')
131 it('Should fail with an incorrect sort', async function () {
132 await request(server.url)
134 .query({ sort: 'hello' })
135 .set('Accept', 'application/json')
140 describe('When listing followers', function () {
141 const path = '/api/v1/server/followers'
143 it('Should fail with a bad start pagination', async function () {
144 await request(server.url)
146 .query({ start: 'hello' })
147 .set('Accept', 'application/json')
151 it('Should fail with a bad count pagination', async function () {
152 await request(server.url)
154 .query({ count: 'hello' })
155 .set('Accept', 'application/json')
159 it('Should fail with an incorrect sort', async function () {
160 await request(server.url)
162 .query({ sort: 'hello' })
163 .set('Accept', 'application/json')
168 describe('When removing following', function () {
169 const path = '/api/v1/server/following'
171 it('Should fail with an invalid token', async function () {
172 await request(server.url)
174 .set('Authorization', 'Bearer faketoken')
175 .set('Accept', 'application/json')
179 it('Should fail if the user is not an administrator', async function () {
180 await request(server.url)
182 .set('Authorization', 'Bearer ' + userAccessToken)
183 .set('Accept', 'application/json')
187 it('Should fail we do not follow this server', async function () {
188 await request(server.url)
189 .delete(path + '/example.com')
190 .set('Authorization', 'Bearer ' + server.accessToken)
191 .set('Accept', 'application/json')
195 it('Should succeed with the correct parameters')
199 after(async function () {
200 killallServers([ server ])
202 // Keep the logs if the test failed