diff options
Diffstat (limited to 'server/tests/api/videos/video-blacklist-management.ts')
-rw-r--r-- | server/tests/api/videos/video-blacklist-management.ts | 78 |
1 files changed, 57 insertions, 21 deletions
diff --git a/server/tests/api/videos/video-blacklist-management.ts b/server/tests/api/videos/video-blacklist-management.ts index 4d1a06436..7bf39dc99 100644 --- a/server/tests/api/videos/video-blacklist-management.ts +++ b/server/tests/api/videos/video-blacklist-management.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | /* tslint:disable:no-unused-expressions */ | 1 | /* tslint:disable:no-unused-expression */ |
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import * as lodash from 'lodash' | 4 | import * as lodash from 'lodash' |
@@ -7,29 +7,33 @@ import { | |||
7 | addVideoToBlacklist, | 7 | addVideoToBlacklist, |
8 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
9 | getBlacklistedVideosList, | 9 | getBlacklistedVideosList, |
10 | getMyVideos, | ||
10 | getSortedBlacklistedVideosList, | 11 | getSortedBlacklistedVideosList, |
11 | getVideosList, | 12 | getVideosList, |
12 | killallServers, | 13 | killallServers, |
13 | removeVideoFromBlacklist, | 14 | removeVideoFromBlacklist, |
14 | ServerInfo, | 15 | ServerInfo, |
15 | setAccessTokensToServers, | 16 | setAccessTokensToServers, |
17 | updateVideoBlacklist, | ||
16 | uploadVideo | 18 | uploadVideo |
17 | } from '../../utils/index' | 19 | } from '../../utils/index' |
18 | import { doubleFollow } from '../../utils/server/follows' | 20 | import { doubleFollow } from '../../utils/server/follows' |
19 | import { waitJobs } from '../../utils/server/jobs' | 21 | import { waitJobs } from '../../utils/server/jobs' |
22 | import { VideoAbuse } from '../../../../shared/models/videos' | ||
20 | 23 | ||
21 | const expect = chai.expect | 24 | const expect = chai.expect |
22 | const orderBy = lodash.orderBy | 25 | const orderBy = lodash.orderBy |
23 | 26 | ||
24 | describe('Test video blacklist management', function () { | 27 | describe('Test video blacklist management', function () { |
25 | let servers: ServerInfo[] = [] | 28 | let servers: ServerInfo[] = [] |
29 | let videoId: number | ||
26 | 30 | ||
27 | async function blacklistVideosOnServer (server: ServerInfo) { | 31 | async function blacklistVideosOnServer (server: ServerInfo) { |
28 | const res = await getVideosList(server.url) | 32 | const res = await getVideosList(server.url) |
29 | 33 | ||
30 | const videos = res.body.data | 34 | const videos = res.body.data |
31 | for (let video of videos) { | 35 | for (let video of videos) { |
32 | await addVideoToBlacklist(server.url, server.accessToken, video.id) | 36 | await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason') |
33 | } | 37 | } |
34 | } | 38 | } |
35 | 39 | ||
@@ -62,53 +66,85 @@ describe('Test video blacklist management', function () { | |||
62 | 66 | ||
63 | expect(res.body.total).to.equal(2) | 67 | expect(res.body.total).to.equal(2) |
64 | 68 | ||
65 | const videos = res.body.data | 69 | const blacklistedVideos = res.body.data |
66 | expect(videos).to.be.an('array') | 70 | expect(blacklistedVideos).to.be.an('array') |
67 | expect(videos.length).to.equal(2) | 71 | expect(blacklistedVideos.length).to.equal(2) |
72 | |||
73 | for (const blacklistedVideo of blacklistedVideos) { | ||
74 | expect(blacklistedVideo.reason).to.equal('super reason') | ||
75 | videoId = blacklistedVideo.video.id | ||
76 | } | ||
68 | }) | 77 | }) |
69 | 78 | ||
70 | it('Should get the correct sort when sorting by descending id', async function () { | 79 | it('Should get the correct sort when sorting by descending id', async function () { |
71 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') | 80 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') |
72 | expect(res.body.total).to.equal(2) | 81 | expect(res.body.total).to.equal(2) |
73 | 82 | ||
74 | const videos = res.body.data | 83 | const blacklistedVideos = res.body.data |
75 | expect(videos).to.be.an('array') | 84 | expect(blacklistedVideos).to.be.an('array') |
76 | expect(videos.length).to.equal(2) | 85 | expect(blacklistedVideos.length).to.equal(2) |
77 | 86 | ||
78 | const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) | 87 | const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) |
79 | 88 | ||
80 | expect(videos).to.deep.equal(result) | 89 | expect(blacklistedVideos).to.deep.equal(result) |
81 | }) | 90 | }) |
82 | 91 | ||
83 | it('Should get the correct sort when sorting by descending video name', async function () { | 92 | it('Should get the correct sort when sorting by descending video name', async function () { |
84 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | 93 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') |
85 | expect(res.body.total).to.equal(2) | 94 | expect(res.body.total).to.equal(2) |
86 | 95 | ||
87 | const videos = res.body.data | 96 | const blacklistedVideos = res.body.data |
88 | expect(videos).to.be.an('array') | 97 | expect(blacklistedVideos).to.be.an('array') |
89 | expect(videos.length).to.equal(2) | 98 | expect(blacklistedVideos.length).to.equal(2) |
90 | 99 | ||
91 | const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) | 100 | const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) |
92 | 101 | ||
93 | expect(videos).to.deep.equal(result) | 102 | expect(blacklistedVideos).to.deep.equal(result) |
94 | }) | 103 | }) |
95 | 104 | ||
96 | it('Should get the correct sort when sorting by ascending creation date', async function () { | 105 | it('Should get the correct sort when sorting by ascending creation date', async function () { |
97 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') | 106 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') |
98 | expect(res.body.total).to.equal(2) | 107 | expect(res.body.total).to.equal(2) |
99 | 108 | ||
100 | const videos = res.body.data | 109 | const blacklistedVideos = res.body.data |
101 | expect(videos).to.be.an('array') | 110 | expect(blacklistedVideos).to.be.an('array') |
102 | expect(videos.length).to.equal(2) | 111 | expect(blacklistedVideos.length).to.equal(2) |
103 | 112 | ||
104 | const result = orderBy(res.body.data, [ 'createdAt' ]) | 113 | const result = orderBy(res.body.data, [ 'createdAt' ]) |
105 | 114 | ||
106 | expect(videos).to.deep.equal(result) | 115 | expect(blacklistedVideos).to.deep.equal(result) |
116 | }) | ||
117 | }) | ||
118 | |||
119 | describe('When updating blacklisted videos', function () { | ||
120 | it('Should change the reason', async function () { | ||
121 | await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') | ||
122 | |||
123 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | ||
124 | const video = res.body.data.find(b => b.video.id === videoId) | ||
125 | |||
126 | expect(video.reason).to.equal('my super reason updated') | ||
127 | }) | ||
128 | }) | ||
129 | |||
130 | describe('When listing my videos', function () { | ||
131 | it('Should display blacklisted videos', async function () { | ||
132 | await blacklistVideosOnServer(servers[1]) | ||
133 | |||
134 | const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) | ||
135 | |||
136 | expect(res.body.total).to.equal(2) | ||
137 | expect(res.body.data).to.have.lengthOf(2) | ||
138 | |||
139 | for (const video of res.body.data) { | ||
140 | expect(video.blacklisted).to.be.true | ||
141 | expect(video.blacklistedReason).to.equal('super reason') | ||
142 | } | ||
107 | }) | 143 | }) |
108 | }) | 144 | }) |
109 | 145 | ||
110 | describe('When removing a blacklisted video', function () { | 146 | describe('When removing a blacklisted video', function () { |
111 | let videoToRemove | 147 | let videoToRemove: VideoAbuse |
112 | let blacklist = [] | 148 | let blacklist = [] |
113 | 149 | ||
114 | it('Should not have any video in videos list on server 1', async function () { | 150 | it('Should not have any video in videos list on server 1', async function () { |
@@ -125,7 +161,7 @@ describe('Test video blacklist management', function () { | |||
125 | blacklist = res.body.data.slice(1) | 161 | blacklist = res.body.data.slice(1) |
126 | 162 | ||
127 | // Remove it | 163 | // Remove it |
128 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId) | 164 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) |
129 | }) | 165 | }) |
130 | 166 | ||
131 | it('Should have the ex-blacklisted video in videos list on server 1', async function () { | 167 | it('Should have the ex-blacklisted video in videos list on server 1', async function () { |
@@ -136,8 +172,8 @@ describe('Test video blacklist management', function () { | |||
136 | expect(videos).to.be.an('array') | 172 | expect(videos).to.be.an('array') |
137 | expect(videos.length).to.equal(1) | 173 | expect(videos.length).to.equal(1) |
138 | 174 | ||
139 | expect(videos[0].name).to.equal(videoToRemove.name) | 175 | expect(videos[0].name).to.equal(videoToRemove.video.name) |
140 | expect(videos[0].id).to.equal(videoToRemove.videoId) | 176 | expect(videos[0].id).to.equal(videoToRemove.video.id) |
141 | }) | 177 | }) |
142 | 178 | ||
143 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { | 179 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { |