@@ -223,7 +223,20 @@ describe('Command Prototype', () => {
223223
224224 expect ( TheCommand . flags . workspace . default ) . toBe ( 'Stage' )
225225 expect ( TheCommand . flags . workspace . char ) . toBe ( 'w' )
226- expect ( TheCommand . flags . workspace . exclusive ) . toEqual ( [ 'import' ] )
226+ expect ( TheCommand . flags . workspace . exclusive ) . toEqual ( [ 'import' , 'no-login' ] )
227+
228+ expect ( TheCommand . flags . org ) . toBeDefined ( )
229+ expect ( TheCommand . flags . org . hidden ) . toBeFalsy ( )
230+ expect ( TheCommand . flags . org . char ) . toBe ( 'o' )
231+ expect ( TheCommand . flags . org . exclusive ) . toEqual ( [ 'import' , 'no-login' ] )
232+
233+ expect ( TheCommand . flags . project ) . toBeDefined ( )
234+ expect ( TheCommand . flags . project . hidden ) . toBeFalsy ( )
235+ expect ( TheCommand . flags . project . char ) . toBe ( 'p' )
236+ expect ( TheCommand . flags . project . exclusive ) . toEqual ( [ 'import' , 'no-login' ] )
237+
238+ expect ( TheCommand . flags [ 'template-options' ] ) . toBeDefined ( )
239+ expect ( TheCommand . flags [ 'template-options' ] . type ) . toBe ( 'option' )
227240
228241 expect ( TheCommand . flags [ 'confirm-new-workspace' ] . type ) . toBe ( 'boolean' )
229242 expect ( TheCommand . flags [ 'confirm-new-workspace' ] . default ) . toBe ( true )
@@ -801,3 +814,70 @@ describe('dev terms', () => {
801814 await expect ( command . run ( ) ) . rejects . toThrow ( 'The Developer Terms of Service could not be accepted' )
802815 } )
803816} )
817+
818+ describe ( 'template-options' , ( ) => {
819+ test ( 'no flag' , async ( ) => {
820+ command . argv = [ '--template' , 'some-template' ]
821+
822+ const installOptions = {
823+ installNpm : true ,
824+ templates : [ 'some-template' ] ,
825+ useDefaultValues : false
826+ }
827+
828+ await command . run ( )
829+ expect ( command . installTemplates ) . toHaveBeenCalledWith ( installOptions )
830+ } )
831+
832+ test ( 'valid base64' , async ( ) => {
833+ const templateOptions = {
834+ text : 'base-text'
835+ }
836+ const base64 = Buffer . from ( JSON . stringify ( templateOptions ) ) . toString ( 'base64' )
837+ command . argv = [ '--template' , 'some-template' , '--template-options' , `${ base64 } ` ]
838+
839+ const installOptions = {
840+ installNpm : true ,
841+ templates : [ 'some-template' ] ,
842+ useDefaultValues : false ,
843+ templateOptions
844+ }
845+
846+ await command . run ( )
847+ expect ( command . installTemplates ) . toHaveBeenCalledWith ( installOptions )
848+ } )
849+
850+ test ( 'valid base64 --no-login' , async ( ) => {
851+ const templateOptions = {
852+ text : 'base-text'
853+ }
854+ const base64 = Buffer . from ( JSON . stringify ( templateOptions ) ) . toString ( 'base64' )
855+ command . argv = [ '--no-login' , '--template' , 'some-template' , '--template-options' , `${ base64 } ` ]
856+
857+ const installOptions = {
858+ installConfig : false ,
859+ installNpm : true ,
860+ templates : [ 'some-template' ] ,
861+ useDefaultValues : false ,
862+ templateOptions
863+ }
864+
865+ await command . run ( )
866+ expect ( command . installTemplates ) . toHaveBeenCalledWith ( installOptions )
867+ } )
868+
869+ test ( 'invalid base64' , async ( ) => {
870+ command . argv = [ '--template' , 'some-template' , '--template-options=%' ] // % is an invalid base64 character
871+
872+ expect . assertions ( 1 )
873+ await expect ( command . run ( ) ) . rejects . toThrow ( '--template-options: % is not a base64 encoded JSON object.' )
874+ } )
875+
876+ test ( 'malformed json' , async ( ) => {
877+ const options = '{' // ew== in base64
878+ command . argv = [ '--template' , 'some-template' , `--template-options=${ Buffer . from ( options ) . toString ( 'base64' ) } ` ]
879+
880+ expect . assertions ( 1 )
881+ await expect ( command . run ( ) ) . rejects . toThrow ( '--template-options: ew== is not a base64 encoded JSON object.' )
882+ } )
883+ } )
0 commit comments