@@ -17,44 +17,6 @@ import ElasticApiParser from '../ElasticApiParser';
17
17
18
18
const apiPartialPath = path . resolve ( __dirname , '../__mocks__/apiPartial.js' ) ;
19
19
20
- const code = `
21
- api.cat.prototype.allocation = ca({
22
- params: {
23
- format: { type: 'string' },
24
- bytes: { type: 'enum', options: ['b', 'k', 'kb'] },
25
- local: { type: 'boolean' },
26
- masterTimeout: { type: 'time', name: 'master_timeout' },
27
- h: { type: 'list' },
28
- help: { type: 'boolean', 'default': false },
29
- v: { type: 'boolean', 'default': false }
30
- },
31
- urls: [
32
- {
33
- fmt: '/_cat/allocation/<%=nodeId%>',
34
- req: { nodeId: { type: 'list' }}
35
- }, {
36
- fmt: '/_cat/allocation'
37
- }, {
38
- fmt: '/<%=index%>/<%=type%>/_update_by_query',
39
- req: {
40
- index: {
41
- type: 'list'
42
- },
43
- type: {
44
- type: 'list'
45
- }
46
- }
47
- }, {
48
- fmt: '/<%=index%>/_update_by_query',
49
- req: {
50
- index: {
51
- type: 'list'
52
- }
53
- }
54
- }
55
- ]
56
- });` ;
57
-
58
20
describe ( 'ElasticApiParser' , ( ) => {
59
21
let parser ;
60
22
@@ -136,6 +98,24 @@ describe('ElasticApiParser', () => {
136
98
} ) ;
137
99
} ) ;
138
100
101
+ describe ( 'cleanUpSource()' , ( ) => {
102
+ it ( 'should {<<api-param-type-boolean,`Boolean`>>} convert to {Boolean}' , ( ) => {
103
+ expect (
104
+ ElasticApiParser . cleanUpSource (
105
+ `@param {<<api-param-type-boolean,\`Boolean\`>>} params.analyzeWildcard`
106
+ )
107
+ ) . toEqual ( `@param {Boolean} params.analyzeWildcard` ) ;
108
+ } ) ;
109
+
110
+ it ( "should api['delete'] convert to api.delete" , ( ) => {
111
+ expect (
112
+ ElasticApiParser . cleanUpSource (
113
+ `api.indices.prototype['delete'] = ca({`
114
+ )
115
+ ) . toEqual ( `api.indices.prototype.delete = ca({` ) ;
116
+ } ) ;
117
+ } ) ;
118
+
139
119
describe ( 'parseParamsDescription()' , ( ) => {
140
120
it ( 'should return descriptions for fields' , ( ) => {
141
121
const source = ElasticApiParser . cleanUpSource (
@@ -164,7 +144,47 @@ describe('ElasticApiParser', () => {
164
144
165
145
describe ( 'codeToSettings()' , ( ) => {
166
146
it ( 'should return settings as object from ca({ settings })' , ( ) => {
167
- expect ( ElasticApiParser . codeToSettings ( code ) ) . toMatchObject ( {
147
+ expect (
148
+ ElasticApiParser . codeToSettings (
149
+ `
150
+ api.cat.prototype.allocation = ca({
151
+ params: {
152
+ format: { type: 'string' },
153
+ bytes: { type: 'enum', options: ['b', 'k', 'kb'] },
154
+ local: { type: 'boolean' },
155
+ masterTimeout: { type: 'time', name: 'master_timeout' },
156
+ h: { type: 'list' },
157
+ help: { type: 'boolean', 'default': false },
158
+ v: { type: 'boolean', 'default': false }
159
+ },
160
+ urls: [
161
+ {
162
+ fmt: '/_cat/allocation/<%=nodeId%>',
163
+ req: { nodeId: { type: 'list' }}
164
+ }, {
165
+ fmt: '/_cat/allocation'
166
+ }, {
167
+ fmt: '/<%=index%>/<%=type%>/_update_by_query',
168
+ req: {
169
+ index: {
170
+ type: 'list'
171
+ },
172
+ type: {
173
+ type: 'list'
174
+ }
175
+ }
176
+ }, {
177
+ fmt: '/<%=index%>/_update_by_query',
178
+ req: {
179
+ index: {
180
+ type: 'list'
181
+ }
182
+ }
183
+ }
184
+ ]
185
+ });`
186
+ )
187
+ ) . toMatchObject ( {
168
188
params : {
169
189
bytes : { options : [ 'b' , 'k' , 'kb' ] , type : 'enum' } ,
170
190
format : { type : 'string' } ,
@@ -201,20 +221,12 @@ describe('ElasticApiParser', () => {
201
221
expect ( ElasticApiParser . getMethodName ( 'api.updateByQuery' ) ) . toEqual (
202
222
'updateByQuery'
203
223
) ;
204
-
205
- expect ( ElasticApiParser . getMethodName ( `api['delete']` ) ) . toEqual (
206
- 'delete'
207
- ) ;
208
224
} ) ;
209
225
210
226
it ( 'should return array of string' , ( ) => {
211
227
expect (
212
228
ElasticApiParser . getMethodName ( 'api.cat.prototype.allocation' )
213
229
) . toEqual ( [ 'cat' , 'allocation' ] ) ;
214
-
215
- expect (
216
- ElasticApiParser . getMethodName ( `api.indices.prototype['delete']` )
217
- ) . toEqual ( [ 'indices' , 'delete' ] ) ;
218
230
} ) ;
219
231
} ) ;
220
232
0 commit comments