diff --git a/internal/commands/project.go b/internal/commands/project.go index 5a195ace1..4f6cbb957 100644 --- a/internal/commands/project.go +++ b/internal/commands/project.go @@ -610,6 +610,7 @@ func toProjectView(model wrappers.ProjectResponseModel) projectView { //nolint:g Tags: model.Tags, Groups: model.Groups, ApplicationIds: model.ApplicationIds, + MainBranch: model.MainBranch, } } @@ -618,6 +619,7 @@ type projectView struct { Name string CreatedAt time.Time `format:"name:Created at;time:01-02-06 15:04:05"` UpdatedAt time.Time `format:"name:Updated at;time:01-02-06 15:04:05"` + MainBranch string Tags map[string]string Groups []string ApplicationIds []string diff --git a/internal/commands/project_test.go b/internal/commands/project_test.go index 25b0d8a9c..973f3576b 100644 --- a/internal/commands/project_test.go +++ b/internal/commands/project_test.go @@ -4,10 +4,12 @@ package commands import ( "testing" + "time" asserts "github.com/stretchr/testify/assert" errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors" + "github.com/checkmarx/ast-cli/internal/wrappers" "github.com/checkmarx/ast-cli/internal/wrappers/mock" "github.com/checkmarx/ast-cli/internal/wrappers/utils" @@ -269,3 +271,30 @@ func TestSupportEmptyTags_whenOnlyKeysFlagHasEmptyValue_shouldNotChangeParams(t assert.Equal(t, params["tags-values"], "value1") assert.Equal(t, len(params), 4) } + +func TestToProjectView(t *testing.T) { + // Arrange: Create a sample ProjectResponseModel + input := wrappers.ProjectResponseModel{ + ID: "123", + Name: "Test Project", + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + MainBranch: "main", + Tags: map[string]string{"key1": "value1"}, + Groups: []string{"group1", "group2"}, + ApplicationIds: []string{"app1", "app2"}, + } + + // Act: Call the toProjectView function + result := toProjectView(input) + + // Assert: Verify the fields are correctly mapped + assert.Equal(t, result.ID, input.ID) + assert.Equal(t, result.Name, input.Name) + assert.Equal(t, result.CreatedAt, input.CreatedAt) + assert.Equal(t, result.UpdatedAt, input.UpdatedAt) + assert.Equal(t, result.MainBranch, input.MainBranch) + assert.DeepEqual(t, result.Tags, input.Tags) + assert.DeepEqual(t, result.Groups, input.Groups) + assert.DeepEqual(t, result.ApplicationIds, input.ApplicationIds) +} diff --git a/test/integration/project_test.go b/test/integration/project_test.go index ca09be098..cf6e73d19 100644 --- a/test/integration/project_test.go +++ b/test/integration/project_test.go @@ -4,6 +4,7 @@ package integration import ( "fmt" + asserts "github.com/stretchr/testify/assert" "io" "io/ioutil" "log" @@ -365,3 +366,22 @@ func TestCreateProjectWithSSHKey(t *testing.T) { fmt.Printf("New project created with id: %s \n", createdProject.ID) deleteProject(t, createdProject.ID) } + +func TestProjectShow_MainBranch_Exist(t *testing.T) { + + projectID, projectName := createProject(t, Tags, Groups) + defer deleteProject(t, projectID) + + args := []string{ + "scan", "create", + flag(params.ProjectName), projectName, + flag(params.SourcesFlag), "data/insecure.zip", + flag(params.BranchFlag), "dummy_branch", + flag(params.BranchPrimaryFlag), + } + err, _ := executeCommand(t, args...) + assert.NilError(t, err) + + project := showProject(t, projectID) + asserts.Contains(t, project.MainBranch, "dummy_branch", "Project main branch should be 'dummy_branch'") +}