Skip to content

Commit f5bedc2

Browse files
Added mainBranch field in projectPreview
1 parent 90eeb94 commit f5bedc2

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

internal/commands/project.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ func toProjectView(model wrappers.ProjectResponseModel) projectView { //nolint:g
610610
Tags: model.Tags,
611611
Groups: model.Groups,
612612
ApplicationIds: model.ApplicationIds,
613+
MainBranch: model.MainBranch,
613614
}
614615
}
615616

@@ -618,6 +619,7 @@ type projectView struct {
618619
Name string
619620
CreatedAt time.Time `format:"name:Created at;time:01-02-06 15:04:05"`
620621
UpdatedAt time.Time `format:"name:Updated at;time:01-02-06 15:04:05"`
622+
MainBranch string
621623
Tags map[string]string
622624
Groups []string
623625
ApplicationIds []string

internal/commands/project_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
package commands
44

55
import (
6+
"github.com/checkmarx/ast-cli/internal/wrappers"
67
"testing"
8+
"time"
79

810
asserts "github.com/stretchr/testify/assert"
911

@@ -269,3 +271,30 @@ func TestSupportEmptyTags_whenOnlyKeysFlagHasEmptyValue_shouldNotChangeParams(t
269271
assert.Equal(t, params["tags-values"], "value1")
270272
assert.Equal(t, len(params), 4)
271273
}
274+
275+
func TestToProjectView(t *testing.T) {
276+
// Arrange: Create a sample ProjectResponseModel
277+
input := wrappers.ProjectResponseModel{
278+
ID: "123",
279+
Name: "Test Project",
280+
CreatedAt: time.Now(),
281+
UpdatedAt: time.Now(),
282+
MainBranch: "main",
283+
Tags: map[string]string{"key1": "value1"},
284+
Groups: []string{"group1", "group2"},
285+
ApplicationIds: []string{"app1", "app2"},
286+
}
287+
288+
// Act: Call the toProjectView function
289+
result := toProjectView(input)
290+
291+
// Assert: Verify the fields are correctly mapped
292+
assert.Equal(t, result.ID, input.ID)
293+
assert.Equal(t, result.Name, input.Name)
294+
assert.Equal(t, result.CreatedAt, input.CreatedAt)
295+
assert.Equal(t, result.UpdatedAt, input.UpdatedAt)
296+
assert.Equal(t, result.MainBranch, input.MainBranch)
297+
assert.DeepEqual(t, result.Tags, input.Tags)
298+
assert.DeepEqual(t, result.Groups, input.Groups)
299+
assert.DeepEqual(t, result.ApplicationIds, input.ApplicationIds)
300+
}

test/integration/project_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,21 @@ func TestCreateProjectWithSSHKey(t *testing.T) {
365365
fmt.Printf("New project created with id: %s \n", createdProject.ID)
366366
deleteProject(t, createdProject.ID)
367367
}
368+
369+
func TestProjectShow_MainBranch_Exist(t *testing.T) {
370+
371+
projectID, projectName := createProject(t, Tags, Groups)
372+
373+
args := []string{
374+
"scan", "create",
375+
flag(params.ProjectName), projectName,
376+
flag(params.SourcesFlag), "data/insecure.zip",
377+
flag(params.BranchFlag), "dummy_branch",
378+
flag(params.BranchPrimaryFlag), "dummy_branch",
379+
}
380+
err, _ = executeCommand(t, args...)
381+
assert.NilError(t, err)
382+
383+
project := showProject(t, createdProject.ID)
384+
asserts.Contains(t, project.MainBranch, "dummy_branch", "Project main branch should be 'dummy_branch'")
385+
}

0 commit comments

Comments
 (0)