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