@@ -5,6 +5,7 @@ package executor
55import (
66 "testing"
77
8+ "github.com/mendixlabs/mxcli/mdl/ast"
89 "github.com/mendixlabs/mxcli/mdl/backend/mock"
910 "github.com/mendixlabs/mxcli/mdl/types"
1011 "github.com/mendixlabs/mxcli/model"
@@ -526,3 +527,75 @@ func TestListDataTransformers_Mock_JSON(t *testing.T) {
526527 assertValidJSON (t , buf .String ())
527528 assertContainsStr (t , buf .String (), "Transform1" )
528529}
530+
531+ func TestShowAccessOnMicroflow_Mock_JSON (t * testing.T ) {
532+ mod := mkModule ("MyModule" )
533+ h := mkHierarchy (mod )
534+ mf := mkMicroflow (mod .ID , "ACT_DoStuff" )
535+ mf .AllowedModuleRoles = []model.ID {"MyModule.User" , "MyModule.Admin" }
536+ withContainer (h , mf .ContainerID , mod .ID )
537+
538+ mb := & mock.MockBackend {
539+ IsConnectedFunc : func () bool { return true },
540+ ListMicroflowsFunc : func () ([]* microflows.Microflow , error ) { return []* microflows.Microflow {mf }, nil },
541+ }
542+
543+ name := & ast.QualifiedName {Module : "MyModule" , Name : "ACT_DoStuff" }
544+ ctx , buf := newMockCtx (t , withBackend (mb ), withFormat (FormatJSON ), withHierarchy (h ))
545+ assertNoError (t , showAccessOnMicroflow (ctx , name ))
546+ assertValidJSON (t , buf .String ())
547+ assertContainsStr (t , buf .String (), "User" )
548+ }
549+
550+ func TestShowAccessOnPage_Mock_JSON (t * testing.T ) {
551+ mod := mkModule ("MyModule" )
552+ h := mkHierarchy (mod )
553+ pg := mkPage (mod .ID , "Page_Home" )
554+ pg .AllowedRoles = []model.ID {"MyModule.User" }
555+ withContainer (h , pg .ContainerID , mod .ID )
556+
557+ mb := & mock.MockBackend {
558+ IsConnectedFunc : func () bool { return true },
559+ ListPagesFunc : func () ([]* pages.Page , error ) { return []* pages.Page {pg }, nil },
560+ }
561+
562+ name := & ast.QualifiedName {Module : "MyModule" , Name : "Page_Home" }
563+ ctx , buf := newMockCtx (t , withBackend (mb ), withFormat (FormatJSON ), withHierarchy (h ))
564+ assertNoError (t , showAccessOnPage (ctx , name ))
565+ assertValidJSON (t , buf .String ())
566+ assertContainsStr (t , buf .String (), "User" )
567+ }
568+
569+ // TestShowConstants_Mock_JSON_EmptyResult verifies that an empty result still
570+ // produces valid JSON (not the "No ... found." plain-text message).
571+ func TestShowConstants_Mock_JSON_EmptyResult (t * testing.T ) {
572+ mod := mkModule ("MyModule" )
573+ h := mkHierarchy (mod )
574+
575+ mb := & mock.MockBackend {
576+ IsConnectedFunc : func () bool { return true },
577+ ListConstantsFunc : func () ([]* model.Constant , error ) { return nil , nil },
578+ }
579+
580+ ctx , buf := newMockCtx (t , withBackend (mb ), withFormat (FormatJSON ), withHierarchy (h ))
581+ assertNoError (t , showConstants (ctx , "" ))
582+ assertValidJSON (t , buf .String ())
583+ assertNotContainsStr (t , buf .String (), "No constants found" )
584+ }
585+
586+ // TestShowPublishedRestServices_Mock_JSON_EmptyResult verifies that an empty
587+ // result still produces valid JSON in JSON mode.
588+ func TestShowPublishedRestServices_Mock_JSON_EmptyResult (t * testing.T ) {
589+ mod := mkModule ("MyModule" )
590+ h := mkHierarchy (mod )
591+
592+ mb := & mock.MockBackend {
593+ IsConnectedFunc : func () bool { return true },
594+ ListPublishedRestServicesFunc : func () ([]* model.PublishedRestService , error ) { return nil , nil },
595+ }
596+
597+ ctx , buf := newMockCtx (t , withBackend (mb ), withFormat (FormatJSON ), withHierarchy (h ))
598+ assertNoError (t , showPublishedRestServices (ctx , "" ))
599+ assertValidJSON (t , buf .String ())
600+ assertNotContainsStr (t , buf .String (), "No published REST services found" )
601+ }
0 commit comments