]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
0e1dc3e7 | 3 | import * as chai from 'chai' |
afffe988 | 4 | import 'mocha' |
0e1dc3e7 | 5 | import { |
0e1dc3e7 | 6 | flushAndRunMultipleServers, |
afffe988 | 7 | flushTests, |
0e1dc3e7 | 8 | getVideoAbusesList, |
afffe988 | 9 | getVideosList, |
0e1dc3e7 | 10 | killallServers, |
afffe988 C |
11 | reportVideoAbuse, |
12 | ServerInfo, | |
13 | setAccessTokensToServers, | |
14 | uploadVideo, | |
15 | wait | |
0e1dc3e7 | 16 | } from '../utils' |
afffe988 C |
17 | import { doubleFollow } from '../utils/follows' |
18 | ||
19 | const expect = chai.expect | |
0e1dc3e7 C |
20 | |
21 | describe('Test video abuses', function () { | |
22 | let servers: ServerInfo[] = [] | |
23 | ||
24 | before(async function () { | |
572f8d3d | 25 | this.timeout(50000) |
0e1dc3e7 C |
26 | |
27 | // Run servers | |
28 | servers = await flushAndRunMultipleServers(2) | |
29 | ||
30 | // Get the access tokens | |
31 | await setAccessTokensToServers(servers) | |
32 | ||
afffe988 C |
33 | // Server 1 and server 2 follow each other |
34 | await doubleFollow(servers[0], servers[1]) | |
0e1dc3e7 | 35 | |
afffe988 | 36 | // Upload some videos on each servers |
0e1dc3e7 | 37 | const video1Attributes = { |
afffe988 C |
38 | name: 'my super name for server 1', |
39 | description: 'my super description for server 1' | |
0e1dc3e7 C |
40 | } |
41 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | |
42 | ||
43 | const video2Attributes = { | |
afffe988 C |
44 | name: 'my super name for server 2', |
45 | description: 'my super description for server 2' | |
0e1dc3e7 C |
46 | } |
47 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | |
48 | ||
572f8d3d | 49 | // Wait videos propagation, server 2 has transcoding enabled |
d48ff09d | 50 | await wait(15000) |
0e1dc3e7 C |
51 | |
52 | const res = await getVideosList(servers[0].url) | |
53 | const videos = res.body.data | |
54 | ||
55 | expect(videos.length).to.equal(2) | |
56 | ||
afffe988 C |
57 | servers[0].video = videos.find(video => video.name === 'my super name for server 1') |
58 | servers[1].video = videos.find(video => video.name === 'my super name for server 2') | |
0e1dc3e7 C |
59 | }) |
60 | ||
61 | it('Should not have video abuses', async function () { | |
62 | const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | |
63 | ||
64 | expect(res.body.total).to.equal(0) | |
65 | expect(res.body.data).to.be.an('array') | |
66 | expect(res.body.data.length).to.equal(0) | |
67 | }) | |
68 | ||
69 | it('Should report abuse on a local video', async function () { | |
572f8d3d | 70 | this.timeout(10000) |
0e1dc3e7 C |
71 | |
72 | const reason = 'my super bad reason' | |
73 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) | |
74 | ||
afffe988 | 75 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 |
572f8d3d | 76 | await wait(5000) |
0e1dc3e7 C |
77 | }) |
78 | ||
afffe988 | 79 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { |
0e1dc3e7 C |
80 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) |
81 | ||
82 | expect(res1.body.total).to.equal(1) | |
83 | expect(res1.body.data).to.be.an('array') | |
84 | expect(res1.body.data.length).to.equal(1) | |
85 | ||
86 | const abuse = res1.body.data[0] | |
87 | expect(abuse.reason).to.equal('my super bad reason') | |
88 | expect(abuse.reporterUsername).to.equal('root') | |
afffe988 | 89 | expect(abuse.reporterServerHost).to.equal('localhost:9001') |
0e1dc3e7 C |
90 | expect(abuse.videoId).to.equal(servers[0].video.id) |
91 | ||
92 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
93 | expect(res2.body.total).to.equal(0) | |
94 | expect(res2.body.data).to.be.an('array') | |
95 | expect(res2.body.data.length).to.equal(0) | |
96 | }) | |
97 | ||
98 | it('Should report abuse on a remote video', async function () { | |
572f8d3d | 99 | this.timeout(10000) |
0e1dc3e7 C |
100 | |
101 | const reason = 'my super bad reason 2' | |
102 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) | |
103 | ||
104 | // We wait requests propagation | |
572f8d3d | 105 | await wait(5000) |
0e1dc3e7 C |
106 | }) |
107 | ||
afffe988 | 108 | it('Should have 2 video abuse on server 1 and 1 on server 2', async function () { |
0e1dc3e7 C |
109 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) |
110 | expect(res1.body.total).to.equal(2) | |
111 | expect(res1.body.data).to.be.an('array') | |
112 | expect(res1.body.data.length).to.equal(2) | |
113 | ||
114 | const abuse1 = res1.body.data[0] | |
115 | expect(abuse1.reason).to.equal('my super bad reason') | |
116 | expect(abuse1.reporterUsername).to.equal('root') | |
afffe988 | 117 | expect(abuse1.reporterServerHost).to.equal('localhost:9001') |
0e1dc3e7 C |
118 | expect(abuse1.videoId).to.equal(servers[0].video.id) |
119 | ||
120 | const abuse2 = res1.body.data[1] | |
121 | expect(abuse2.reason).to.equal('my super bad reason 2') | |
122 | expect(abuse2.reporterUsername).to.equal('root') | |
afffe988 | 123 | expect(abuse2.reporterServerHost).to.equal('localhost:9001') |
0e1dc3e7 C |
124 | expect(abuse2.videoId).to.equal(servers[1].video.id) |
125 | ||
126 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
127 | expect(res2.body.total).to.equal(1) | |
128 | expect(res2.body.data).to.be.an('array') | |
129 | expect(res2.body.data.length).to.equal(1) | |
130 | ||
131 | const abuse3 = res2.body.data[0] | |
132 | expect(abuse3.reason).to.equal('my super bad reason 2') | |
133 | expect(abuse3.reporterUsername).to.equal('root') | |
afffe988 | 134 | expect(abuse3.reporterServerHost).to.equal('localhost:9001') |
0e1dc3e7 C |
135 | }) |
136 | ||
137 | after(async function () { | |
138 | killallServers(servers) | |
139 | ||
140 | // Keep the logs if the test failed | |
141 | if (this['ok']) { | |
142 | await flushTests() | |
143 | } | |
144 | }) | |
145 | }) |