]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos' | |
6 | import { | |
7 | cleanupTests, | |
8 | deleteVideoAbuse, | |
9 | flushAndRunMultipleServers, | |
10 | getVideoAbusesList, | |
11 | getVideosList, | |
12 | reportVideoAbuse, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | updateVideoAbuse, | |
16 | uploadVideo | |
17 | } from '../../../../shared/extra-utils/index' | |
18 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' | |
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
20 | ||
21 | const expect = chai.expect | |
22 | ||
23 | describe('Test video abuses', function () { | |
24 | let servers: ServerInfo[] = [] | |
25 | let abuseServer2: VideoAbuse | |
26 | ||
27 | before(async function () { | |
28 | this.timeout(50000) | |
29 | ||
30 | // Run servers | |
31 | servers = await flushAndRunMultipleServers(2) | |
32 | ||
33 | // Get the access tokens | |
34 | await setAccessTokensToServers(servers) | |
35 | ||
36 | // Server 1 and server 2 follow each other | |
37 | await doubleFollow(servers[0], servers[1]) | |
38 | ||
39 | // Upload some videos on each servers | |
40 | const video1Attributes = { | |
41 | name: 'my super name for server 1', | |
42 | description: 'my super description for server 1' | |
43 | } | |
44 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | |
45 | ||
46 | const video2Attributes = { | |
47 | name: 'my super name for server 2', | |
48 | description: 'my super description for server 2' | |
49 | } | |
50 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | |
51 | ||
52 | // Wait videos propagation, server 2 has transcoding enabled | |
53 | await waitJobs(servers) | |
54 | ||
55 | const res = await getVideosList(servers[0].url) | |
56 | const videos = res.body.data | |
57 | ||
58 | expect(videos.length).to.equal(2) | |
59 | ||
60 | servers[0].video = videos.find(video => video.name === 'my super name for server 1') | |
61 | servers[1].video = videos.find(video => video.name === 'my super name for server 2') | |
62 | }) | |
63 | ||
64 | it('Should not have video abuses', async function () { | |
65 | const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | |
66 | ||
67 | expect(res.body.total).to.equal(0) | |
68 | expect(res.body.data).to.be.an('array') | |
69 | expect(res.body.data.length).to.equal(0) | |
70 | }) | |
71 | ||
72 | it('Should report abuse on a local video', async function () { | |
73 | this.timeout(15000) | |
74 | ||
75 | const reason = 'my super bad reason' | |
76 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) | |
77 | ||
78 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 | |
79 | await waitJobs(servers) | |
80 | }) | |
81 | ||
82 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { | |
83 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | |
84 | ||
85 | expect(res1.body.total).to.equal(1) | |
86 | expect(res1.body.data).to.be.an('array') | |
87 | expect(res1.body.data.length).to.equal(1) | |
88 | ||
89 | const abuse: VideoAbuse = res1.body.data[0] | |
90 | expect(abuse.reason).to.equal('my super bad reason') | |
91 | expect(abuse.reporterAccount.name).to.equal('root') | |
92 | expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) | |
93 | expect(abuse.video.id).to.equal(servers[0].video.id) | |
94 | ||
95 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
96 | expect(res2.body.total).to.equal(0) | |
97 | expect(res2.body.data).to.be.an('array') | |
98 | expect(res2.body.data.length).to.equal(0) | |
99 | }) | |
100 | ||
101 | it('Should report abuse on a remote video', async function () { | |
102 | this.timeout(10000) | |
103 | ||
104 | const reason = 'my super bad reason 2' | |
105 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) | |
106 | ||
107 | // We wait requests propagation | |
108 | await waitJobs(servers) | |
109 | }) | |
110 | ||
111 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { | |
112 | const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) | |
113 | expect(res1.body.total).to.equal(2) | |
114 | expect(res1.body.data).to.be.an('array') | |
115 | expect(res1.body.data.length).to.equal(2) | |
116 | ||
117 | const abuse1: VideoAbuse = res1.body.data[0] | |
118 | expect(abuse1.reason).to.equal('my super bad reason') | |
119 | expect(abuse1.reporterAccount.name).to.equal('root') | |
120 | expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port) | |
121 | expect(abuse1.video.id).to.equal(servers[0].video.id) | |
122 | expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING) | |
123 | expect(abuse1.state.label).to.equal('Pending') | |
124 | expect(abuse1.moderationComment).to.be.null | |
125 | ||
126 | const abuse2: VideoAbuse = res1.body.data[1] | |
127 | expect(abuse2.reason).to.equal('my super bad reason 2') | |
128 | expect(abuse2.reporterAccount.name).to.equal('root') | |
129 | expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port) | |
130 | expect(abuse2.video.id).to.equal(servers[1].video.id) | |
131 | expect(abuse2.state.id).to.equal(VideoAbuseState.PENDING) | |
132 | expect(abuse2.state.label).to.equal('Pending') | |
133 | expect(abuse2.moderationComment).to.be.null | |
134 | ||
135 | const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
136 | expect(res2.body.total).to.equal(1) | |
137 | expect(res2.body.data).to.be.an('array') | |
138 | expect(res2.body.data.length).to.equal(1) | |
139 | ||
140 | abuseServer2 = res2.body.data[0] | |
141 | expect(abuseServer2.reason).to.equal('my super bad reason 2') | |
142 | expect(abuseServer2.reporterAccount.name).to.equal('root') | |
143 | expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port) | |
144 | expect(abuseServer2.state.id).to.equal(VideoAbuseState.PENDING) | |
145 | expect(abuseServer2.state.label).to.equal('Pending') | |
146 | expect(abuseServer2.moderationComment).to.be.null | |
147 | }) | |
148 | ||
149 | it('Should update the state of a video abuse', async function () { | |
150 | const body = { state: VideoAbuseState.REJECTED } | |
151 | await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) | |
152 | ||
153 | const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
154 | expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED) | |
155 | }) | |
156 | ||
157 | it('Should add a moderation comment', async function () { | |
158 | const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' } | |
159 | await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) | |
160 | ||
161 | const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
162 | expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED) | |
163 | expect(res.body.data[0].moderationComment).to.equal('It is valid') | |
164 | }) | |
165 | ||
166 | it('Should delete the video abuse', async function () { | |
167 | await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id) | |
168 | ||
169 | const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) | |
170 | expect(res.body.total).to.equal(0) | |
171 | expect(res.body.data).to.be.an('array') | |
172 | expect(res.body.data.length).to.equal(0) | |
173 | }) | |
174 | ||
175 | after(async function () { | |
176 | await cleanupTests(servers) | |
177 | }) | |
178 | }) |