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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
import t from 'tap';
import {
compositeFrom,
exposeDependency,
input,
withPropertiesFromObject,
} from '#composite';
t.test(`withPropertiesFromObject: basic behavior`, t => {
t.plan(4);
const composite = compositeFrom({
compose: false,
steps: [
withPropertiesFromObject({
object: 'object',
properties: 'properties',
}),
exposeDependency({dependency: '#object'}),
],
});
t.match(composite, {
expose: {
dependencies: ['object', 'properties'],
},
});
t.same(
composite.expose.compute({
object: {foo: 'bar', bim: 'BOOM', bam: 'baz'},
properties: ['foo', 'bim'],
}),
{foo: 'bar', bim: 'BOOM'});
t.same(
composite.expose.compute({
object: {value1: 'uwah', value2: 'arah'},
properties: ['value1', 'value3'],
}),
{value1: 'uwah', value3: null});
t.same(
composite.expose.compute({
object: null,
properties: ['ohMe', 'ohMy', 'ohDear'],
}),
{ohMe: null, ohMy: null, ohDear: null});
});
t.test(`withPropertiesFromObject: output shapes & values`, t => {
t.plan(2 * 2 * 3 ** 2);
const dependencies = {
['object_dependency']:
{foo: 'apple', bar: 'banana', baz: 'orange'},
[input('object_neither')]:
{foo: 'koala', bar: 'okapi', baz: 'mongoose'},
['properties_dependency']:
['foo', 'bar', 'missing1'],
[input('properties_neither')]:
['foo', 'baz', 'missing3'],
};
const mapLevel1 = [
[input.value('prefix_value'), [
['object_dependency', [
['properties_dependency', {
'#object': {foo: 'apple', bar: 'banana', missing1: null},
}],
[input.value(['bar', 'baz', 'missing2']), {
'#prefix_value.bar': 'banana',
'#prefix_value.baz': 'orange',
'#prefix_value.missing2': null,
}],
[input('properties_neither'), {
'#object': {foo: 'apple', baz: 'orange', missing3: null},
}]]],
[input.value({foo: 'ouh', bar: 'rah', baz: 'nyu'}), [
['properties_dependency', {
'#object': {foo: 'ouh', bar: 'rah', missing1: null},
}],
[input.value(['bar', 'baz', 'missing2']), {
'#prefix_value.bar': 'rah',
'#prefix_value.baz': 'nyu',
'#prefix_value.missing2': null,
}],
[input('properties_neither'), {
'#object': {foo: 'ouh', baz: 'nyu', missing3: null},
}]]],
[input('object_neither'), [
['properties_dependency', {
'#object': {foo: 'koala', bar: 'okapi', missing1: null},
}],
[input.value(['bar', 'baz', 'missing2']), {
'#prefix_value.bar': 'okapi',
'#prefix_value.baz': 'mongoose',
'#prefix_value.missing2': null,
}],
[input('properties_neither'), {
'#object': {foo: 'koala', baz: 'mongoose', missing3: null},
}]]]]],
[input.value(null), [
['object_dependency', [
['properties_dependency', {
'#object': {foo: 'apple', bar: 'banana', missing1: null},
}],
[input.value(['bar', 'baz', 'missing2']), {
'#object_dependency.bar': 'banana',
'#object_dependency.baz': 'orange',
'#object_dependency.missing2': null,
}],
[input('properties_neither'), {
'#object': {foo: 'apple', baz: 'orange', missing3: null},
}]]],
[input.value({foo: 'ouh', bar: 'rah', baz: 'nyu'}), [
['properties_dependency', {
'#object': {foo: 'ouh', bar: 'rah', missing1: null},
}],
[input.value(['bar', 'baz', 'missing2']), {
'#object.bar': 'rah',
'#object.baz': 'nyu',
'#object.missing2': null,
}],
[input('properties_neither'), {
'#object': {foo: 'ouh', baz: 'nyu', missing3: null},
}]]],
[input('object_neither'), [
['properties_dependency', {
'#object': {foo: 'koala', bar: 'okapi', missing1: null},
}],
[input.value(['bar', 'baz', 'missing2']), {
'#object.bar': 'okapi',
'#object.baz': 'mongoose',
'#object.missing2': null,
}],
[input('properties_neither'), {
'#object': {foo: 'koala', baz: 'mongoose', missing3: null},
}]]]]],
];
for (const [prefixInput, mapLevel2] of mapLevel1) {
for (const [objectInput, mapLevel3] of mapLevel2) {
for (const [propertiesInput, outputDict] of mapLevel3) {
const step = withPropertiesFromObject({
prefix: prefixInput,
object: objectInput,
properties: propertiesInput,
});
quickCheckOutputs(step, outputDict);
}
}
}
function quickCheckOutputs(step, outputDict) {
t.same(
Object.keys(step.toDescription().outputs),
Object.keys(outputDict));
const composite = compositeFrom({
compose: false,
steps: [step, {
dependencies: Object.keys(outputDict),
compute: dependencies => dependencies,
}],
});
t.same(
composite.expose.compute(dependencies),
outputDict);
}
});
|