@@ -389,3 +389,111 @@ func TestBoardDelete(t *testing.T) {
389389 assertExitCode (t , err , errors .ExitNotFound )
390390 })
391391}
392+
393+ func TestBoardPublish (t * testing.T ) {
394+ t .Run ("publishes board" , func (t * testing.T ) {
395+ mock := NewMockClient ()
396+ mock .PostResponse = & client.APIResponse {
397+ StatusCode : 201 ,
398+ Data : map [string ]any {
399+ "id" : "123" ,
400+ "name" : "Published Board" ,
401+ "public_url" : "https://app.fizzy.do/public/boards/test" ,
402+ },
403+ }
404+
405+ result := SetTestMode (mock )
406+ SetTestConfig ("token" , "account" , "https://api.example.com" )
407+ defer ResetTestMode ()
408+
409+ err := boardPublishCmd .RunE (boardPublishCmd , []string {"123" })
410+ assertExitCode (t , err , 0 )
411+
412+ if err != nil {
413+ t .Fatalf ("unexpected error: %v" , err )
414+ }
415+ if ! result .Response .OK {
416+ t .Error ("expected success response" )
417+ }
418+ if len (mock .PostCalls ) != 1 {
419+ t .Errorf ("expected 1 Post call, got %d" , len (mock .PostCalls ))
420+ }
421+ if mock .PostCalls [0 ].Path != "/boards/123/publication.json" {
422+ t .Errorf ("expected path '/boards/123/publication.json', got '%s'" , mock .PostCalls [0 ].Path )
423+ }
424+ if result .Response == nil || result .Response .Data == nil {
425+ t .Fatal ("expected response data" )
426+ }
427+ data , ok := result .Response .Data .(map [string ]any )
428+ if ! ok {
429+ t .Fatal ("expected response data map" )
430+ }
431+ if data ["public_url" ] != "https://app.fizzy.do/public/boards/test" {
432+ t .Errorf ("expected public_url in response, got %v" , data ["public_url" ])
433+ }
434+ })
435+
436+ t .Run ("handles API error" , func (t * testing.T ) {
437+ mock := NewMockClient ()
438+ mock .PostError = errors .NewForbiddenError ("Only admins can publish boards" )
439+
440+ SetTestMode (mock )
441+ SetTestConfig ("token" , "account" , "https://api.example.com" )
442+ defer ResetTestMode ()
443+
444+ err := boardPublishCmd .RunE (boardPublishCmd , []string {"123" })
445+ assertExitCode (t , err , errors .ExitForbidden )
446+ })
447+ }
448+
449+ func TestBoardUnpublish (t * testing.T ) {
450+ t .Run ("unpublishes board" , func (t * testing.T ) {
451+ mock := NewMockClient ()
452+ mock .DeleteResponse = & client.APIResponse {
453+ StatusCode : 204 ,
454+ Data : map [string ]any {},
455+ }
456+
457+ result := SetTestMode (mock )
458+ SetTestConfig ("token" , "account" , "https://api.example.com" )
459+ defer ResetTestMode ()
460+
461+ err := boardUnpublishCmd .RunE (boardUnpublishCmd , []string {"123" })
462+ assertExitCode (t , err , 0 )
463+
464+ if err != nil {
465+ t .Fatalf ("unexpected error: %v" , err )
466+ }
467+ if ! result .Response .OK {
468+ t .Error ("expected success response" )
469+ }
470+ if len (mock .DeleteCalls ) != 1 {
471+ t .Errorf ("expected 1 Delete call, got %d" , len (mock .DeleteCalls ))
472+ }
473+ if mock .DeleteCalls [0 ].Path != "/boards/123/publication.json" {
474+ t .Errorf ("expected path '/boards/123/publication.json', got '%s'" , mock .DeleteCalls [0 ].Path )
475+ }
476+ if result .Response == nil || result .Response .Data == nil {
477+ t .Fatal ("expected response data" )
478+ }
479+ data , ok := result .Response .Data .(map [string ]any )
480+ if ! ok {
481+ t .Fatal ("expected response data map" )
482+ }
483+ if data ["unpublished" ] != true {
484+ t .Errorf ("expected unpublished=true, got %v" , data ["unpublished" ])
485+ }
486+ })
487+
488+ t .Run ("handles not found" , func (t * testing.T ) {
489+ mock := NewMockClient ()
490+ mock .DeleteError = errors .NewNotFoundError ("Board not found" )
491+
492+ SetTestMode (mock )
493+ SetTestConfig ("token" , "account" , "https://api.example.com" )
494+ defer ResetTestMode ()
495+
496+ err := boardUnpublishCmd .RunE (boardUnpublishCmd , []string {"999" })
497+ assertExitCode (t , err , errors .ExitNotFound )
498+ })
499+ }
0 commit comments