Skip to content
Closed
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 @@ -3,7 +3,9 @@
package commands

import (
"github.com/checkmarx/ast-cli/internal/wrappers"

Check failure on line 6 in internal/commands/project_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (goimports)

Check failure on line 6 in internal/commands/project_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (goimports)
"testing"
"time"

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

Expand Down Expand Up @@ -269,3 +271,30 @@
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)
}
18 changes: 18 additions & 0 deletions test/integration/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,21 @@
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)

Check failure on line 371 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

declared and not used: projectID

Check failure on line 371 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

declared and not used: projectID

args := []string{
"scan", "create",
flag(params.ProjectName), projectName,
flag(params.SourcesFlag), "data/insecure.zip",
flag(params.BranchFlag), "dummy_branch",
flag(params.BranchPrimaryFlag), "dummy_branch",
}
err, _ = executeCommand(t, args...)

Check failure on line 380 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

undefined: err

Check failure on line 380 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

undefined: err
assert.NilError(t, err)

Check failure on line 381 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

undefined: err

Check failure on line 381 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

undefined: err

project := showProject(t, createdProject.ID)

Check failure on line 383 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

undefined: createdProject

Check failure on line 383 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

undefined: createdProject
asserts.Contains(t, project.MainBranch, "dummy_branch", "Project main branch should be 'dummy_branch'")

Check failure on line 384 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

undefined: asserts

Check failure on line 384 in test/integration/project_test.go

View workflow job for this annotation

GitHub Actions / integration-tests

undefined: asserts
}
Loading