]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/follows.ts
Fix margin issue when seeking video
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / follows.ts
CommitLineData
9a27cdc2
C
1/* tslint:disable:no-unused-expression */
2
9a27cdc2 3import 'mocha'
79d5caf9 4import * as request from 'supertest'
9a27cdc2
C
5
6import {
9a27cdc2 7 createUser,
79d5caf9 8 flushTests,
9a27cdc2 9 killallServers,
79d5caf9
C
10 loginAndGetAccessToken,
11 runServer,
12 ServerInfo,
13 setAccessTokensToServers
9a27cdc2
C
14} from '../../utils'
15
16describe('Test server follows API validators', function () {
17 let server: ServerInfo
18
19 // ---------------------------------------------------------------
20
21 before(async function () {
22 this.timeout(45000)
23
24 await flushTests()
25 server = await runServer(1)
26
27 await setAccessTokensToServers([ server ])
28 })
29
30 describe('When managing following', function () {
31 let userAccessToken = null
32
33 before(async function () {
34 await createUser(server.url, server.accessToken, 'user1', 'password')
35 server.user = {
36 username: 'user1',
37 password: 'password'
38 }
39
40 userAccessToken = await loginAndGetAccessToken(server)
41 })
42
43 describe('When adding follows', function () {
44 const path = '/api/v1/server/following'
45 const body = {
46 hosts: [ 'localhost:9002' ]
47 }
48
49 it('Should fail without hosts', async function () {
50 await request(server.url)
51 .post(path)
52 .set('Authorization', 'Bearer ' + server.accessToken)
53 .set('Accept', 'application/json')
54 .expect(400)
55 })
56
57 it('Should fail if hosts is not an array', async function () {
58 await request(server.url)
59 .post(path)
60 .send({ hosts: 'localhost:9002' })
61 .set('Authorization', 'Bearer ' + server.accessToken)
62 .set('Accept', 'application/json')
63 .expect(400)
64 })
65
66 it('Should fail if the array is not composed by hosts', async function () {
67 await request(server.url)
68 .post(path)
69 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
70 .set('Authorization', 'Bearer ' + server.accessToken)
71 .set('Accept', 'application/json')
72 .expect(400)
73 })
74
75 it('Should fail if the array is composed with http schemes', async function () {
76 await request(server.url)
77 .post(path)
78 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
79 .set('Authorization', 'Bearer ' + server.accessToken)
80 .set('Accept', 'application/json')
81 .expect(400)
82 })
83
84 it('Should fail if hosts are not unique', async function () {
85 await request(server.url)
86 .post(path)
87 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
88 .set('Authorization', 'Bearer ' + server.accessToken)
89 .set('Accept', 'application/json')
90 .expect(400)
91 })
92
93 it('Should fail with an invalid token', async function () {
94 await request(server.url)
95 .post(path)
96 .send(body)
97 .set('Authorization', 'Bearer fake_token')
98 .set('Accept', 'application/json')
99 .expect(401)
100 })
101
102 it('Should fail if the user is not an administrator', async function () {
103 await request(server.url)
104 .post(path)
105 .send(body)
106 .set('Authorization', 'Bearer ' + userAccessToken)
107 .set('Accept', 'application/json')
108 .expect(403)
109 })
110 })
111
112 describe('When listing followings', function () {
113 const path = '/api/v1/server/following'
114
115 it('Should fail with a bad start pagination', async function () {
116 await request(server.url)
117 .get(path)
118 .query({ start: 'hello' })
119 .set('Accept', 'application/json')
120 .expect(400)
121 })
122
123 it('Should fail with a bad count pagination', async function () {
124 await request(server.url)
125 .get(path)
126 .query({ count: 'hello' })
127 .set('Accept', 'application/json')
128 .expect(400)
129 })
130
131 it('Should fail with an incorrect sort', async function () {
132 await request(server.url)
133 .get(path)
134 .query({ sort: 'hello' })
135 .set('Accept', 'application/json')
136 .expect(400)
137 })
138 })
139
140 describe('When listing followers', function () {
141 const path = '/api/v1/server/followers'
142
143 it('Should fail with a bad start pagination', async function () {
144 await request(server.url)
145 .get(path)
146 .query({ start: 'hello' })
147 .set('Accept', 'application/json')
148 .expect(400)
149 })
150
151 it('Should fail with a bad count pagination', async function () {
152 await request(server.url)
153 .get(path)
154 .query({ count: 'hello' })
155 .set('Accept', 'application/json')
156 .expect(400)
157 })
158
159 it('Should fail with an incorrect sort', async function () {
160 await request(server.url)
161 .get(path)
162 .query({ sort: 'hello' })
163 .set('Accept', 'application/json')
164 .expect(400)
165 })
166 })
167
168 describe('When removing following', function () {
169 // it('Should fail with an invalid token', async function () {
170 // await request(server.url)
171 // .delete(path + '/1')
172 // .set('Authorization', 'Bearer faketoken')
173 // .set('Accept', 'application/json')
174 // .expect(401)
175 // })
176 //
177 // it('Should fail if the user is not an administrator', async function () {
178 // await request(server.url)
179 // .delete(path + '/1')
180 // .set('Authorization', 'Bearer ' + userAccessToken)
181 // .set('Accept', 'application/json')
182 // .expect(403)
183 // })
184 //
185 // it('Should fail with an undefined id', async function () {
186 // await request(server.url)
187 // .delete(path + '/' + undefined)
188 // .set('Authorization', 'Bearer ' + server.accessToken)
189 // .set('Accept', 'application/json')
190 // .expect(400)
191 // })
192 //
193 // it('Should fail with an invalid id', async function () {
194 // await request(server.url)
195 // .delete(path + '/foobar')
196 // .set('Authorization', 'Bearer ' + server.accessToken)
197 // .set('Accept', 'application/json')
198 // .expect(400)
199 // })
200 //
201 // it('Should fail we do not follow this server', async function () {
202 // await request(server.url)
203 // .delete(path + '/-1')
204 // .set('Authorization', 'Bearer ' + server.accessToken)
205 // .set('Accept', 'application/json')
206 // .expect(404)
207 // })
208 //
209 // it('Should succeed with the correct parameters')
210 })
211 })
212
213 after(async function () {
214 killallServers([ server ])
215
216 // Keep the logs if the test failed
217 if (this['ok']) {
218 await flushTests()
219 }
220 })
221})