aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils')
-rw-r--r--server/tests/utils/login.js11
-rw-r--r--server/tests/utils/miscs.js6
-rw-r--r--server/tests/utils/servers.js8
-rw-r--r--server/tests/utils/video-abuses.js73
-rw-r--r--server/tests/utils/videos.js84
5 files changed, 154 insertions, 28 deletions
diff --git a/server/tests/utils/login.js b/server/tests/utils/login.js
index 465564e14..c984c0baf 100644
--- a/server/tests/utils/login.js
+++ b/server/tests/utils/login.js
@@ -4,7 +4,8 @@ const request = require('supertest')
4 4
5const loginUtils = { 5const loginUtils = {
6 login, 6 login,
7 loginAndGetAccessToken 7 loginAndGetAccessToken,
8 getUserAccessToken
8} 9}
9 10
10// ---------------------- Export functions -------------------- 11// ---------------------- Export functions --------------------
@@ -43,6 +44,14 @@ function loginAndGetAccessToken (server, callback) {
43 }) 44 })
44} 45}
45 46
47function getUserAccessToken (server, user, callback) {
48 login(server.url, server.client, user, 200, function (err, res) {
49 if (err) return callback(err)
50
51 return callback(null, res.body.access_token)
52 })
53}
54
46// --------------------------------------------------------------------------- 55// ---------------------------------------------------------------------------
47 56
48module.exports = loginUtils 57module.exports = loginUtils
diff --git a/server/tests/utils/miscs.js b/server/tests/utils/miscs.js
index 4ceff65df..c4b661496 100644
--- a/server/tests/utils/miscs.js
+++ b/server/tests/utils/miscs.js
@@ -6,12 +6,14 @@ const miscsUtils = {
6 6
7// ---------------------- Export functions -------------------- 7// ---------------------- Export functions --------------------
8 8
9function dateIsValid (dateString) { 9function dateIsValid (dateString, interval) {
10 const dateToCheck = new Date(dateString) 10 const dateToCheck = new Date(dateString)
11 const now = new Date() 11 const now = new Date()
12 12
13 // Check if the interval is more than 2 minutes 13 // Check if the interval is more than 2 minutes
14 if (now - dateToCheck > 120000) return false 14 if (!interval) interval = 120000
15
16 if (now - dateToCheck > interval) return false
15 17
16 return true 18 return true
17} 19}
diff --git a/server/tests/utils/servers.js b/server/tests/utils/servers.js
index 01c9a2f39..1946ef49a 100644
--- a/server/tests/utils/servers.js
+++ b/server/tests/utils/servers.js
@@ -34,7 +34,7 @@ function flushAndRunMultipleServers (totalServers, serversRun) {
34 runServer(j, function (app, url) { 34 runServer(j, function (app, url) {
35 anotherServerDone(j, app, url) 35 anotherServerDone(j, app, url)
36 }) 36 })
37 }, 1000 * j) 37 }, 1000 * (j - 1))
38 } 38 }
39 }) 39 })
40} 40}
@@ -60,12 +60,12 @@ function runServer (number, callback) {
60 60
61 // These actions are async so we need to be sure that they have both been done 61 // These actions are async so we need to be sure that they have both been done
62 const serverRunString = { 62 const serverRunString = {
63 'Connected to mongodb': false, 63 'Database is ready': false,
64 'Server listening on port': false 64 'Server listening on port': false
65 } 65 }
66 66
67 const regexps = { 67 const regexps = {
68 client_id: 'Client id: ([a-f0-9]+)', 68 client_id: 'Client id: (.+)',
69 client_secret: 'Client secret: (.+)', 69 client_secret: 'Client secret: (.+)',
70 user_username: 'Username: (.+)', 70 user_username: 'Username: (.+)',
71 user_password: 'User password: (.+)' 71 user_password: 'User password: (.+)'
@@ -103,7 +103,7 @@ function runServer (number, callback) {
103 if (serverRunString[key] === false) dontContinue = true 103 if (serverRunString[key] === false) dontContinue = true
104 } 104 }
105 105
106 // If no, there is maybe one thing not already initialized (mongodb...) 106 // If no, there is maybe one thing not already initialized (client/user credentials generation...)
107 if (dontContinue === true) return 107 if (dontContinue === true) return
108 108
109 server.app.stdout.removeListener('data', onStdout) 109 server.app.stdout.removeListener('data', onStdout)
diff --git a/server/tests/utils/video-abuses.js b/server/tests/utils/video-abuses.js
new file mode 100644
index 000000000..596c824b3
--- /dev/null
+++ b/server/tests/utils/video-abuses.js
@@ -0,0 +1,73 @@
1'use strict'
2
3const request = require('supertest')
4
5const videosUtils = {
6 getVideoAbusesList,
7 getVideoAbusesListPagination,
8 getVideoAbusesListSort,
9 reportVideoAbuse
10}
11
12// ---------------------- Export functions --------------------
13
14function reportVideoAbuse (url, token, videoId, reason, specialStatus, end) {
15 if (!end) {
16 end = specialStatus
17 specialStatus = 204
18 }
19
20 const path = '/api/v1/videos/' + videoId + '/abuse'
21
22 request(url)
23 .post(path)
24 .set('Accept', 'application/json')
25 .set('Authorization', 'Bearer ' + token)
26 .send({ reason })
27 .expect(specialStatus)
28 .end(end)
29}
30
31function getVideoAbusesList (url, token, end) {
32 const path = '/api/v1/videos/abuse'
33
34 request(url)
35 .get(path)
36 .query({ sort: 'createdAt' })
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + token)
39 .expect(200)
40 .expect('Content-Type', /json/)
41 .end(end)
42}
43
44function getVideoAbusesListPagination (url, token, start, count, end) {
45 const path = '/api/v1/videos/abuse'
46
47 request(url)
48 .get(path)
49 .query({ start: start })
50 .query({ count: count })
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + token)
53 .expect(200)
54 .expect('Content-Type', /json/)
55 .end(end)
56}
57
58function getVideoAbusesListSort (url, token, sort, end) {
59 const path = '/api/v1/videos/abuse'
60
61 request(url)
62 .get(path)
63 .query({ sort: sort })
64 .set('Accept', 'application/json')
65 .set('Authorization', 'Bearer ' + token)
66 .expect(200)
67 .expect('Content-Type', /json/)
68 .end(end)
69}
70
71// ---------------------------------------------------------------------------
72
73module.exports = videosUtils
diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js
index 536093db1..f94368437 100644
--- a/server/tests/utils/videos.js
+++ b/server/tests/utils/videos.js
@@ -15,7 +15,8 @@ const videosUtils = {
15 searchVideoWithPagination, 15 searchVideoWithPagination,
16 searchVideoWithSort, 16 searchVideoWithSort,
17 testVideoImage, 17 testVideoImage,
18 uploadVideo 18 uploadVideo,
19 updateVideo
19} 20}
20 21
21// ---------------------- Export functions -------------------- 22// ---------------------- Export functions --------------------
@@ -25,7 +26,7 @@ function getAllVideosListBy (url, end) {
25 26
26 request(url) 27 request(url)
27 .get(path) 28 .get(path)
28 .query({ sort: 'createdDate' }) 29 .query({ sort: 'createdAt' })
29 .query({ start: 0 }) 30 .query({ start: 0 })
30 .query({ count: 10000 }) 31 .query({ count: 10000 })
31 .set('Accept', 'application/json') 32 .set('Accept', 'application/json')
@@ -57,17 +58,25 @@ function getVideosList (url, end) {
57 .end(end) 58 .end(end)
58} 59}
59 60
60function getVideosListPagination (url, start, count, end) { 61function getVideosListPagination (url, start, count, sort, end) {
62 if (!end) {
63 end = sort
64 sort = null
65 }
66
61 const path = '/api/v1/videos' 67 const path = '/api/v1/videos'
62 68
63 request(url) 69 const req = request(url)
64 .get(path) 70 .get(path)
65 .query({ start: start }) 71 .query({ start: start })
66 .query({ count: count }) 72 .query({ count: count })
67 .set('Accept', 'application/json') 73
68 .expect(200) 74 if (sort) req.query({ sort })
69 .expect('Content-Type', /json/) 75
70 .end(end) 76 req.set('Accept', 'application/json')
77 .expect(200)
78 .expect('Content-Type', /json/)
79 .end(end)
71} 80}
72 81
73function getVideosListSort (url, sort, end) { 82function getVideosListSort (url, sort, end) {
@@ -115,18 +124,26 @@ function searchVideo (url, search, field, end) {
115 .end(end) 124 .end(end)
116} 125}
117 126
118function searchVideoWithPagination (url, search, field, start, count, end) { 127function searchVideoWithPagination (url, search, field, start, count, sort, end) {
128 if (!end) {
129 end = sort
130 sort = null
131 }
132
119 const path = '/api/v1/videos' 133 const path = '/api/v1/videos'
120 134
121 request(url) 135 const req = request(url)
122 .get(path + '/search/' + search) 136 .get(path + '/search/' + search)
123 .query({ start: start }) 137 .query({ start: start })
124 .query({ count: count }) 138 .query({ count: count })
125 .query({ field: field }) 139 .query({ field: field })
126 .set('Accept', 'application/json') 140
127 .expect(200) 141 if (sort) req.query({ sort })
128 .expect('Content-Type', /json/) 142
129 .end(end) 143 req.set('Accept', 'application/json')
144 .expect(200)
145 .expect('Content-Type', /json/)
146 .end(end)
130} 147}
131 148
132function searchVideoWithSort (url, search, sort, end) { 149function searchVideoWithSort (url, search, sort, end) {
@@ -194,6 +211,31 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
194 .end(end) 211 .end(end)
195} 212}
196 213
214function updateVideo (url, accessToken, id, name, description, tags, specialStatus, end) {
215 if (!end) {
216 end = specialStatus
217 specialStatus = 204
218 }
219
220 const path = '/api/v1/videos/' + id
221
222 const req = request(url)
223 .put(path)
224 .set('Accept', 'application/json')
225 .set('Authorization', 'Bearer ' + accessToken)
226
227 if (name) req.field('name', name)
228 if (description) req.field('description', description)
229
230 if (tags) {
231 for (let i = 0; i < tags.length; i++) {
232 req.field('tags[' + i + ']', tags[i])
233 }
234 }
235
236 req.expect(specialStatus).end(end)
237}
238
197// --------------------------------------------------------------------------- 239// ---------------------------------------------------------------------------
198 240
199module.exports = videosUtils 241module.exports = videosUtils