@@ -17,44 +17,6 @@ import ElasticApiParser from '../ElasticApiParser';
1717
1818const apiPartialPath = path . resolve ( __dirname , '../__mocks__/apiPartial.js' ) ;
1919
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-
5820describe ( 'ElasticApiParser' , ( ) => {
5921 let parser ;
6022
@@ -136,6 +98,24 @@ describe('ElasticApiParser', () => {
13698 } ) ;
13799 } ) ;
138100
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+
139119 describe ( 'parseParamsDescription()' , ( ) => {
140120 it ( 'should return descriptions for fields' , ( ) => {
141121 const source = ElasticApiParser . cleanUpSource (
@@ -164,7 +144,47 @@ describe('ElasticApiParser', () => {
164144
165145 describe ( 'codeToSettings()' , ( ) => {
166146 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 ( {
168188 params : {
169189 bytes : { options : [ 'b' , 'k' , 'kb' ] , type : 'enum' } ,
170190 format : { type : 'string' } ,
@@ -201,20 +221,12 @@ describe('ElasticApiParser', () => {
201221 expect ( ElasticApiParser . getMethodName ( 'api.updateByQuery' ) ) . toEqual (
202222 'updateByQuery'
203223 ) ;
204-
205- expect ( ElasticApiParser . getMethodName ( `api['delete']` ) ) . toEqual (
206- 'delete'
207- ) ;
208224 } ) ;
209225
210226 it ( 'should return array of string' , ( ) => {
211227 expect (
212228 ElasticApiParser . getMethodName ( 'api.cat.prototype.allocation' )
213229 ) . toEqual ( [ 'cat' , 'allocation' ] ) ;
214-
215- expect (
216- ElasticApiParser . getMethodName ( `api.indices.prototype['delete']` )
217- ) . toEqual ( [ 'indices' , 'delete' ] ) ;
218230 } ) ;
219231 } ) ;
220232
0 commit comments