]>
Commit | Line | Data |
---|---|---|
792dbaf0 GS |
1 | /* tslint:disable:no-unused-expressions */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | const expect = chai.expect | |
6 | import * as lodash from 'lodash' | |
7 | const orderBy = lodash.orderBy | |
8 | ||
9 | import { | |
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 | ||
25 | describe('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 | }) |