@@ -88,6 +88,91 @@ test.serial('sets the exit code to 1', async (t) => {
8888 process . exitCode = origExitCode ;
8989} ) ;
9090
91+ test . serial (
92+ 'redirects to beta handler when openfn.yaml exists in cwd' ,
93+ async ( t ) => {
94+ t . plan ( 3 ) ;
95+ mockfs ( {
96+ [ './config.json' ] : `{"apiKey": "123"}` ,
97+ [ './project.yaml' ] : `{"apiKey": "123"}` ,
98+ [ './openfn.yaml' ] : 'project:\n endpoint: https://from-yaml.org' ,
99+ } ) ;
100+
101+ await deployHandler ( options , logger , mockDeploy , async ( args : any ) => {
102+ t . is ( args . force , true ) ;
103+ t . is ( args . endpoint , 'https://from-yaml.org' ) ;
104+ t . truthy ( logger . _find ( 'always' , / D e t e c t e d o p e n f n .y a m l f i l e / i) ) ;
105+ } ) ;
106+ }
107+ ) ;
108+
109+ test . serial ( 'does not redirect when PREFER_LEGACY_SYNC is set' , async ( t ) => {
110+ t . plan ( 1 ) ;
111+ mockfs ( {
112+ [ './config.json' ] : `{"apiKey": "123", "endpoint": "https://api.example.com"}` ,
113+ [ './project.yaml' ] : `{"apiKey": "123"}` ,
114+ [ './openfn.yaml' ] : 'project:\n endpoint: https://from-yaml.org' ,
115+ } ) ;
116+ process . env . PREFER_LEGACY_SYNC = '1' ;
117+
118+ await deployHandler ( options , logger , mockDeploy , async ( args : any ) => {
119+ t . fail ( 'called beta handler' ) ;
120+ } ) ;
121+
122+ delete process . env . PREFER_LEGACY_SYNC ;
123+ t . pass ( ) ;
124+ } ) ;
125+
126+ test . serial ( 'CLI endpoint preferred over openfn.yaml endpoint' , async ( t ) => {
127+ t . plan ( 1 ) ;
128+ mockfs ( {
129+ [ './config.json' ] : `{"apiKey": "123"}` ,
130+ [ './project.yaml' ] : `{"apiKey": "123"}` ,
131+ [ './openfn.yaml' ] : 'project:\n endpoint: https://from-yaml.org' ,
132+ } ) ;
133+
134+ await deployHandler (
135+ { ...options , endpoint : 'https://from-cli.org' } as any ,
136+ logger ,
137+ mockDeploy ,
138+ async ( args : any ) => {
139+ t . is ( args . endpoint , 'https://from-cli.org' ) ;
140+ }
141+ ) ;
142+ } ) ;
143+
144+ test . serial (
145+ 'openfn.yaml endpoint preferred over config.json endpoint' ,
146+ async ( t ) => {
147+ mockfs ( {
148+ [ './config.json' ] : `{"apiKey": "123", "endpoint": "https://from-config.org"}` ,
149+ [ './project.yaml' ] : `{"apiKey": "123"}` ,
150+ [ './openfn.yaml' ] : 'project:\n endpoint: https://from-yaml.org' ,
151+ } ) ;
152+
153+ await deployHandler ( options , logger , mockDeploy , async ( args : any ) => {
154+ t . is ( args . endpoint , 'https://from-yaml.org' ) ;
155+ } ) ;
156+ }
157+ ) ;
158+
159+ test . serial ( 'CLI apiKey preferred over config.json apiKey' , async ( t ) => {
160+ mockfs ( {
161+ [ './config.json' ] : `{"apiKey": "from-config"}` ,
162+ [ './project.yaml' ] : `{"apiKey": "from-config"}` ,
163+ [ './openfn.yaml' ] : 'project:\n endpoint: https://from-yaml.org' ,
164+ } ) ;
165+
166+ await deployHandler (
167+ { ...options , apiKey : 'from-cli' } as any ,
168+ logger ,
169+ mockDeploy ,
170+ async ( args : any ) => {
171+ t . is ( args . apiKey , 'from-cli' ) ;
172+ }
173+ ) ;
174+ } ) ;
175+
91176test . serial ( 'catches DeployErrors' , async ( t ) => {
92177 const origExitCode = process . exitCode ;
93178
0 commit comments