@@ -3,19 +3,126 @@ var expect = require('chai').expect,
33 sdk = require ( 'postman-collection' ) ,
44 fs = require ( 'fs' ) ,
55 path = require ( 'path' ) ;
6- // collectionsPath = './fixtures';
76
87describe ( 'convert function' , function ( ) {
8+ const collection = new sdk . Collection ( JSON . parse (
9+ fs . readFileSync ( path . resolve ( __dirname , './fixtures/sample_collection.json' ) . toString ( ) ) ) ) ;
910
10- it ( 'should convert a simple get request' , function ( done ) {
11- const collection = new sdk . Collection ( JSON . parse (
12- fs . readFileSync ( path . resolve ( __dirname , './fixtures/sample_collection.json' ) . toString ( ) ) ) ) ;
11+ it ( 'should convert requests with asyncType option as async' , function ( done ) {
12+ collection . items . members . forEach ( ( item ) => {
13+ convert ( item . request , { asyncType : 'async' } , function ( err , snippet ) {
14+ if ( err ) {
15+ console . error ( err ) ;
16+ }
17+ expect ( snippet ) . to . not . be . empty ;
18+ expect ( snippet ) . to . include ( '$client->sendAsync(' ) ;
19+ } ) ;
20+ } ) ;
21+ done ( ) ;
22+ } ) ;
23+
24+ it ( 'should convert requests with asyncType option not present' , function ( done ) {
25+ collection . items . members . forEach ( ( item ) => {
26+ convert ( item . request , { } , function ( err , snippet ) {
27+ if ( err ) {
28+ console . error ( err ) ;
29+ }
30+ expect ( snippet ) . to . not . be . empty ;
31+ expect ( snippet ) . to . include ( '$client->sendAsync(' ) ;
32+ } ) ;
33+ } ) ;
34+ done ( ) ;
35+ } ) ;
36+
37+ it ( 'should convert requests with sync option as sync' , function ( done ) {
1338 collection . items . members . forEach ( ( item ) => {
1439 convert ( item . request , { asyncType : 'sync' } , function ( err , snippet ) {
1540 if ( err ) {
1641 console . error ( err ) ;
1742 }
1843 expect ( snippet ) . to . not . be . empty ;
44+ expect ( snippet ) . to . include ( '$client->send(' ) ;
45+ } ) ;
46+ } ) ;
47+ done ( ) ;
48+ } ) ;
49+
50+ it ( 'should convert requests with includeBoilerplate option as true' , function ( done ) {
51+ collection . items . members . forEach ( ( item ) => {
52+ convert ( item . request , { includeBoilerplate : true } , function ( err , snippet ) {
53+ if ( err ) {
54+ console . error ( err ) ;
55+ }
56+ expect ( snippet ) . to . not . be . empty ;
57+ expect ( snippet ) . to . include ( '<?php\n' +
58+ '$composerHome = substr(shell_exec(\'composer config home -g\'), 0, -1).\'/vendor/autoload.php\';\n' ) ;
59+ } ) ;
60+ } ) ;
61+ done ( ) ;
62+ } ) ;
63+
64+ it ( 'should convert requests with includeBoilerplate option not present' , function ( done ) {
65+ collection . items . members . forEach ( ( item ) => {
66+ convert ( item . request , { } , function ( err , snippet ) {
67+ if ( err ) {
68+ console . error ( err ) ;
69+ }
70+ expect ( snippet ) . to . not . be . empty ;
71+ expect ( snippet ) . to . not . include ( '<?php\n' +
72+ '$composerHome = substr(shell_exec(\'composer config home -g\'), 0, -1).\'/vendor/autoload.php\';\n' ) ;
73+ } ) ;
74+ } ) ;
75+ done ( ) ;
76+ } ) ;
77+
78+ it ( 'should convert requests with includeBoilerplate option as false' , function ( done ) {
79+ collection . items . members . forEach ( ( item ) => {
80+ convert ( item . request , { includeBoilerplate : false } , function ( err , snippet ) {
81+ if ( err ) {
82+ console . error ( err ) ;
83+ }
84+ expect ( snippet ) . to . not . be . empty ;
85+ expect ( snippet ) . to . not . include ( '<?php\n' +
86+ '$composerHome = substr(shell_exec(\'composer config home -g\'), 0, -1).\'/vendor/autoload.php\';\n' ) ;
87+ } ) ;
88+ } ) ;
89+ done ( ) ;
90+ } ) ;
91+
92+ it ( 'should convert requests with followRedirect option not present' , function ( done ) {
93+ collection . items . members . forEach ( ( item ) => {
94+ convert ( item . request , { } , function ( err , snippet ) {
95+ if ( err ) {
96+ console . error ( err ) ;
97+ }
98+ expect ( snippet ) . to . not . be . empty ;
99+ expect ( snippet ) . to . not . include ( '\'allow_redirects\' => false' ) ;
100+ } ) ;
101+ } ) ;
102+ done ( ) ;
103+ } ) ;
104+
105+ it ( 'should convert requests with followRedirect option as true' , function ( done ) {
106+ collection . items . members . forEach ( ( item ) => {
107+ convert ( item . request , { followRedirect : true } , function ( err , snippet ) {
108+ if ( err ) {
109+ console . error ( err ) ;
110+ }
111+ expect ( snippet ) . to . not . be . empty ;
112+ expect ( snippet ) . to . not . include ( '\'allow_redirects\' => false' ) ;
113+ } ) ;
114+ } ) ;
115+ done ( ) ;
116+ } ) ;
117+
118+ it ( 'should convert requests with followRedirect option as false' , function ( done ) {
119+ collection . items . members . forEach ( ( item ) => {
120+ convert ( item . request , { followRedirect : false } , function ( err , snippet ) {
121+ if ( err ) {
122+ console . error ( err ) ;
123+ }
124+ expect ( snippet ) . to . not . be . empty ;
125+ expect ( snippet ) . to . include ( '\'allow_redirects\' => false' ) ;
19126 } ) ;
20127 } ) ;
21128 done ( ) ;
@@ -25,4 +132,44 @@ describe('convert function', function () {
25132 expect ( function ( ) { convert ( { } , { } ) ; } )
26133 . to . throw ( 'Php-Guzzle~convert: Callback is not a function' ) ;
27134 } ) ;
135+
136+ it ( 'should convert requests with requestTimeout option set as 500' , function ( done ) {
137+ collection . items . members . forEach ( ( item ) => {
138+ convert ( item . request , { requestTimeout : 500 } , function ( err , snippet ) {
139+ if ( err ) {
140+ console . error ( err ) ;
141+ }
142+ expect ( snippet ) . to . not . be . empty ;
143+ expect ( snippet ) . to . include ( '\'timeout\' => 500' ) ;
144+ } ) ;
145+ } ) ;
146+ done ( ) ;
147+ } ) ;
148+
149+ it ( 'should convert requests with requestTimeout option not present' , function ( done ) {
150+ collection . items . members . forEach ( ( item ) => {
151+ convert ( item . request , { requestTimeout : 0 } , function ( err , snippet ) {
152+ if ( err ) {
153+ console . error ( err ) ;
154+ }
155+ expect ( snippet ) . to . not . be . empty ;
156+ expect ( snippet ) . to . not . include ( '\'timeout\'' ) ;
157+ } ) ;
158+ } ) ;
159+ done ( ) ;
160+ } ) ;
161+
162+ it ( 'should convert requests with requestTimeout option set as 0' , function ( done ) {
163+ collection . items . members . forEach ( ( item ) => {
164+ convert ( item . request , { requestTimeout : 0 } , function ( err , snippet ) {
165+ if ( err ) {
166+ console . error ( err ) ;
167+ }
168+ expect ( snippet ) . to . not . be . empty ;
169+ expect ( snippet ) . to . not . include ( '\'timeout\' => 0' ) ;
170+ } ) ;
171+ } ) ;
172+ done ( ) ;
173+ } ) ;
174+
28175} ) ;
0 commit comments