@@ -4,188 +4,196 @@ import yank from '../src/yank.js'
4
4
import data from './data.json'
5
5
6
6
describe ( 'src/filter' , ( ) => {
7
- describe ( 'as' , ( ) => {
8
- it ( 'should set node.key.name to the argument given' , ( ) => {
9
- const name = 'test-name'
10
- const node = {
11
- key : {
12
- name : null
7
+ describe ( 'filters' , ( ) => {
8
+ describe ( 'as' , ( ) => {
9
+ it ( 'should set node.key.name to the argument given' , ( ) => {
10
+ const name = 'test-name'
11
+ const node = {
12
+ key : {
13
+ name : null
14
+ }
13
15
}
14
- }
15
-
16
- filters . as ( {
17
- node,
18
- data,
19
- flag : null ,
20
- args : [
21
- name
22
- ]
23
- } )
24
16
25
- expect ( node . key . name ) . toEqual ( name )
26
- } )
17
+ filters . as ( {
18
+ node,
19
+ data,
20
+ flag : null ,
21
+ args : [
22
+ name
23
+ ]
24
+ } )
25
+
26
+ expect ( node . key . name ) . toEqual ( name )
27
+ } )
27
28
28
- it ( 'should rename a property after picking it from a data object' , ( ) => {
29
- const result = yank ( data , `
29
+ it ( 'should rename a property after picking it from a data object' , ( ) => {
30
+ const result = yank ( data , `
30
31
dateOfBirth | as(dob)
31
32
` )
32
33
33
- expect ( result ) . toEqual ( {
34
- dob : data . dateOfBirth
34
+ expect ( result ) . toEqual ( {
35
+ dob : data . dateOfBirth
36
+ } )
35
37
} )
36
38
} )
37
- } )
38
39
39
- describe ( 'nullable' , ( ) => {
40
- it ( 'should set node.options.nullable to true' , ( ) => {
41
- const node = {
42
- options : {
43
- nullable : false
40
+ describe ( 'nullable' , ( ) => {
41
+ it ( 'should set node.options.nullable to true' , ( ) => {
42
+ const node = {
43
+ options : {
44
+ nullable : false
45
+ }
44
46
}
45
- }
46
-
47
- filters . nullable ( {
48
- node,
49
- data,
50
- flag : {
51
- on : jest . fn ( )
52
- } ,
53
- args : [ ]
54
- } )
55
47
56
- expect ( node . options . nullable ) . toBe ( true )
57
- } )
48
+ filters . nullable ( {
49
+ node,
50
+ data,
51
+ flag : {
52
+ on : jest . fn ( )
53
+ } ,
54
+ args : [ ]
55
+ } )
58
56
59
- it ( 'MACRO flag should set all children to nullable' , ( ) => {
60
- const node = {
61
- options : {
62
- nullable : true
63
- } ,
64
- children : [
65
- {
66
- options : {
67
- nullable : false
68
- }
57
+ expect ( node . options . nullable ) . toBe ( true )
58
+ } )
59
+
60
+ it ( 'MACRO flag should set all children to nullable' , ( ) => {
61
+ const node = {
62
+ options : {
63
+ nullable : true
69
64
} ,
70
- {
71
- options : {
72
- nullable : false
65
+ children : [
66
+ {
67
+ options : {
68
+ nullable : false
69
+ }
70
+ } ,
71
+ {
72
+ options : {
73
+ nullable : false
74
+ }
73
75
}
74
- }
75
- ]
76
- }
77
-
78
- filters . nullable ( {
79
- node,
80
- data,
81
- args : [ ] ,
82
- flag : {
83
- on : ( _ , cb ) => cb ( )
76
+ ]
84
77
}
85
- } )
86
78
87
- expect ( node . options . nullable ) . toBe ( true )
88
- expect ( node . children . every ( c => c . options . nullable === true ) ) . toBe ( true )
89
- } )
79
+ filters . nullable ( {
80
+ node,
81
+ data,
82
+ args : [ ] ,
83
+ flag : {
84
+ on : ( _ , cb ) => cb ( )
85
+ }
86
+ } )
87
+
88
+ expect ( node . options . nullable ) . toBe ( true )
89
+ expect ( node . children . every ( c => c . options . nullable === true ) ) . toBe ( true )
90
+ } )
90
91
91
- it ( 'should set undefined values to null' , ( ) => {
92
- const result = yank ( data , `
92
+ it ( 'should set undefined values to null' , ( ) => {
93
+ const result = yank ( data , `
93
94
noValueHere | nullable,
94
- alsoNoValueHere
95
- ` )
95
+ alsoNoValueHere
96
+ ` )
96
97
97
- expect ( result . alsoNoValueHere ) . toBeUndefined ( )
98
- expect ( result ) . toEqual ( {
99
- noValueHere : null
98
+ expect ( result . alsoNoValueHere ) . toBeUndefined ( )
99
+ expect ( result ) . toEqual ( {
100
+ noValueHere : null
101
+ } )
100
102
} )
101
103
} )
102
- } )
103
104
104
- describe ( 'extract' , ( ) => {
105
- it ( 'should set node.options.extract to true' , ( ) => {
106
- const node = {
107
- options : {
108
- extract : false
105
+ describe ( 'extract' , ( ) => {
106
+ it ( 'should set node.options.extract to true' , ( ) => {
107
+ const node = {
108
+ options : {
109
+ extract : false
110
+ }
109
111
}
110
- }
111
112
112
- filters . extract ( {
113
- node,
114
- data,
115
- args : [ ] ,
116
- flag : null
117
- } )
113
+ filters . extract ( {
114
+ node,
115
+ data,
116
+ args : [ ] ,
117
+ flag : null
118
+ } )
118
119
119
- expect ( node . options . extract ) . toBe ( true )
120
- } )
120
+ expect ( node . options . extract ) . toBe ( true )
121
+ } )
121
122
122
- it ( 'should merge current depth of values into parent depth' , ( ) => {
123
- const result = yank ( data , `
123
+ it ( 'should merge current depth of values into parent depth' , ( ) => {
124
+ const result = yank ( data , `
124
125
addressDetails | extract: {
125
126
address1,
126
127
address2
127
128
}
128
129
` )
129
130
130
- expect ( result . addressDetails ) . toBeUndefined ( )
131
- expect ( result ) . toEqual ( {
132
- address1 : data . addressDetails . address1 ,
133
- address2 : data . addressDetails . address2
131
+ expect ( result . addressDetails ) . toBeUndefined ( )
132
+ expect ( result ) . toEqual ( {
133
+ address1 : data . addressDetails . address1 ,
134
+ address2 : data . addressDetails . address2
135
+ } )
134
136
} )
135
137
} )
136
- } )
137
138
138
- describe ( 'exec' , ( ) => {
139
- it ( 'should set node.options.exec to a method in the current depth' , ( ) => {
140
- const value = 'test-value'
141
- const arg = 'test-arg'
142
- const args = [
143
- 'arg1' ,
144
- 'arg2'
145
- ]
146
- const dataWithFn = {
147
- ...data ,
148
- testFn : jest . fn ( ) . mockReturnValue ( value )
149
- }
150
- const node = {
151
- options : {
152
- exec : null
153
- }
154
- }
155
-
156
- filters . exec ( {
157
- node,
158
- data : dataWithFn ,
159
- flag : null ,
160
- args : [
161
- 'testFn' ,
162
- ...args
139
+ describe ( 'exec' , ( ) => {
140
+ it ( 'should set node.options.exec to a method in the current depth' , ( ) => {
141
+ const value = 'test-value'
142
+ const arg = 'test-arg'
143
+ const args = [
144
+ 'arg1' ,
145
+ 'arg2'
163
146
]
164
- } )
147
+ const dataWithFn = {
148
+ ...data ,
149
+ testFn : jest . fn ( ) . mockReturnValue ( value )
150
+ }
151
+ const node = {
152
+ options : {
153
+ exec : null
154
+ }
155
+ }
165
156
166
- const result = node . options . exec ( arg )
157
+ filters . exec ( {
158
+ node,
159
+ data : dataWithFn ,
160
+ flag : null ,
161
+ args : [
162
+ 'testFn' ,
163
+ ...args
164
+ ]
165
+ } )
167
166
168
- expect ( dataWithFn . testFn ) . toBeCalledWith ( arg , ...args )
169
- expect ( result ) . toEqual ( value )
170
- } )
167
+ const result = node . options . exec ( arg )
168
+
169
+ expect ( dataWithFn . testFn ) . toBeCalledWith ( arg , ...args )
170
+ expect ( result ) . toEqual ( value )
171
+ } )
171
172
172
- it ( 'should execute a method in the current depth with the picked value' , ( ) => {
173
- const value = 'test-value'
174
- const arg = 'foo'
175
- const dataWithFn = {
176
- ...data ,
177
- testFn : jest
178
- . fn ( )
179
- . mockReturnValue ( value )
180
- }
181
- const result = yank ( dataWithFn , `
173
+ it ( 'should execute a method in the current depth with the picked value' , ( ) => {
174
+ const value = 'test-value'
175
+ const arg = 'foo'
176
+ const dataWithFn = {
177
+ ...data ,
178
+ testFn : jest
179
+ . fn ( )
180
+ . mockReturnValue ( value )
181
+ }
182
+ const result = yank ( dataWithFn , `
182
183
firstName | exec(testFn, ${ arg } )
183
184
` )
184
185
185
- expect ( dataWithFn . testFn ) . toBeCalledWith ( data . firstName , arg )
186
- expect ( result ) . toEqual ( {
187
- firstName : value
186
+ expect ( dataWithFn . testFn ) . toBeCalledWith ( data . firstName , arg )
187
+ expect ( result ) . toEqual ( {
188
+ firstName : value
189
+ } )
188
190
} )
189
191
} )
190
192
} )
193
+
194
+ describe ( 'Filter' , ( ) => {
195
+ describe ( 'filter' , ( ) => {
196
+ // @TODO
197
+ } )
198
+ } )
191
199
} )
0 commit comments