+function testImage (url, videoName, imagePath, callback) {
+ // Don't test images if the node env is not set
+ // Because we need a special ffmpeg version for this test
+ if (process.env.NODE_TEST_IMAGE) {
+ request(url)
+ .get(imagePath)
+ .expect(200)
+ .end(function (err, res) {
+ if (err) return callback(err)
+
+ fs.readFile(pathUtils.join(__dirname, 'fixtures', videoName + '.jpg'), function (err, data) {
+ if (err) return callback(err)
+
+ callback(null, data.equals(res.body))
+ })
+ })
+ } else {
+ console.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.')
+ callback(null, true)
+ }
+}
+
+function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) {
+ if (!end) {
+ end = specialStatus
+ specialStatus = 204
+ }
+
+ const path = '/api/v1/videos'
+
+ const req = request(url)
+ .post(path)
+ .set('Accept', 'application/json')
+ .set('Authorization', 'Bearer ' + accessToken)
+ .field('name', name)
+ .field('description', description)
+
+ for (let i = 0; i < tags.length; i++) {
+ req.field('tags[' + i + ']', tags[i])
+ }
+
+ let filepath = ''
+ if (pathUtils.isAbsolute(fixture)) {
+ filepath = fixture
+ } else {
+ filepath = pathUtils.join(__dirname, 'fixtures', fixture)
+ }
+
+ req.attach('videofile', filepath)
+ .expect(specialStatus)
+ .end(end)
+}
+