-
Notifications
You must be signed in to change notification settings - Fork 17
/
coconut.test.js
117 lines (97 loc) · 3.29 KB
/
coconut.test.js
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
const Coconut = require('./coconut');
const assert = require('assert').strict;
const INPUT_URL = "https://s3-eu-west-1.amazonaws.com/files.coconut.co/bbb_800k.mp4";
const STORAGE = {
"service": "s3",
"bucket": process.env.AWS_BUCKET,
"region": process.env.AWS_REGION,
"path": "/coconutjs/tests/",
"credentials": {
"access_key_id": process.env.AWS_ACCESS_KEY_ID,
"secret_access_key": process.env.AWS_SECRET_ACCESS_KEY
}
}
const NOTIFICATION = {
"type": "http",
"url": process.env.COCONUT_WEBHOOK_URL
}
describe("New Coconut Client", function() {
it("should instantiate new client with API Key", function() {
const coconut = new Coconut.Client(process.env.COCONUT_API_KEY);
assert.strictEqual(coconut.api_key, process.env.COCONUT_API_KEY);
});
it("should set the default api endpoint if no region or endpoint provided", function() {
const coconut = new Coconut.Client(process.env.COCONUT_API_KEY);
assert.strictEqual(coconut.getEndpoint(), "https://api.coconut.co/v2");
});
it("should update the api endpoint if region is provided", function() {
const coconut = new Coconut.Client(process.env.COCONUT_API_KEY, {region: "us-west-2"});
assert.strictEqual(coconut.getEndpoint(), "https://api-us-west-2.coconut.co/v2");
});
it("should override the api endpoint if endpoint is provided", function() {
const coconut = new Coconut.Client(process.env.COCONUT_API_KEY, {endpoint: "http://localhost:3001/v2"});
assert.strictEqual(coconut.getEndpoint(), "http://localhost:3001/v2");
});
});
describe("Job creation", function() {
it("should create a job", function() {
const coconut = new Coconut.Client(process.env.COCONUT_API_KEY);
coconut.notification = NOTIFICATION
coconut.storage = STORAGE
coconut.Job.create({
"input": {"url": INPUT_URL},
"outputs": {
"mp4": {
"path": "/video.mp4",
"duration": 1
}
}
}, function(job, err) {
if(job) {
assert.strictEqual(null, err);
assert.strictEqual(job.status, "job.starting");
}
});
});
it("should create a job with promise", function() {
const coconut = new Coconut.Client(process.env.COCONUT_API_KEY);
coconut.notification = NOTIFICATION
coconut.storage = STORAGE
const promise = coconut.Job.create({
"input": {"url": INPUT_URL},
"outputs": {
"mp4": {
"path": "/video.mp4",
"duration": 1
}
}
});
promise.then(function(job) {
if(job) {
assert.strictEqual(null, err);
assert.strictEqual(job.status, "job.starting");
}
});
});
it("should not create a job because of error", function() {
const coconut = new Coconut.Client(process.env.COCONUT_API_KEY);
coconut.notification = NOTIFICATION
coconut.storage = STORAGE
coconut.Job.create({
"input": {"url": INPUT_URL},
"outputs": {
"mp4": {
"path": "/video.mp4",
"notvalidparam": "no",
}
}
}, function(job, err) {
assert.strictEqual(null, job);
assert.strictEqual(err.error_code, "output_param_not_valid");
});
});
it("should not blow up when job ID is empty", function() {
const coconut = new Coconut.Client(process.env.COCONUT_API_KEY);
coconut.Job.retrieve()
});
});