@@ -145,3 +145,122 @@ describe('hlx publish --remote (with filters)', () => {
145145 await fse . remove ( testRoot ) ;
146146 } ) ;
147147} ) ;
148+
149+ describe ( 'hlx publish --remote (with filters, but without config)' , ( ) => {
150+ let RemotePublishCommand ;
151+ let writeDictItem ;
152+ let purgeAll ;
153+ let testRoot ;
154+ let pwd ;
155+ let publishedstrains ;
156+ let remote ;
157+
158+ beforeEach ( 'Setting up Fake Server' , async function bef ( ) {
159+ this . timeout ( 5000 ) ;
160+ writeDictItem = sinon . fake . resolves ( true ) ;
161+ purgeAll = sinon . fake . resolves ( true ) ;
162+
163+ RemotePublishCommand = proxyquire ( '../src/remotepublish.cmd' , {
164+ '@adobe/fastly-native-promises' : ( ) => ( {
165+ transact : fn => fn ( 3 ) ,
166+ writeDictItem,
167+ purgeAll,
168+ } ) ,
169+ } ) ;
170+
171+
172+ // ensure to reset nock to avoid conflicts with PollyJS
173+ nock . restore ( ) ;
174+ nock . cleanAll ( ) ;
175+ nock . activate ( ) ;
176+
177+ nock ( 'https://adobeioruntime.net' )
178+ . post ( '/api/v1/web/helix/default/publish' , ( body ) => {
179+ publishedstrains = body . configuration . strains . reduce ( ( o , strain ) => {
180+ if ( strain . origin ) {
181+ // eslint-disable-next-line no-param-reassign
182+ o [ strain . name ] = strain . origin . hostname === 'www.adobe.io' ? 'branch' : 'master' ;
183+ }
184+ if ( strain . package ) {
185+ // eslint-disable-next-line no-param-reassign
186+ o [ strain . name ] = strain . package ;
187+ }
188+ return o ;
189+ } , { } ) ;
190+ return true ;
191+ } )
192+ . reply ( 200 , { } )
193+ . post ( '/api/v1/web/helix/default/addlogger' )
194+ . reply ( 200 , { } ) ;
195+
196+ // set up a fake git repo.
197+ testRoot = await createTestRoot ( ) ;
198+ await fse . copy ( path . resolve ( __dirname , 'fixtures/filtered-master.yaml' ) , path . resolve ( testRoot , 'wrong-helix-config.yaml' ) ) ;
199+
200+ // throw a Javascript error when any shell.js command encounters an error
201+ shell . config . fatal = true ;
202+
203+ // init git repo
204+ pwd = shell . pwd ( ) ;
205+ shell . cd ( testRoot ) ;
206+ shell . exec ( 'git init' ) ;
207+ shell . exec ( 'git add -A' ) ;
208+ shell . exec ( 'git commit -m"initial commit."' ) ;
209+
210+ // set up command
211+ remote = await new RemotePublishCommand ( makeLogger ( { logLevel : 'debug' } ) )
212+ . withWskAuth ( 'fakeauth' )
213+ . withWskNamespace ( 'fakename' )
214+ . withFastlyAuth ( 'fake_auth' )
215+ . withFastlyNamespace ( 'fake_name' )
216+ . withWskHost ( 'doesn.t.matter' )
217+ . withPublishAPI ( 'https://adobeioruntime.net/api/v1/web/helix/default/publish' )
218+ . withConfigFile ( path . resolve ( __dirname , 'fixtures/filtered.yaml' ) )
219+ . withDryRun ( false ) ;
220+ } ) ;
221+
222+ it ( 'publishing without filters takes everything from branch' , async ( ) => {
223+ await remote . run ( ) ;
224+
225+ assert . deepEqual ( publishedstrains , {
226+ default : 'branch' ,
227+ 'both-api' : 'branch' ,
228+ 'branch-foo' : 'branch' ,
229+ 'branch-bar' : 'branch' ,
230+ 'only-branch' : 'branch' ,
231+ } ) ;
232+ } ) ;
233+
234+ it ( 'publishing with only fails' , async ( ) => {
235+ remote = remote . withFilter ( 'branch-*' , undefined ) ;
236+ try {
237+ await remote . run ( ) ;
238+ assert . fail ( 'this should fail' ) ;
239+ } catch ( e ) {
240+ if ( e instanceof assert . AssertionError ) {
241+ throw e ;
242+ }
243+ assert . equal ( e . message , 'Error while running the Publish command' ) ;
244+ }
245+ } ) ;
246+
247+ it ( 'publishing with exclude fails' , async ( ) => {
248+ remote = remote . withFilter ( undefined , 'branch-*' ) ;
249+ try {
250+ await remote . run ( ) ;
251+ assert . fail ( 'this should fail' ) ;
252+ } catch ( e ) {
253+ if ( e instanceof assert . AssertionError ) {
254+ throw e ;
255+ }
256+ assert . equal ( e . message , 'Error while running the Publish command' ) ;
257+ }
258+ } ) ;
259+
260+
261+ afterEach ( async ( ) => {
262+ nock . restore ( ) ;
263+ shell . cd ( pwd ) ;
264+ await fse . remove ( testRoot ) ;
265+ } ) ;
266+ } ) ;
0 commit comments