aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/video-blacklist-management.ts
diff options
context:
space:
mode:
authorGreen-Star <Green-Star@users.noreply.github.com>2017-09-22 09:13:43 +0200
committerBigard Florian <florian.bigard@gmail.com>2017-09-22 09:13:43 +0200
commit792dbaf07f83fbe3f1d209cd9edf190442c7d2f3 (patch)
treef7edf9caf17baaaf95c219c3ac73d598e3fd3df8 /server/tests/api/video-blacklist-management.ts
parentc9d6d155c397d0da0cb2d50064264fc1716f0501 (diff)
downloadPeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.gz
PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.zst
PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.zip
Handle blacklist (#84)
* Client: Add list blacklist feature * Server: Add list blacklist feature * Client: Add videoId column * Server: Add some video infos in the REST api * Client: Add video information in the blacklist list * Fix sortable columns :) * Client: Add removeFromBlacklist feature * Server: Add removeFromBlacklist feature * Move to TypeScript * Move to TypeScript and Promises * Server: Fix blacklist list sort * Server: Fetch videos informations * Use common shared interface for client and server * Add check-params remove blacklisted video tests * Add check-params list blacklisted videos tests * Add list blacklist tests * Add remove from blacklist tests * Add video blacklist management tests * Fix rebase onto develop issues * Server: Add sort on blacklist id column * Server: Add blacklists library * Add blacklist id sort test * Add check-params tests for blacklist list pagination, count and sort * Fix coding style * Increase Remote API tests timeout * Increase Request scheduler API tests timeout * Fix typo * Increase video transcoding API tests timeout * Move tests to Typescript * Use lodash orderBy method * Fix typos * Client: Remove optional tests in blacklist model attributes * Move blacklist routes from 'blacklists' to 'blacklist' * CLient: Remove blacklist-list.component.scss * Rename 'blacklists' files to 'blacklist' * Use only BlacklistedVideo interface * Server: Use getFormattedObjects method in listBlacklist method * Client: Use new coding style * Server: Use new sort validator methods * Server: Use new checkParams methods * Client: Fix sortable columns
Diffstat (limited to 'server/tests/api/video-blacklist-management.ts')
-rw-r--r--server/tests/api/video-blacklist-management.ts162
1 files changed, 162 insertions, 0 deletions
diff --git a/server/tests/api/video-blacklist-management.ts b/server/tests/api/video-blacklist-management.ts
new file mode 100644
index 000000000..7057f4b23
--- /dev/null
+++ b/server/tests/api/video-blacklist-management.ts
@@ -0,0 +1,162 @@
1/* tslint:disable:no-unused-expressions */
2
3import 'mocha'
4import * as chai from 'chai'
5const expect = chai.expect
6import * as lodash from 'lodash'
7const orderBy = lodash.orderBy
8
9import {
10 ServerInfo,
11 flushTests,
12 wait,
13 setAccessTokensToServers,
14 flushAndRunMultipleServers,
15 killallServers,
16 makeFriends,
17 getVideosList,
18 uploadVideo,
19 addVideoToBlacklist,
20 removeVideoFromBlacklist,
21 getBlacklistedVideosList,
22 getSortedBlacklistedVideosList
23} from '../utils'
24
25describe('Test video blacklist management', function () {
26 let servers: ServerInfo[] = []
27
28 async function blacklistVideosOnPod (server: ServerInfo) {
29 const res = await getVideosList(server.url)
30
31 const videos = res.body.data
32 for (let video of videos) {
33 await addVideoToBlacklist(server.url, server.accessToken, video.id)
34 }
35 }
36
37 before(async function () {
38 this.timeout(120000)
39
40 // Run servers
41 servers = await flushAndRunMultipleServers(2)
42
43 // Get the access tokens
44 await setAccessTokensToServers(servers)
45
46 // Pod 1 makes friend with pod 2
47 await makeFriends(servers[0].url, servers[0].accessToken)
48
49 // Upload 2 videos on pod 2
50 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on pod 2' })
51 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on pod 2' })
52
53 // Wait videos propagation
54 await wait(22000)
55
56 // Blacklist the two videos on pod 1
57 await blacklistVideosOnPod(servers[0])
58 })
59
60 describe('When listing blacklisted videos', function () {
61 it('Should display all the blacklisted videos', async function () {
62 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
63
64 expect(res.body.total).to.equal(2)
65
66 const videos = res.body.data
67 expect(videos).to.be.an('array')
68 expect(videos.length).to.equal(2)
69 })
70
71 it('Should get the correct sort when sorting by descending id', async function () {
72 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
73 expect(res.body.total).to.equal(2)
74
75 const videos = res.body.data
76 expect(videos).to.be.an('array')
77 expect(videos.length).to.equal(2)
78
79 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
80
81 expect(videos).to.deep.equal(result)
82 })
83
84 it('Should get the correct sort when sorting by descending video name', async function () {
85 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
86 expect(res.body.total).to.equal(2)
87
88 const videos = res.body.data
89 expect(videos).to.be.an('array')
90 expect(videos.length).to.equal(2)
91
92 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
93
94 expect(videos).to.deep.equal(result)
95 })
96
97 it('Should get the correct sort when sorting by ascending creation date', async function () {
98 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
99 expect(res.body.total).to.equal(2)
100
101 const videos = res.body.data
102 expect(videos).to.be.an('array')
103 expect(videos.length).to.equal(2)
104
105 const result = orderBy(res.body.data, [ 'createdAt' ])
106
107 expect(videos).to.deep.equal(result)
108 })
109 })
110
111 describe('When removing a blacklisted video', function () {
112 let videoToRemove
113 let blacklist = []
114
115 it('Should not have any video in videos list on pod 1', async function () {
116 const res = await getVideosList(servers[0].url)
117 expect(res.body.total).to.equal(0)
118 expect(res.body.data).to.be.an('array')
119 expect(res.body.data.length).to.equal(0)
120 })
121
122 it('Should remove a video from the blacklist on pod 1', async function () {
123 // Get one video in the blacklist
124 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
125 videoToRemove = res.body.data[0]
126 blacklist = res.body.data.slice(1)
127
128 // Remove it
129 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId)
130 })
131
132 it('Should have the ex-blacklisted video in videos list on pod 1', async function () {
133 const res = await getVideosList(servers[0].url)
134 expect(res.body.total).to.equal(1)
135
136 const videos = res.body.data
137 expect(videos).to.be.an('array')
138 expect(videos.length).to.equal(1)
139
140 expect(videos[0].name).to.equal(videoToRemove.name)
141 expect(videos[0].id).to.equal(videoToRemove.videoId)
142 })
143
144 it('Should not have the ex-blacklisted video in videos blacklist list on pod 1', async function () {
145 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
146 expect(res.body.total).to.equal(1)
147
148 const videos = res.body.data
149 expect(videos).to.be.an('array')
150 expect(videos.length).to.equal(1)
151 expect(videos).to.deep.equal(blacklist)
152 })
153 })
154
155 after(async function () {
156 killallServers(servers)
157
158 if (this['ok']) {
159 await flushTests()
160 }
161 })
162})