diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-01 19:04:29 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-01 19:04:29 +0200 |
commit | 843aa7ba0312e7180e7bbae147e32ee60e70d9ba (patch) | |
tree | df5533a9dda312877b8b3a6992b81c75044c094e /server/tests/api/video-blacklist.js | |
parent | 3eeeb87fe62fab3e48455f53c8a725b49878b9b3 (diff) | |
download | PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.tar.gz PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.tar.zst PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.zip |
Server: add tests for video blacklists
Diffstat (limited to 'server/tests/api/video-blacklist.js')
-rw-r--r-- | server/tests/api/video-blacklist.js | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/server/tests/api/video-blacklist.js b/server/tests/api/video-blacklist.js new file mode 100644 index 000000000..c95fc17cb --- /dev/null +++ b/server/tests/api/video-blacklist.js | |||
@@ -0,0 +1,138 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const chai = require('chai') | ||
6 | const each = require('async/each') | ||
7 | const expect = chai.expect | ||
8 | const series = require('async/series') | ||
9 | |||
10 | const loginUtils = require('../utils/login') | ||
11 | const podsUtils = require('../utils/pods') | ||
12 | const serversUtils = require('../utils/servers') | ||
13 | const videosUtils = require('../utils/videos') | ||
14 | const videoBlacklistsUtils = require('../utils/video-blacklists') | ||
15 | |||
16 | describe('Test video blacklists', function () { | ||
17 | let servers = [] | ||
18 | |||
19 | before(function (done) { | ||
20 | this.timeout(30000) | ||
21 | |||
22 | series([ | ||
23 | // Run servers | ||
24 | function (next) { | ||
25 | serversUtils.flushAndRunMultipleServers(2, function (serversRun) { | ||
26 | servers = serversRun | ||
27 | next() | ||
28 | }) | ||
29 | }, | ||
30 | // Get the access tokens | ||
31 | function (next) { | ||
32 | each(servers, function (server, callbackEach) { | ||
33 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
34 | if (err) return callbackEach(err) | ||
35 | |||
36 | server.accessToken = accessToken | ||
37 | callbackEach() | ||
38 | }) | ||
39 | }, next) | ||
40 | }, | ||
41 | // Pod 1 makes friend with pod 2 | ||
42 | function (next) { | ||
43 | const server = servers[0] | ||
44 | podsUtils.makeFriends(server.url, server.accessToken, next) | ||
45 | }, | ||
46 | // Upload a video on pod 2 | ||
47 | function (next) { | ||
48 | const videoAttributes = { | ||
49 | name: 'my super name for pod 2', | ||
50 | description: 'my super description for pod 2' | ||
51 | } | ||
52 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next) | ||
53 | }, | ||
54 | // Wait videos propagation | ||
55 | function (next) { | ||
56 | setTimeout(next, 11000) | ||
57 | }, | ||
58 | function (next) { | ||
59 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
60 | if (err) throw err | ||
61 | |||
62 | const videos = res.body.data | ||
63 | |||
64 | expect(videos.length).to.equal(1) | ||
65 | |||
66 | servers[0].remoteVideo = videos.find(function (video) { return video.name === 'my super name for pod 2' }) | ||
67 | |||
68 | next() | ||
69 | }) | ||
70 | } | ||
71 | ], done) | ||
72 | }) | ||
73 | |||
74 | it('Should blacklist a remote video on pod 1', function (done) { | ||
75 | videoBlacklistsUtils.addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id, done) | ||
76 | }) | ||
77 | |||
78 | it('Should not have the video blacklisted in videos list on pod 1', function (done) { | ||
79 | videosUtils.getVideosList(servers[0].url, function (err, res) { | ||
80 | if (err) throw err | ||
81 | |||
82 | expect(res.body.total).to.equal(0) | ||
83 | expect(res.body.data).to.be.an('array') | ||
84 | expect(res.body.data.length).to.equal(0) | ||
85 | |||
86 | done() | ||
87 | }) | ||
88 | }) | ||
89 | |||
90 | it('Should not have the video blacklisted in videos search on pod 1', function (done) { | ||
91 | videosUtils.searchVideo(servers[0].url, 'name', function (err, res) { | ||
92 | if (err) throw err | ||
93 | |||
94 | expect(res.body.total).to.equal(0) | ||
95 | expect(res.body.data).to.be.an('array') | ||
96 | expect(res.body.data.length).to.equal(0) | ||
97 | |||
98 | done() | ||
99 | }) | ||
100 | }) | ||
101 | |||
102 | it('Should have the blacklisted video in videos list on pod 2', function (done) { | ||
103 | videosUtils.getVideosList(servers[1].url, function (err, res) { | ||
104 | if (err) throw err | ||
105 | |||
106 | expect(res.body.total).to.equal(1) | ||
107 | expect(res.body.data).to.be.an('array') | ||
108 | expect(res.body.data.length).to.equal(1) | ||
109 | |||
110 | done() | ||
111 | }) | ||
112 | }) | ||
113 | |||
114 | it('Should have the video blacklisted in videos search on pod 2', function (done) { | ||
115 | videosUtils.searchVideo(servers[1].url, 'name', function (err, res) { | ||
116 | if (err) throw err | ||
117 | |||
118 | expect(res.body.total).to.equal(1) | ||
119 | expect(res.body.data).to.be.an('array') | ||
120 | expect(res.body.data.length).to.equal(1) | ||
121 | |||
122 | done() | ||
123 | }) | ||
124 | }) | ||
125 | |||
126 | after(function (done) { | ||
127 | servers.forEach(function (server) { | ||
128 | process.kill(-server.app.pid) | ||
129 | }) | ||
130 | |||
131 | // Keep the logs if the test failed | ||
132 | if (this.ok) { | ||
133 | serversUtils.flushTests(done) | ||
134 | } else { | ||
135 | done() | ||
136 | } | ||
137 | }) | ||
138 | }) | ||