-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck-runtime.js
61 lines (49 loc) · 1.81 KB
/
check-runtime.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
var process = require('process');
var Craftgate = require('@craftgate/craftgate');
var craftgate = new Craftgate.Client({
apiKey: 'sandbox-YEhueLgomBjqsnvBlWVVuFsVhlvJlMHE',
secretKey: 'sandbox-tBdcdKVGmGupzfaWcULcwDLMoglZZvTz',
baseUrl: 'https://sandbox-api.craftgate.io'
});
function assert(expr, message) {
if (!expr) {
console.error('Check failed', message);
return process.exit(1);
}
console.info('Check OK', message);
}
function assertAsync(fn, message) {
try {
fn(function (err, result) {
if (err) {
console.error('Async check failed', message, err);
return process.exit(2);
}
console.info('Async check OK', message, result);
});
} catch (err) {
console.error('Async check failed before being executed', message, err);
process.exit(3)
}
}
function isConstructor(fn) {
return fn && (typeof fn === 'function') && fn.prototype && (fn.prototype.constructor === fn);
}
function testSearch(callback) {
craftgate.onboarding()
.searchMembers({isBuyer: false, isSubMerchant: true})
.then(function (results) {
callback(null, {success: true, totalSize: results.totalSize});
})
.catch(function (err) {
callback(err);
});
}
assert(!!Craftgate, 'Craftgate must not be false');
assert(isConstructor(Craftgate.Client), 'Craftgate.Client must be a constructor');
assert(!!Craftgate.Model, 'Craftgate.Model must not be false')
assert(Object.keys(Craftgate.Model).length > 0, 'Craftgate.Model must not be empty');
assert(!!Craftgate.Adapter, 'Craftgate.Adapter must not be false')
assert(Object.keys(Craftgate.Adapter).length > 0, 'Craftgate.Adapter must not be empty');
assert(!!Craftgate.CraftgateError, 'Craftgate.CraftgateError must not be false');
assert(isConstructor(Craftgate.Client), 'Craftgate.CraftgateError must be a constructor');