@@ -206,6 +206,7 @@ describe('previewCommand', () => {
206206 createApiClient : ( ) => ( {
207207 request : async ( ) => ( { } ) ,
208208 } ) ,
209+ getBuild : async ( ) => ( { project : { isPublic : true } } ) ,
209210 uploadPreviewZip : async ( _client , buildId ) => {
210211 capturedBuildId = buildId ;
211212 return {
@@ -244,6 +245,7 @@ describe('previewCommand', () => {
244245 } ) ,
245246 detectBranch : async ( ) => 'main' ,
246247 createApiClient : ( ) => ( { } ) ,
248+ getBuild : async ( ) => ( { project : { isPublic : true } } ) ,
247249 uploadPreviewZip : async ( _client , buildId ) => {
248250 capturedBuildId = buildId ;
249251 return {
@@ -311,6 +313,7 @@ describe('previewCommand', () => {
311313 apiUrl : 'https://api.test' ,
312314 } ) ,
313315 createApiClient : ( ) => ( { } ) ,
316+ getBuild : async ( ) => ( { project : { isPublic : true } } ) ,
314317 uploadPreviewZip : async ( ) => ( {
315318 previewUrl : 'https://preview.test' ,
316319 uploaded : 3 ,
@@ -344,6 +347,7 @@ describe('previewCommand', () => {
344347 apiUrl : 'https://api.test' ,
345348 } ) ,
346349 createApiClient : ( ) => ( { } ) ,
350+ getBuild : async ( ) => ( { project : { isPublic : true } } ) ,
347351 uploadPreviewZip : async ( ) => ( {
348352 previewUrl : 'https://preview.test' ,
349353 uploaded : 3 ,
@@ -562,4 +566,121 @@ describe('previewCommand', () => {
562566 'Should exclude tsconfig.json'
563567 ) ;
564568 } ) ;
569+
570+ it ( 'fails for private project without --public-link flag' , async ( ) => {
571+ let output = createMockOutput ( ) ;
572+ let exitCode = null ;
573+
574+ let result = await previewCommand (
575+ distDir ,
576+ { build : 'build-123' } ,
577+ { } ,
578+ {
579+ loadConfig : async ( ) => ( {
580+ apiKey : 'test-token' ,
581+ apiUrl : 'https://api.test' ,
582+ } ) ,
583+ createApiClient : ( ) => ( { } ) ,
584+ getBuild : async ( ) => ( {
585+ id : 'build-123' ,
586+ project : { id : 'proj-1' , name : 'Test Project' , isPublic : false } ,
587+ } ) ,
588+ uploadPreviewZip : async ( ) => {
589+ throw new Error ( 'Should not reach upload' ) ;
590+ } ,
591+ output,
592+ exit : code => {
593+ exitCode = code ;
594+ } ,
595+ }
596+ ) ;
597+
598+ assert . strictEqual ( exitCode , 1 ) ;
599+ assert . strictEqual ( result . success , false ) ;
600+ assert . strictEqual ( result . reason , 'private-project-no-flag' ) ;
601+ assert . ok (
602+ output . calls . some (
603+ c => c . method === 'error' && c . args [ 0 ] . includes ( 'private' )
604+ ) ,
605+ 'Should show private project error'
606+ ) ;
607+ assert . ok (
608+ output . calls . some (
609+ c => c . method === 'print' && c . args [ 0 ] . includes ( '--public-link' )
610+ ) ,
611+ 'Should mention --public-link flag in output'
612+ ) ;
613+ } ) ;
614+
615+ it ( 'succeeds for private project with --public-link flag' , async ( ) => {
616+ let output = createMockOutput ( ) ;
617+ let uploadCalled = false ;
618+
619+ let result = await previewCommand (
620+ distDir ,
621+ { build : 'build-123' , publicLink : true } ,
622+ { } ,
623+ {
624+ loadConfig : async ( ) => ( {
625+ apiKey : 'test-token' ,
626+ apiUrl : 'https://api.test' ,
627+ } ) ,
628+ createApiClient : ( ) => ( { } ) ,
629+ getBuild : async ( ) => ( {
630+ id : 'build-123' ,
631+ project : { id : 'proj-1' , name : 'Test Project' , isPublic : false } ,
632+ } ) ,
633+ uploadPreviewZip : async ( ) => {
634+ uploadCalled = true ;
635+ return {
636+ previewUrl : 'https://preview.test' ,
637+ uploaded : 3 ,
638+ totalBytes : 1000 ,
639+ newBytes : 800 ,
640+ } ;
641+ } ,
642+ output,
643+ exit : ( ) => { } ,
644+ }
645+ ) ;
646+
647+ assert . strictEqual ( uploadCalled , true , 'Should call upload' ) ;
648+ assert . strictEqual ( result . success , true ) ;
649+ } ) ;
650+
651+ it ( 'succeeds for public project without --public-link flag' , async ( ) => {
652+ let output = createMockOutput ( ) ;
653+ let uploadCalled = false ;
654+
655+ let result = await previewCommand (
656+ distDir ,
657+ { build : 'build-123' } ,
658+ { } ,
659+ {
660+ loadConfig : async ( ) => ( {
661+ apiKey : 'test-token' ,
662+ apiUrl : 'https://api.test' ,
663+ } ) ,
664+ createApiClient : ( ) => ( { } ) ,
665+ getBuild : async ( ) => ( {
666+ id : 'build-123' ,
667+ project : { id : 'proj-1' , name : 'Test Project' , isPublic : true } ,
668+ } ) ,
669+ uploadPreviewZip : async ( ) => {
670+ uploadCalled = true ;
671+ return {
672+ previewUrl : 'https://preview.test' ,
673+ uploaded : 3 ,
674+ totalBytes : 1000 ,
675+ newBytes : 800 ,
676+ } ;
677+ } ,
678+ output,
679+ exit : ( ) => { } ,
680+ }
681+ ) ;
682+
683+ assert . strictEqual ( uploadCalled , true , 'Should call upload' ) ;
684+ assert . strictEqual ( result . success , true ) ;
685+ } ) ;
565686} ) ;
0 commit comments