@@ -12,7 +12,9 @@ var expect = require('chai').expect,
1212 convert,
1313 getSnippetFooter,
1414 getSnippetRequestObject,
15- groupHeadersSameKey
15+ groupHeadersSameKey,
16+ getSnippetBoilerplate,
17+ getIncludeBoilerplate
1618 } = require ( '../../lib/phpGuzzle' ) ,
1719 collectionsPath = './fixtures' ;
1820
@@ -21,7 +23,7 @@ describe('convert function', function () {
2123 it ( 'should convert a simple get request' , function ( done ) {
2224 const collection = new sdk . Collection ( JSON . parse (
2325 fs . readFileSync ( path . resolve ( __dirname , collectionsPath , './sample_collection.json' ) . toString ( ) ) ) ) ;
24- convert ( collection . items . members [ 0 ] . request , { } , function ( err , snippet ) {
26+ convert ( collection . items . members [ 0 ] . request , { includeBoilerplate : true } , function ( err , snippet ) {
2527 if ( err ) {
2628 console . error ( err ) ;
2729 }
@@ -34,6 +36,19 @@ describe('convert function', function () {
3436 expect ( function ( ) { convert ( { } , { } ) ; } )
3537 . to . throw ( 'Php-Guzzle~convert: Callback is not a function' ) ;
3638 } ) ;
39+
40+ it ( 'should convert a simple get request without boilerplate' , function ( done ) {
41+ const collection = new sdk . Collection ( JSON . parse (
42+ fs . readFileSync ( path . resolve ( __dirname , collectionsPath , './sample_collection.json' ) . toString ( ) ) ) ) ;
43+ convert ( collection . items . members [ 0 ] . request , { includeBoilerplate : false } , function ( err , snippet ) {
44+ if ( err ) {
45+ console . error ( err ) ;
46+ }
47+ expect ( snippet ) . to . not . be . empty ;
48+ expect ( snippet ) . to . not . include ( 'use' ) ;
49+ } ) ;
50+ done ( ) ;
51+ } ) ;
3752} ) ;
3853
3954describe ( 'getHeaders function' , function ( ) {
@@ -250,3 +265,59 @@ describe('groupHeadersSameKey method', function () {
250265 expect ( result [ 0 ] . key ) . to . equal ( 'key1' ) ;
251266 } ) ;
252267} ) ;
268+
269+ describe ( 'getSnippetBoilerplate method' , function ( ) {
270+ it ( 'should the boilerplate with include option in true"' , function ( ) {
271+ const expected = '<?php\n' +
272+ '$composerHome = substr(shell_exec(\'composer config home -g\'), 0, -1).\'/vendor/autoload.php\';\n' +
273+ 'require $composerHome; // your path to autoload.php \n' +
274+ 'use Psr\\Http\\Message\\ResponseInterface;\n' +
275+ 'use GuzzleHttp\\Exception\\RequestException;\n' +
276+ 'use GuzzleHttp\\Client;\n' +
277+ 'use GuzzleHttp\\Psr7\\Utils;\n' +
278+ 'use GuzzleHttp\\Psr7\\Request;\n' ,
279+ result = getSnippetBoilerplate ( true ) ;
280+ expect ( result ) . to . equal ( expected ) ;
281+ } ) ;
282+
283+ it ( 'should return empty string for include option in false' , function ( ) {
284+ const expected = '' ,
285+ result = getSnippetBoilerplate ( false ) ;
286+ expect ( result ) . to . equal ( expected ) ;
287+ } ) ;
288+ } ) ;
289+
290+ describe ( 'getIncludeBoilerplate method' , function ( ) {
291+ it ( 'should return false with empty options' , function ( ) {
292+ const result = getIncludeBoilerplate ( { } ) ;
293+ expect ( result ) . to . be . false ;
294+ } ) ;
295+ it ( 'should return false with undefined options' , function ( ) {
296+ const result = getIncludeBoilerplate ( ) ;
297+ expect ( result ) . to . be . false ;
298+ } ) ;
299+ it ( 'should return false with null options' , function ( ) {
300+ const result = getIncludeBoilerplate ( null ) ;
301+ expect ( result ) . to . be . false ;
302+ } ) ;
303+ it ( 'should return false with options and include option not present' , function ( ) {
304+ const result = getIncludeBoilerplate ( { asyncType : 'sync' } ) ;
305+ expect ( result ) . to . be . false ;
306+ } ) ;
307+ it ( 'should return false with options and include option present with value of false' , function ( ) {
308+ const result = getIncludeBoilerplate ( { includeBoilerplate : false } ) ;
309+ expect ( result ) . to . be . false ;
310+ } ) ;
311+ it ( 'should return false with options and include option present with value of false' , function ( ) {
312+ const result = getIncludeBoilerplate ( { includeBoilerplate : true } ) ;
313+ expect ( result ) . to . be . true ;
314+ } ) ;
315+ it ( 'should return false with options and include option present with value of false' , function ( ) {
316+ const result = getIncludeBoilerplate ( { includeBoilerplate : undefined } ) ;
317+ expect ( result ) . to . be . false ;
318+ } ) ;
319+ it ( 'should return false with options and include option present with value of false' , function ( ) {
320+ const result = getIncludeBoilerplate ( { includeBoilerplate : null } ) ;
321+ expect ( result ) . to . be . false ;
322+ } ) ;
323+ } ) ;
0 commit comments