-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevaluate.spec.js
More file actions
81 lines (69 loc) · 2.05 KB
/
evaluate.spec.js
File metadata and controls
81 lines (69 loc) · 2.05 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
'use strict';
var JSONScript = require('../lib/jsonscript');
var assert = require('assert');
var testutil = require('./testutil');
var getPromise = testutil.getPromise;
var shouldBeError = testutil.shouldBeError;
var executors = require('./executors');
describe('script evaluation', function() {
var js, callsResolutions;
before(function() {
js = new JSONScript;
js.addExecutor('router1', executors.router1);
});
beforeEach(function(){
callsResolutions = getPromise.callsResolutions = [];
});
it('should evaluate parallel execution', function() {
var script = {
a: {
$exec: 'router1',
$method: 'get',
$args: { path: '/resource' }
},
b: {
$exec: 'router1',
$method: 'post',
$args: { path: '/resource', body: { test: 'test' } }
}
};
return js.evaluate(script).then(function (res) {
assert.deepEqual(res, {
a: 'you requested /resource from router1',
b: 'you posted {"test":"test"} to router1 /resource'
});
assert.deepEqual(callsResolutions, [
{ call: 'get: /resource' },
{ call: 'post: /resource' },
{ res: 'you requested /resource from router1' },
{ res: 'you posted {"test":"test"} to router1 /resource' }
]);
});
});
it('should evaluate sequential execution', function() {
var script = [
{
$exec: 'router1',
$method: 'get',
$args: { path: '/resource' }
},
{
$exec: 'router1',
$method: 'post',
$args: { path: '/resource', body: { test: 'test' } }
}
];
return js.evaluate(script).then(function (res) {
assert.deepEqual(res, [
'you requested /resource from router1',
'you posted {"test":"test"} to router1 /resource'
]);
assert.deepEqual(callsResolutions, [
{ call: 'get: /resource' },
{ res: 'you requested /resource from router1' },
{ call: 'post: /resource' },
{ res: 'you posted {"test":"test"} to router1 /resource' }
]);
});
});
});