diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params/follows.ts | 84 | ||||
-rw-r--r-- | server/tests/api/follows.ts | 174 | ||||
-rw-r--r-- | server/tests/api/index-slow.ts | 1 |
3 files changed, 218 insertions, 41 deletions
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index a215e7b1a..0af1562f5 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts | |||
@@ -166,47 +166,49 @@ describe('Test server follows API validators', function () { | |||
166 | }) | 166 | }) |
167 | 167 | ||
168 | describe('When removing following', function () { | 168 | describe('When removing following', function () { |
169 | // it('Should fail with an invalid token', async function () { | 169 | const path = '/api/v1/server/following' |
170 | // await request(server.url) | 170 | |
171 | // .delete(path + '/1') | 171 | it('Should fail with an invalid token', async function () { |
172 | // .set('Authorization', 'Bearer faketoken') | 172 | await request(server.url) |
173 | // .set('Accept', 'application/json') | 173 | .delete(path + '/1') |
174 | // .expect(401) | 174 | .set('Authorization', 'Bearer faketoken') |
175 | // }) | 175 | .set('Accept', 'application/json') |
176 | // | 176 | .expect(401) |
177 | // it('Should fail if the user is not an administrator', async function () { | 177 | }) |
178 | // await request(server.url) | 178 | |
179 | // .delete(path + '/1') | 179 | it('Should fail if the user is not an administrator', async function () { |
180 | // .set('Authorization', 'Bearer ' + userAccessToken) | 180 | await request(server.url) |
181 | // .set('Accept', 'application/json') | 181 | .delete(path + '/1') |
182 | // .expect(403) | 182 | .set('Authorization', 'Bearer ' + userAccessToken) |
183 | // }) | 183 | .set('Accept', 'application/json') |
184 | // | 184 | .expect(403) |
185 | // it('Should fail with an undefined id', async function () { | 185 | }) |
186 | // await request(server.url) | 186 | |
187 | // .delete(path + '/' + undefined) | 187 | it('Should fail with an undefined id', async function () { |
188 | // .set('Authorization', 'Bearer ' + server.accessToken) | 188 | await request(server.url) |
189 | // .set('Accept', 'application/json') | 189 | .delete(path + '/' + undefined) |
190 | // .expect(400) | 190 | .set('Authorization', 'Bearer ' + server.accessToken) |
191 | // }) | 191 | .set('Accept', 'application/json') |
192 | // | 192 | .expect(400) |
193 | // it('Should fail with an invalid id', async function () { | 193 | }) |
194 | // await request(server.url) | 194 | |
195 | // .delete(path + '/foobar') | 195 | it('Should fail with an invalid id', async function () { |
196 | // .set('Authorization', 'Bearer ' + server.accessToken) | 196 | await request(server.url) |
197 | // .set('Accept', 'application/json') | 197 | .delete(path + '/foobar') |
198 | // .expect(400) | 198 | .set('Authorization', 'Bearer ' + server.accessToken) |
199 | // }) | 199 | .set('Accept', 'application/json') |
200 | // | 200 | .expect(400) |
201 | // it('Should fail we do not follow this server', async function () { | 201 | }) |
202 | // await request(server.url) | 202 | |
203 | // .delete(path + '/-1') | 203 | it('Should fail we do not follow this server', async function () { |
204 | // .set('Authorization', 'Bearer ' + server.accessToken) | 204 | await request(server.url) |
205 | // .set('Accept', 'application/json') | 205 | .delete(path + '/-1') |
206 | // .expect(404) | 206 | .set('Authorization', 'Bearer ' + server.accessToken) |
207 | // }) | 207 | .set('Accept', 'application/json') |
208 | // | 208 | .expect(404) |
209 | // it('Should succeed with the correct parameters') | 209 | }) |
210 | |||
211 | it('Should succeed with the correct parameters') | ||
210 | }) | 212 | }) |
211 | }) | 213 | }) |
212 | 214 | ||
diff --git a/server/tests/api/follows.ts b/server/tests/api/follows.ts new file mode 100644 index 000000000..b2f53d3a7 --- /dev/null +++ b/server/tests/api/follows.ts | |||
@@ -0,0 +1,174 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | |||
6 | import { | ||
7 | flushAndRunMultipleServers, | ||
8 | flushTests, | ||
9 | getVideosList, | ||
10 | killallServers, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers, | ||
13 | uploadVideo, | ||
14 | wait | ||
15 | } from '../utils' | ||
16 | import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../utils/follows' | ||
17 | |||
18 | const expect = chai.expect | ||
19 | |||
20 | describe('Test follows', function () { | ||
21 | let servers: ServerInfo[] = [] | ||
22 | let server3Id: number | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(120000) | ||
26 | |||
27 | servers = await flushAndRunMultipleServers(3) | ||
28 | |||
29 | // Get the access tokens | ||
30 | await setAccessTokensToServers(servers) | ||
31 | }) | ||
32 | |||
33 | it('Should not have followers', async function () { | ||
34 | for (const server of servers) { | ||
35 | const res = await getFollowersListPaginationAndSort(server.url, 0, 5, 'createdAt') | ||
36 | const follows = res.body.data | ||
37 | |||
38 | expect(res.body.total).to.equal(0) | ||
39 | expect(follows).to.be.an('array') | ||
40 | expect(follows.length).to.equal(0) | ||
41 | } | ||
42 | }) | ||
43 | |||
44 | it('Should not have following', async function () { | ||
45 | for (const server of servers) { | ||
46 | const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') | ||
47 | const follows = res.body.data | ||
48 | |||
49 | expect(res.body.total).to.equal(0) | ||
50 | expect(follows).to.be.an('array') | ||
51 | expect(follows.length).to.equal(0) | ||
52 | } | ||
53 | }) | ||
54 | |||
55 | it('Should have server 1 following server 2 and 3', async function () { | ||
56 | this.timeout(10000) | ||
57 | |||
58 | await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken) | ||
59 | |||
60 | await wait(7000) | ||
61 | }) | ||
62 | |||
63 | it('Should have 2 followings on server 1', async function () { | ||
64 | let res = await getFollowingListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') | ||
65 | let follows = res.body.data | ||
66 | |||
67 | expect(res.body.total).to.equal(2) | ||
68 | expect(follows).to.be.an('array') | ||
69 | expect(follows.length).to.equal(1) | ||
70 | |||
71 | res = await getFollowingListPaginationAndSort(servers[0].url, 1, 1, 'createdAt') | ||
72 | follows = follows.concat(res.body.data) | ||
73 | |||
74 | const server2Follow = follows.find(f => f.following.host === 'localhost:9002') | ||
75 | const server3Follow = follows.find(f => f.following.host === 'localhost:9003') | ||
76 | |||
77 | expect(server2Follow).to.not.be.undefined | ||
78 | expect(server3Follow).to.not.be.undefined | ||
79 | expect(server2Follow.state).to.equal('accepted') | ||
80 | expect(server3Follow.state).to.equal('accepted') | ||
81 | |||
82 | server3Id = server3Follow.following.id | ||
83 | }) | ||
84 | |||
85 | it('Should have 0 followings on server 1 and 2', async function () { | ||
86 | for (const server of [ servers[1], servers[2] ]) { | ||
87 | const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') | ||
88 | const follows = res.body.data | ||
89 | |||
90 | expect(res.body.total).to.equal(0) | ||
91 | expect(follows).to.be.an('array') | ||
92 | expect(follows.length).to.equal(0) | ||
93 | } | ||
94 | }) | ||
95 | |||
96 | it('Should have 1 followers on server 2 and 3', async function () { | ||
97 | for (const server of [ servers[1], servers[2] ]) { | ||
98 | let res = await getFollowersListPaginationAndSort(server.url, 0, 1, 'createdAt') | ||
99 | |||
100 | let follows = res.body.data | ||
101 | expect(res.body.total).to.equal(1) | ||
102 | expect(follows).to.be.an('array') | ||
103 | expect(follows.length).to.equal(1) | ||
104 | expect(follows[0].follower.host).to.equal('localhost:9001') | ||
105 | } | ||
106 | }) | ||
107 | |||
108 | it('Should have 0 followers on server 1', async function () { | ||
109 | const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') | ||
110 | const follows = res.body.data | ||
111 | |||
112 | expect(res.body.total).to.equal(0) | ||
113 | expect(follows).to.be.an('array') | ||
114 | expect(follows.length).to.equal(0) | ||
115 | }) | ||
116 | |||
117 | it('Should unfollow server 3 on server 1', async function () { | ||
118 | this.timeout(5000) | ||
119 | |||
120 | await unfollow(servers[0].url, servers[0].accessToken, server3Id) | ||
121 | |||
122 | await wait(3000) | ||
123 | }) | ||
124 | |||
125 | it('Should not follow server 3 on server 1 anymore', async function () { | ||
126 | const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') | ||
127 | let follows = res.body.data | ||
128 | |||
129 | expect(res.body.total).to.equal(1) | ||
130 | expect(follows).to.be.an('array') | ||
131 | expect(follows.length).to.equal(1) | ||
132 | |||
133 | expect(follows[0].following.host).to.equal('localhost:9002') | ||
134 | }) | ||
135 | |||
136 | it('Should not have server 1 as follower on server 3 anymore', async function () { | ||
137 | const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 1, 'createdAt') | ||
138 | |||
139 | let follows = res.body.data | ||
140 | expect(res.body.total).to.equal(0) | ||
141 | expect(follows).to.be.an('array') | ||
142 | expect(follows.length).to.equal(0) | ||
143 | }) | ||
144 | |||
145 | it('Should upload a video on server 2 ans 3 and propagate only the video of server 2', async function () { | ||
146 | this.timeout(10000) | ||
147 | |||
148 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) | ||
149 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) | ||
150 | |||
151 | await wait(5000) | ||
152 | |||
153 | let res = await getVideosList(servers[0].url) | ||
154 | expect(res.body.total).to.equal(1) | ||
155 | expect(res.body.data[0].name).to.equal('server2') | ||
156 | |||
157 | res = await getVideosList(servers[1].url) | ||
158 | expect(res.body.total).to.equal(1) | ||
159 | expect(res.body.data[0].name).to.equal('server2') | ||
160 | |||
161 | res = await getVideosList(servers[2].url) | ||
162 | expect(res.body.total).to.equal(1) | ||
163 | expect(res.body.data[0].name).to.equal('server3') | ||
164 | }) | ||
165 | |||
166 | after(async function () { | ||
167 | killallServers(servers) | ||
168 | |||
169 | // Keep the logs if the test failed | ||
170 | if (this['ok']) { | ||
171 | await flushTests() | ||
172 | } | ||
173 | }) | ||
174 | }) | ||
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts index b3c3d778c..da56398b1 100644 --- a/server/tests/api/index-slow.ts +++ b/server/tests/api/index-slow.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | // Order of the tests we want to execute | 1 | // Order of the tests we want to execute |
2 | // import './multiple-servers' | 2 | // import './multiple-servers' |
3 | import './video-transcoder' | 3 | import './video-transcoder' |
4 | import './follows' | ||