@@ -141,8 +141,7 @@ describe('project create', () => {
141141 await program . parseAsync ( [ 'node' , 'catalyst' , 'project' , 'create' , '--root-dir' , tmpDir ] ) ;
142142
143143 if ( savedStoreHash !== undefined ) process . env . CATALYST_STORE_HASH = savedStoreHash ;
144- if ( savedAccessToken !== undefined )
145- process . env . CATALYST_ACCESS_TOKEN = savedAccessToken ;
144+ if ( savedAccessToken !== undefined ) process . env . CATALYST_ACCESS_TOKEN = savedAccessToken ;
146145
147146 expect ( consola . error ) . toHaveBeenCalledWith ( 'Insufficient information to create a project.' ) ;
148147 expect ( consola . info ) . toHaveBeenCalledWith (
@@ -220,8 +219,7 @@ describe('project list', () => {
220219 await program . parseAsync ( [ 'node' , 'catalyst' , 'project' , 'list' ] ) ;
221220
222221 if ( savedStoreHash !== undefined ) process . env . CATALYST_STORE_HASH = savedStoreHash ;
223- if ( savedAccessToken !== undefined )
224- process . env . CATALYST_ACCESS_TOKEN = savedAccessToken ;
222+ if ( savedAccessToken !== undefined ) process . env . CATALYST_ACCESS_TOKEN = savedAccessToken ;
225223
226224 expect ( consola . error ) . toHaveBeenCalledWith ( 'Insufficient information to list projects.' ) ;
227225 expect ( consola . info ) . toHaveBeenCalledWith (
@@ -492,8 +490,7 @@ describe('project link', () => {
492490 await program . parseAsync ( [ 'node' , 'catalyst' , 'project' , 'link' , '--root-dir' , tmpDir ] ) ;
493491
494492 if ( savedStoreHash !== undefined ) process . env . CATALYST_STORE_HASH = savedStoreHash ;
495- if ( savedAccessToken !== undefined )
496- process . env . CATALYST_ACCESS_TOKEN = savedAccessToken ;
493+ if ( savedAccessToken !== undefined ) process . env . CATALYST_ACCESS_TOKEN = savedAccessToken ;
497494 if ( savedCatalystProjectUuid !== undefined )
498495 process . env . CATALYST_PROJECT_UUID = savedCatalystProjectUuid ;
499496
@@ -514,300 +511,3 @@ describe('project link', () => {
514511 } ) ;
515512} ) ;
516513
517- describe ( 'project list' , ( ) => {
518- test ( 'fetches and displays projects' , async ( ) => {
519- await program . parseAsync ( [
520- 'node' ,
521- 'catalyst' ,
522- 'project' ,
523- 'list' ,
524- '--store-hash' ,
525- storeHash ,
526- '--access-token' ,
527- accessToken ,
528- ] ) ;
529-
530- expect ( mockIdentify ) . toHaveBeenCalledWith ( storeHash ) ;
531- expect ( consola . start ) . toHaveBeenCalledWith ( 'Fetching projects...' ) ;
532- expect ( consola . success ) . toHaveBeenCalledWith ( 'Projects fetched.' ) ;
533- expect ( consola . log ) . toHaveBeenCalledWith ( 'Project One (a23f5785-fd99-4a94-9fb3-945551623923)' ) ;
534- expect ( consola . log ) . toHaveBeenCalledWith ( 'Project Two (b23f5785-fd99-4a94-9fb3-945551623924)' ) ;
535- expect ( exitMock ) . toHaveBeenCalledWith ( 0 ) ;
536- } ) ;
537-
538- test ( 'with insufficient credentials exits with error' , async ( ) => {
539- const savedStoreHash = process . env . BIGCOMMERCE_STORE_HASH ;
540- const savedAccessToken = process . env . BIGCOMMERCE_ACCESS_TOKEN ;
541-
542- delete process . env . BIGCOMMERCE_STORE_HASH ;
543- delete process . env . BIGCOMMERCE_ACCESS_TOKEN ;
544-
545- await program . parseAsync ( [ 'node' , 'catalyst' , 'project' , 'list' ] ) ;
546-
547- if ( savedStoreHash !== undefined ) process . env . BIGCOMMERCE_STORE_HASH = savedStoreHash ;
548- if ( savedAccessToken !== undefined ) process . env . BIGCOMMERCE_ACCESS_TOKEN = savedAccessToken ;
549-
550- expect ( consola . error ) . toHaveBeenCalledWith ( 'Insufficient information to list projects.' ) ;
551- expect ( consola . info ) . toHaveBeenCalledWith (
552- 'Provide both --store-hash and --access-token (or set BIGCOMMERCE_STORE_HASH and BIGCOMMERCE_ACCESS_TOKEN).' ,
553- ) ;
554- expect ( exitMock ) . toHaveBeenCalledWith ( 1 ) ;
555- } ) ;
556- } ) ;
557-
558- describe ( 'project link' , ( ) => {
559- test ( 'properly configured Command instance' , ( ) => {
560- expect ( link ) . toBeInstanceOf ( Command ) ;
561- expect ( link . name ( ) ) . toBe ( 'link' ) ;
562- expect ( link . description ( ) ) . toBe (
563- 'Link your local Catalyst project to a BigCommerce infrastructure project. You can provide a project UUID directly, or fetch and select from available projects using your store credentials.' ,
564- ) ;
565- expect ( link . options ) . toEqual (
566- expect . arrayContaining ( [
567- expect . objectContaining ( { flags : '--store-hash <hash>' } ) ,
568- expect . objectContaining ( { flags : '--access-token <token>' } ) ,
569- expect . objectContaining ( {
570- flags : '--api-host <host>' ,
571- defaultValue : 'api.bigcommerce.com' ,
572- } ) ,
573- expect . objectContaining ( { flags : '--project-uuid <uuid>' } ) ,
574- expect . objectContaining ( { flags : '--root-dir <path>' , defaultValue : process . cwd ( ) } ) ,
575- ] ) ,
576- ) ;
577- } ) ;
578-
579- test ( 'sets projectUuid when called with --project-uuid' , async ( ) => {
580- await program . parseAsync ( [
581- 'node' ,
582- 'catalyst' ,
583- 'project' ,
584- 'link' ,
585- '--project-uuid' ,
586- projectUuid1 ,
587- '--root-dir' ,
588- tmpDir ,
589- ] ) ;
590-
591- expect ( consola . start ) . toHaveBeenCalledWith (
592- 'Writing project UUID to .bigcommerce/project.json...' ,
593- ) ;
594- expect ( consola . success ) . toHaveBeenCalledWith (
595- 'Project UUID written to .bigcommerce/project.json.' ,
596- ) ;
597- expect ( exitMock ) . toHaveBeenCalledWith ( 0 ) ;
598- expect ( config . get ( 'projectUuid' ) ) . toBe ( projectUuid1 ) ;
599- expect ( config . get ( 'framework' ) ) . toBe ( 'catalyst' ) ;
600- } ) ;
601-
602- test ( 'fetches projects and prompts user to select one' , async ( ) => {
603- const consolaPromptMock = vi
604- . spyOn ( consola , 'prompt' )
605- . mockImplementation ( async ( message , opts ) => {
606- expect ( message ) . toContain (
607- 'Select a project or create a new project (Press <enter> to select).' ,
608- ) ;
609-
610- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
611- const options = ( opts as { options : Array < { label : string ; value : string } > } ) . options ;
612-
613- expect ( options ) . toHaveLength ( 3 ) ;
614- expect ( options [ 0 ] ) . toMatchObject ( { label : 'Project One' , value : projectUuid1 } ) ;
615- expect ( options [ 1 ] ) . toMatchObject ( {
616- label : 'Project Two' ,
617- value : projectUuid2 ,
618- } ) ;
619- expect ( options [ 2 ] ) . toMatchObject ( { label : 'Create a new project' , value : 'create' } ) ;
620-
621- return new Promise ( ( resolve ) => resolve ( projectUuid2 ) ) ;
622- } ) ;
623-
624- await program . parseAsync ( [
625- 'node' ,
626- 'catalyst' ,
627- 'project' ,
628- 'link' ,
629- '--store-hash' ,
630- storeHash ,
631- '--access-token' ,
632- accessToken ,
633- '--root-dir' ,
634- tmpDir ,
635- ] ) ;
636-
637- expect ( mockIdentify ) . toHaveBeenCalledWith ( storeHash ) ;
638-
639- expect ( consola . start ) . toHaveBeenCalledWith ( 'Fetching projects...' ) ;
640- expect ( consola . success ) . toHaveBeenCalledWith ( 'Projects fetched.' ) ;
641-
642- expect ( consola . start ) . toHaveBeenCalledWith (
643- 'Writing project UUID to .bigcommerce/project.json...' ,
644- ) ;
645- expect ( consola . success ) . toHaveBeenCalledWith (
646- 'Project UUID written to .bigcommerce/project.json.' ,
647- ) ;
648-
649- expect ( exitMock ) . toHaveBeenCalledWith ( 0 ) ;
650-
651- expect ( config . get ( 'projectUuid' ) ) . toBe ( projectUuid2 ) ;
652- expect ( config . get ( 'framework' ) ) . toBe ( 'catalyst' ) ;
653-
654- consolaPromptMock . mockRestore ( ) ;
655- } ) ;
656-
657- test ( 'prompts to create a new project' , async ( ) => {
658- const consolaPromptMock = vi
659- . spyOn ( consola , 'prompt' )
660- . mockImplementationOnce ( async ( message , opts ) => {
661- expect ( message ) . toContain (
662- 'Select a project or create a new project (Press <enter> to select).' ,
663- ) ;
664-
665- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
666- const options = ( opts as { options : Array < { label : string ; value : string } > } ) . options ;
667-
668- expect ( options ) . toHaveLength ( 3 ) ;
669- expect ( options [ 0 ] ) . toMatchObject ( { label : 'Project One' , value : projectUuid1 } ) ;
670- expect ( options [ 1 ] ) . toMatchObject ( {
671- label : 'Project Two' ,
672- value : projectUuid2 ,
673- } ) ;
674- expect ( options [ 2 ] ) . toMatchObject ( { label : 'Create a new project' , value : 'create' } ) ;
675-
676- return new Promise ( ( resolve ) => resolve ( 'create' ) ) ;
677- } )
678- . mockImplementationOnce ( async ( message ) => {
679- expect ( message ) . toBe ( 'Enter a name for the new project:' ) ;
680-
681- return new Promise ( ( resolve ) => resolve ( 'New Project' ) ) ;
682- } ) ;
683-
684- await program . parseAsync ( [
685- 'node' ,
686- 'catalyst' ,
687- 'project' ,
688- 'link' ,
689- '--store-hash' ,
690- storeHash ,
691- '--access-token' ,
692- accessToken ,
693- '--root-dir' ,
694- tmpDir ,
695- ] ) ;
696-
697- expect ( mockIdentify ) . toHaveBeenCalledWith ( storeHash ) ;
698-
699- expect ( consola . start ) . toHaveBeenCalledWith ( 'Fetching projects...' ) ;
700- expect ( consola . success ) . toHaveBeenCalledWith ( 'Projects fetched.' ) ;
701-
702- expect ( consola . success ) . toHaveBeenCalledWith ( 'Project "New Project" created successfully.' ) ;
703-
704- expect ( exitMock ) . toHaveBeenCalledWith ( 0 ) ;
705-
706- expect ( config . get ( 'projectUuid' ) ) . toBe ( projectUuid3 ) ;
707- expect ( config . get ( 'framework' ) ) . toBe ( 'catalyst' ) ;
708-
709- consolaPromptMock . mockRestore ( ) ;
710- } ) ;
711-
712- test ( 'errors when create project API fails' , async ( ) => {
713- server . use (
714- http . post ( 'https://:apiHost/stores/:storeHash/v3/infrastructure/projects' , ( ) =>
715- HttpResponse . json ( { } , { status : 502 } ) ,
716- ) ,
717- ) ;
718-
719- const consolaPromptMock = vi
720- . spyOn ( consola , 'prompt' )
721- . mockImplementationOnce ( async ( message , opts ) => {
722- expect ( message ) . toContain (
723- 'Select a project or create a new project (Press <enter> to select).' ,
724- ) ;
725-
726- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
727- const options = ( opts as { options : Array < { label : string ; value : string } > } ) . options ;
728-
729- expect ( options ) . toHaveLength ( 3 ) ;
730- expect ( options [ 0 ] ) . toMatchObject ( { label : 'Project One' , value : projectUuid1 } ) ;
731- expect ( options [ 1 ] ) . toMatchObject ( {
732- label : 'Project Two' ,
733- value : projectUuid2 ,
734- } ) ;
735- expect ( options [ 2 ] ) . toMatchObject ( { label : 'Create a new project' , value : 'create' } ) ;
736-
737- return new Promise ( ( resolve ) => resolve ( 'create' ) ) ;
738- } )
739- . mockImplementationOnce ( async ( message ) => {
740- expect ( message ) . toBe ( 'Enter a name for the new project:' ) ;
741-
742- return new Promise ( ( resolve ) => resolve ( 'New Project' ) ) ;
743- } ) ;
744-
745- await program . parseAsync ( [
746- 'node' ,
747- 'catalyst' ,
748- 'project' ,
749- 'link' ,
750- '--store-hash' ,
751- storeHash ,
752- '--access-token' ,
753- accessToken ,
754- '--root-dir' ,
755- tmpDir ,
756- ] ) ;
757-
758- expect ( mockIdentify ) . toHaveBeenCalledWith ( storeHash ) ;
759-
760- expect ( consola . start ) . toHaveBeenCalledWith ( 'Fetching projects...' ) ;
761- expect ( consola . success ) . toHaveBeenCalledWith ( 'Projects fetched.' ) ;
762-
763- expect ( consola . error ) . toHaveBeenCalledWith (
764- 'Failed to create project, is the name already in use?' ,
765- ) ;
766-
767- expect ( exitMock ) . toHaveBeenCalledWith ( 1 ) ;
768-
769- consolaPromptMock . mockRestore ( ) ;
770- } ) ;
771-
772- test ( 'errors when infrastructure projects API is not found' , async ( ) => {
773- server . use (
774- http . get ( 'https://:apiHost/stores/:storeHash/v3/infrastructure/projects' , ( ) =>
775- HttpResponse . json ( { } , { status : 403 } ) ,
776- ) ,
777- ) ;
778-
779- await program . parseAsync ( [
780- 'node' ,
781- 'catalyst' ,
782- 'project' ,
783- 'link' ,
784- '--store-hash' ,
785- storeHash ,
786- '--access-token' ,
787- accessToken ,
788- '--root-dir' ,
789- tmpDir ,
790- ] ) ;
791-
792- expect ( mockIdentify ) . toHaveBeenCalledWith ( storeHash ) ;
793-
794- expect ( consola . start ) . toHaveBeenCalledWith ( 'Fetching projects...' ) ;
795- expect ( consola . error ) . toHaveBeenCalledWith (
796- 'Infrastructure Projects API not enabled. If you are part of the alpha, contact support@bigcommerce.com to enable it.' ,
797- ) ;
798- } ) ;
799-
800- test ( 'errors when no projectUuid, storeHash, or accessToken are provided' , async ( ) => {
801- await program . parseAsync ( [ 'node' , 'catalyst' , 'project' , 'link' , '--root-dir' , tmpDir ] ) ;
802-
803- expect ( consola . start ) . not . toHaveBeenCalled ( ) ;
804- expect ( consola . success ) . not . toHaveBeenCalled ( ) ;
805- expect ( consola . error ) . toHaveBeenCalledWith ( 'Insufficient information to link a project.' ) ;
806- expect ( consola . info ) . toHaveBeenCalledWith ( 'Provide a project UUID with --project-uuid, or' ) ;
807- expect ( consola . info ) . toHaveBeenCalledWith (
808- 'Provide both --store-hash and --access-token to fetch and select a project.' ,
809- ) ;
810-
811- expect ( exitMock ) . toHaveBeenCalledWith ( 1 ) ;
812- } ) ;
813- } ) ;
0 commit comments