This repository was archived by the owner on Mar 20, 2023. It is now read-only.
forked from opencoconut/coconutjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
117 lines (101 loc) · 3.26 KB
/
test.js
File metadata and controls
117 lines (101 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var coconut = require('./coconut');
var fs = require('fs');
exports.testSubmitConfig = function(test) {
conf = coconut.config({
'source': 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
'webhook': 'http://mysite.com/webhook',
'outputs': {'mp4': 's3://a:s@bucket/video.mp4'}
});
coconut.submit(conf, null, function(job) {
test.notEqual(undefined, job);
test.equal('ok', job.status);
test.ok(job.id > 0);
test.done();
});
};
exports.testSubmitBadConfig = function(test) {
conf = coconut.config({
'source': 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4'
});
coconut.submit(conf, null, function(job) {
test.notEqual(undefined, job);
test.equal('error', job.status);
test.equal('config_not_valid', job.error_code);
test.done();
});
};
exports.testSubmitConfigWithAPIKey = function(test) {
conf = coconut.config({
'source': 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4'
});
coconut.submit(conf, 'k-4d204a7fd1fc67fc00e87d3c326d9b75', function(job) {
test.notEqual(undefined, job);
test.equal('error', job.status);
test.equal('authentication_failed', job.error_code);
test.done();
});
};
exports.testGenerateFullConfigWithNoFile = function(test) {
conf = coconut.config({
'vars': {
'vid': 1234,
'user': 5098,
's3': 's3://a:s@bucket'
},
'source': 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
'webhook': 'http://mysite.com/webhook?vid=$vid&user=$user',
'outputs': {
'mp4': '$s3/vid.mp4',
'webm': '$s3/vid.webm',
'jpg_200x': '$s3/thumb.jpg'
}
});
generated = [
'var s3 = s3://a:s@bucket',
'var user = 5098',
'var vid = 1234',
'',
'set source = https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
'set webhook = http://mysite.com/webhook?vid=$vid&user=$user',
'',
'-> jpg_200x = $s3/thumb.jpg',
'-> mp4 = $s3/vid.mp4',
'-> webm = $s3/vid.webm'
].join("\n")
test.equal(generated, conf);
test.done();
}
exports.testGenerateConfigWithFile = function(test) {
fs.writeFileSync('coconut.conf', "var s3 = s3://a:s@bucket/video\nset webhook = http://mysite.com/webhook?vid=$vid&user=$user\n-> mp4 = $s3/$vid.mp4");
conf = coconut.config({
'conf': 'coconut.conf',
'source': 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
'vars': {'vid': 1234, 'user': 5098}
});
generated = [
'var s3 = s3://a:s@bucket/video',
'var user = 5098',
'var vid = 1234',
'',
'set source = https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
'set webhook = http://mysite.com/webhook?vid=$vid&user=$user',
'',
'-> mp4 = $s3/$vid.mp4'
].join("\n")
test.equal(generated, conf);
fs.unlink('coconut.conf');
test.done();
}
exports.testSubmitFile = function(test) {
fs.writeFileSync('coconut.conf', "set webhook = http://mysite.com/webhook?vid=$vid&user=$user\n-> mp4 = s3://a:s@bucket/video/$vid.mp4");
coconut.createJob({
'conf': 'coconut.conf',
'source': 'https://s3-eu-west-1.amazonaws.com/files.coconut.co/test.mp4',
'vars': {'vid': 1234, 'user': 5098}
}, function(job) {
test.equal('ok', job.status);
test.ok(job.id > 0);
fs.unlink('coconut.conf');
test.done();
});
}