@@ -2,6 +2,7 @@ import { binding, after, then, when, given } from "cucumber-tsflow";
22import { assert , expect } from "chai" ;
33import { RequestParameters } from "../../template/request" ;
44import { BaseModelStep } from "./base" ;
5+ import fs = require( "fs" ) ;
56
67const isJson = ( str : string ) : boolean => {
78 try {
@@ -12,6 +13,10 @@ const isJson = (str: string): boolean => {
1213 return true ;
1314} ;
1415
16+ const getTagFileName = ( tag : string ) : string => {
17+ return tag === "" ? "" : tag . charAt ( 0 ) . toUpperCase ( ) + tag . slice ( 1 ) ;
18+ } ;
19+
1520@binding ( )
1621export class ModelSteps extends BaseModelStep {
1722 private requestParams : RequestParameters ;
@@ -21,17 +26,21 @@ export class ModelSteps extends BaseModelStep {
2126 private request : any ;
2227
2328 createApi ( serverIndex = 0 ) : any {
24- const apiModule = require ( "../api/api.ts" ) ;
25- const configurationModule = require ( "../api/configuration.ts" ) ;
26- const mockTransport = async ( params : RequestParameters ) => {
27- this . requestParams = params ;
28- return this . serverResponseObject ;
29- } ;
30-
31- const config = new configurationModule . default ( mockTransport ) ;
32- config . selectedServerIndex = serverIndex ;
33-
34- return new apiModule . default ( config ) ;
29+ try {
30+ const apiModule = require ( "../api/api.ts" ) ;
31+ const configurationModule = require ( "../api/configuration.ts" ) ;
32+ const mockTransport = async ( params : RequestParameters ) => {
33+ this . requestParams = params ;
34+ return this . serverResponseObject ;
35+ } ;
36+
37+ const config = new configurationModule . default ( mockTransport ) ;
38+ config . selectedServerIndex = serverIndex ;
39+
40+ return new apiModule . default ( config ) ;
41+ } catch {
42+ return null ;
43+ }
3544 }
3645
3746 @after ( )
@@ -159,4 +168,36 @@ export class ModelSteps extends BaseModelStep {
159168 public checkMethodType ( value : string ) {
160169 assert . equal ( this . requestParams . method , value ) ;
161170 }
171+
172+ @then ( / t h e a p i f i l e w i t h t a g " ( .* ) " e x i s t s / )
173+ public checkFileExists ( tag : string ) {
174+ fs . existsSync ( `../api/api${ getTagFileName ( tag ) } .ts` ) ;
175+ }
176+
177+ @then ( / t h e a p i f i l e w i t h t a g " ( .* ) " d o e s n o t e x i s t / )
178+ public checkFileDoesNotExist ( tag : string ) {
179+ ! fs . existsSync ( `../api/api${ getTagFileName ( tag ) } .ts` ) ;
180+ }
181+
182+ @then ( / t h e m e t h o d " ( .* ) " s h o u l d b e p r e s e n t i n t h e a p i f i l e w i t h t a g " ( .* ) " / )
183+ public checkMethodExists ( methodName : string , tag : string ) {
184+ fs . existsSync ( `../api/api${ getTagFileName ( tag ) } .ts` ) ;
185+ const apiFile = require ( `../api/api${ tag } .ts` ) ;
186+
187+ const module = new apiFile . default ( ) ;
188+
189+ expect ( module [ methodName ] ) . to . exist ;
190+ }
191+
192+ @then (
193+ / t h e m e t h o d " ( .* ) " s h o u l d n o t b e p r e s e n t i n t h e a p i f i l e w i t h t a g " ( .* ) " /
194+ )
195+ public checkMethodDoesNotExist ( methodName : string , tag : string ) {
196+ fs . existsSync ( `../api/api${ getTagFileName ( tag ) } .ts` ) ;
197+ const apiFile = require ( `../api/api${ tag } .ts` ) ;
198+
199+ const module = new apiFile . default ( ) ;
200+
201+ expect ( module [ methodName ] ) . to . not . exist ;
202+ }
162203}
0 commit comments