]>
Commit | Line | Data |
---|---|---|
0f91ae62 C |
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' | |
d8553faa C |
17 | import { getUserAccessToken } from '../utils/login' |
18 | import { dateIsValid, webtorrentAdd } from '../utils/miscs' | |
19 | import { createUser } from '../utils/users' | |
20 | import { getVideo, rateVideo, testVideoImage } from '../utils/videos' | |
0f91ae62 C |
21 | |
22 | const expect = chai.expect | |
23 | ||
24 | describe('Test follows', function () { | |
25 | let servers: ServerInfo[] = [] | |
0f91ae62 C |
26 | |
27 | before(async function () { | |
c46edbc2 | 28 | this.timeout(20000) |
0f91ae62 C |
29 | |
30 | servers = await flushAndRunMultipleServers(3) | |
31 | ||
32 | // Get the access tokens | |
33 | await setAccessTokensToServers(servers) | |
34 | }) | |
35 | ||
36 | it('Should not have followers', async function () { | |
37 | for (const server of servers) { | |
38 | const res = await getFollowersListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
39 | const follows = res.body.data | |
40 | ||
41 | expect(res.body.total).to.equal(0) | |
42 | expect(follows).to.be.an('array') | |
43 | expect(follows.length).to.equal(0) | |
44 | } | |
45 | }) | |
46 | ||
47 | it('Should not have following', async function () { | |
48 | for (const server of servers) { | |
49 | const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
50 | const follows = res.body.data | |
51 | ||
52 | expect(res.body.total).to.equal(0) | |
53 | expect(follows).to.be.an('array') | |
54 | expect(follows.length).to.equal(0) | |
55 | } | |
56 | }) | |
57 | ||
58 | it('Should have server 1 following server 2 and 3', async function () { | |
59 | this.timeout(10000) | |
60 | ||
61 | await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken) | |
62 | ||
63 | await wait(7000) | |
64 | }) | |
65 | ||
66 | it('Should have 2 followings on server 1', async function () { | |
67 | let res = await getFollowingListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') | |
68 | let follows = res.body.data | |
69 | ||
70 | expect(res.body.total).to.equal(2) | |
71 | expect(follows).to.be.an('array') | |
72 | expect(follows.length).to.equal(1) | |
73 | ||
74 | res = await getFollowingListPaginationAndSort(servers[0].url, 1, 1, 'createdAt') | |
75 | follows = follows.concat(res.body.data) | |
76 | ||
77 | const server2Follow = follows.find(f => f.following.host === 'localhost:9002') | |
78 | const server3Follow = follows.find(f => f.following.host === 'localhost:9003') | |
79 | ||
80 | expect(server2Follow).to.not.be.undefined | |
81 | expect(server3Follow).to.not.be.undefined | |
82 | expect(server2Follow.state).to.equal('accepted') | |
83 | expect(server3Follow.state).to.equal('accepted') | |
0f91ae62 C |
84 | }) |
85 | ||
86 | it('Should have 0 followings on server 1 and 2', async function () { | |
87 | for (const server of [ servers[1], servers[2] ]) { | |
88 | const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
89 | const follows = res.body.data | |
90 | ||
91 | expect(res.body.total).to.equal(0) | |
92 | expect(follows).to.be.an('array') | |
93 | expect(follows.length).to.equal(0) | |
94 | } | |
95 | }) | |
96 | ||
97 | it('Should have 1 followers on server 2 and 3', async function () { | |
98 | for (const server of [ servers[1], servers[2] ]) { | |
99 | let res = await getFollowersListPaginationAndSort(server.url, 0, 1, 'createdAt') | |
100 | ||
101 | let follows = res.body.data | |
102 | expect(res.body.total).to.equal(1) | |
103 | expect(follows).to.be.an('array') | |
104 | expect(follows.length).to.equal(1) | |
105 | expect(follows[0].follower.host).to.equal('localhost:9001') | |
106 | } | |
107 | }) | |
108 | ||
109 | it('Should have 0 followers on server 1', async function () { | |
110 | const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') | |
111 | const follows = res.body.data | |
112 | ||
113 | expect(res.body.total).to.equal(0) | |
114 | expect(follows).to.be.an('array') | |
115 | expect(follows.length).to.equal(0) | |
116 | }) | |
117 | ||
118 | it('Should unfollow server 3 on server 1', async function () { | |
119 | this.timeout(5000) | |
120 | ||
50d6de9c | 121 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) |
0f91ae62 C |
122 | |
123 | await wait(3000) | |
124 | }) | |
125 | ||
126 | it('Should not follow server 3 on server 1 anymore', async function () { | |
127 | const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') | |
128 | let follows = res.body.data | |
129 | ||
130 | expect(res.body.total).to.equal(1) | |
131 | expect(follows).to.be.an('array') | |
132 | expect(follows.length).to.equal(1) | |
133 | ||
134 | expect(follows[0].following.host).to.equal('localhost:9002') | |
135 | }) | |
136 | ||
137 | it('Should not have server 1 as follower on server 3 anymore', async function () { | |
138 | const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 1, 'createdAt') | |
139 | ||
140 | let follows = res.body.data | |
141 | expect(res.body.total).to.equal(0) | |
142 | expect(follows).to.be.an('array') | |
143 | expect(follows.length).to.equal(0) | |
144 | }) | |
145 | ||
146 | it('Should upload a video on server 2 ans 3 and propagate only the video of server 2', async function () { | |
147 | this.timeout(10000) | |
148 | ||
149 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) | |
150 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) | |
151 | ||
152 | await wait(5000) | |
153 | ||
154 | let res = await getVideosList(servers[0].url) | |
155 | expect(res.body.total).to.equal(1) | |
156 | expect(res.body.data[0].name).to.equal('server2') | |
157 | ||
158 | res = await getVideosList(servers[1].url) | |
159 | expect(res.body.total).to.equal(1) | |
160 | expect(res.body.data[0].name).to.equal('server2') | |
161 | ||
162 | res = await getVideosList(servers[2].url) | |
163 | expect(res.body.total).to.equal(1) | |
164 | expect(res.body.data[0].name).to.equal('server3') | |
165 | }) | |
166 | ||
c46edbc2 C |
167 | it('Should propagate previous uploaded videos on a new following', async function () { |
168 | this.timeout(20000) | |
169 | ||
d8553faa C |
170 | const video4Attributes = { |
171 | name: 'server3-4', | |
172 | category: 2, | |
173 | nsfw: true, | |
174 | licence: 6, | |
175 | tags: [ 'tag1', 'tag2', 'tag3' ] | |
176 | } | |
177 | ||
c46edbc2 C |
178 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' }) |
179 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' }) | |
d8553faa | 180 | await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes) |
c46edbc2 C |
181 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' }) |
182 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) | |
183 | ||
d8553faa C |
184 | { |
185 | const user = { username: 'captain', password: 'password' } | |
186 | await createUser(servers[2].url, servers[2].accessToken, user.username, user.password) | |
187 | const userAccessToken = await getUserAccessToken(servers[2], user) | |
188 | ||
189 | const res = await getVideosList(servers[2].url) | |
190 | const video4 = res.body.data.find(v => v.name === 'server3-4') | |
191 | ||
192 | await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like') | |
193 | await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike') | |
194 | } | |
195 | ||
c46edbc2 C |
196 | await wait(5000) |
197 | ||
198 | // Server 1 follows server 3 | |
199 | await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) | |
200 | ||
201 | await wait(7000) | |
202 | ||
203 | let res = await getVideosList(servers[0].url) | |
204 | expect(res.body.total).to.equal(7) | |
205 | ||
206 | const video2 = res.body.data.find(v => v.name === 'server3-2') | |
207 | const video4 = res.body.data.find(v => v.name === 'server3-4') | |
208 | const video6 = res.body.data.find(v => v.name === 'server3-6') | |
209 | ||
210 | expect(video2).to.not.be.undefined | |
211 | expect(video4).to.not.be.undefined | |
212 | expect(video6).to.not.be.undefined | |
d8553faa C |
213 | |
214 | const res2 = await getVideo(servers[0].url, video4.id) | |
215 | const videoDetails = res2.body | |
216 | ||
217 | expect(videoDetails.name).to.equal('server3-4') | |
218 | expect(videoDetails.category).to.equal(2) | |
219 | expect(videoDetails.categoryLabel).to.equal('Films') | |
220 | expect(videoDetails.licence).to.equal(6) | |
221 | expect(videoDetails.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
222 | expect(videoDetails.language).to.equal(3) | |
223 | expect(videoDetails.languageLabel).to.equal('Mandarin') | |
224 | expect(videoDetails.nsfw).to.be.ok | |
225 | expect(videoDetails.description).to.equal('my super description') | |
226 | expect(videoDetails.serverHost).to.equal('localhost:9003') | |
b1fa3eba | 227 | expect(videoDetails.accountName).to.equal('root') |
d8553faa C |
228 | expect(videoDetails.likes).to.equal(1) |
229 | expect(videoDetails.dislikes).to.equal(1) | |
230 | expect(videoDetails.isLocal).to.be.false | |
231 | expect(videoDetails.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
232 | expect(dateIsValid(videoDetails.createdAt)).to.be.true | |
233 | expect(dateIsValid(videoDetails.updatedAt)).to.be.true | |
234 | expect(videoDetails.files).to.have.lengthOf(1) | |
235 | ||
236 | const file = videoDetails.files[0] | |
237 | const magnetUri = file.magnetUri | |
238 | expect(file.magnetUri).to.have.lengthOf.above(2) | |
239 | expect(file.torrentUrl).to.equal(`${servers[2].url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) | |
240 | expect(file.fileUrl).to.equal(`${servers[2].url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`) | |
241 | expect(file.resolution).to.equal(720) | |
242 | expect(file.resolutionLabel).to.equal('720p') | |
243 | expect(file.size).to.equal(218910) | |
244 | ||
245 | const test = await testVideoImage(servers[2].url, 'video_short.webm', videoDetails.thumbnailPath) | |
246 | expect(test).to.equal(true) | |
247 | ||
248 | const torrent = await webtorrentAdd(magnetUri) | |
249 | expect(torrent.files).to.be.an('array') | |
250 | expect(torrent.files.length).to.equal(1) | |
251 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
c46edbc2 C |
252 | }) |
253 | ||
0f91ae62 C |
254 | after(async function () { |
255 | killallServers(servers) | |
256 | ||
257 | // Keep the logs if the test failed | |
258 | if (this['ok']) { | |
259 | await flushTests() | |
260 | } | |
261 | }) | |
262 | }) |