Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ func toProjectView(model wrappers.ProjectResponseModel) projectView { //nolint:g
Tags: model.Tags,
Groups: model.Groups,
ApplicationIds: model.ApplicationIds,
MainBranch: model.MainBranch,
}
}

Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions internal/commands/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
20 changes: 20 additions & 0 deletions test/integration/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package integration

import (
"fmt"
asserts "github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"log"
Expand Down Expand Up @@ -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'")
}
Loading