3 const fs
= require('fs')
4 const pathUtils
= require('path')
5 const request
= require('supertest')
8 getAllVideosListBy: getAllVideosListBy
,
10 getVideosList: getVideosList
,
11 getVideosListPagination: getVideosListPagination
,
12 getVideosListSort: getVideosListSort
,
13 removeVideo: removeVideo
,
14 searchVideo: searchVideo
,
15 searchVideoWithPagination: searchVideoWithPagination
,
16 searchVideoWithSort: searchVideoWithSort
,
17 testVideoImage: testVideoImage
,
18 uploadVideo: uploadVideo
21 // ---------------------- Export functions --------------------
23 function getAllVideosListBy (url
, end
) {
24 const path
= '/api/v1/videos'
28 .query({ sort: 'createdDate' })
30 .query({ count: 10000 })
31 .set('Accept', 'application/json')
33 .expect('Content-Type', /json/)
37 function getVideo (url
, id
, end
) {
38 const path
= '/api/v1/videos/' + id
42 .set('Accept', 'application/json')
44 .expect('Content-Type', /json/)
48 function getVideosList (url
, end
) {
49 const path
= '/api/v1/videos'
53 .query({ sort: 'name' })
54 .set('Accept', 'application/json')
56 .expect('Content-Type', /json/)
60 function getVideosListPagination (url
, start
, count
, end
) {
61 const path
= '/api/v1/videos'
65 .query({ start: start
})
66 .query({ count: count
})
67 .set('Accept', 'application/json')
69 .expect('Content-Type', /json/)
73 function getVideosListSort (url
, sort
, end
) {
74 const path
= '/api/v1/videos'
78 .query({ sort: sort
})
79 .set('Accept', 'application/json')
81 .expect('Content-Type', /json/)
85 function removeVideo (url
, token
, id
, expectedStatus
, end
) {
91 const path
= '/api/v1/videos'
94 .delete(path
+ '/' + id
)
95 .set('Accept', 'application/json')
96 .set('Authorization', 'Bearer ' + token
)
97 .expect(expectedStatus
)
101 function searchVideo (url
, search
, field
, end
) {
107 const path
= '/api/v1/videos'
108 const req
= request(url
)
109 .get(path
+ '/search/' + search
)
110 .set('Accept', 'application/json')
112 if (field
) req
.query({ field: field
})
114 .expect('Content-Type', /json/)
118 function searchVideoWithPagination (url
, search
, field
, start
, count
, end
) {
119 const path
= '/api/v1/videos'
122 .get(path
+ '/search/' + search
)
123 .query({ start: start
})
124 .query({ count: count
})
125 .query({ field: field
})
126 .set('Accept', 'application/json')
128 .expect('Content-Type', /json/)
132 function searchVideoWithSort (url
, search
, sort
, end
) {
133 const path
= '/api/v1/videos'
136 .get(path
+ '/search/' + search
)
137 .query({ sort: sort
})
138 .set('Accept', 'application/json')
140 .expect('Content-Type', /json/)
144 function testVideoImage (url
, videoName
, imagePath
, callback
) {
145 // Don't test images if the node env is not set
146 // Because we need a special ffmpeg version for this test
147 if (process
.env
.NODE_TEST_IMAGE
) {
151 .end(function (err
, res
) {
152 if (err
) return callback(err
)
154 fs
.readFile(pathUtils
.join(__dirname
, '..', 'api', 'fixtures', videoName
+ '.jpg'), function (err
, data
) {
155 if (err
) return callback(err
)
157 callback(null, data
.equals(res
.body
))
161 console
.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.')
166 function uploadVideo (url
, accessToken
, name
, description
, tags
, fixture
, specialStatus
, end
) {
172 const path
= '/api/v1/videos'
174 const req
= request(url
)
176 .set('Accept', 'application/json')
177 .set('Authorization', 'Bearer ' + accessToken
)
179 .field('description', description
)
181 for (let i
= 0; i
< tags
.length
; i
++) {
182 req
.field('tags[' + i
+ ']', tags
[i
])
186 if (pathUtils
.isAbsolute(fixture
)) {
189 filepath
= pathUtils
.join(__dirname
, '..', 'api', 'fixtures', fixture
)
192 req
.attach('videofile', filepath
)
193 .expect(specialStatus
)
197 // ---------------------------------------------------------------------------
199 module
.exports
= videosUtils