|
1 | 1 | package services |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors" |
| 5 | + "github.com/checkmarx/ast-cli/internal/wrappers" |
| 6 | + "github.com/checkmarx/ast-cli/internal/wrappers/mock" |
| 7 | + "gotest.tools/assert" |
4 | 8 | "reflect" |
| 9 | + "strings" |
5 | 10 | "testing" |
6 | 11 | ) |
7 | 12 |
|
@@ -36,3 +41,49 @@ func Test_createApplicationIds(t *testing.T) { |
36 | 41 | }) |
37 | 42 | } |
38 | 43 | } |
| 44 | +func Test_ProjectAssociation_ToApplicationDirectly(t *testing.T) { |
| 45 | + applicationWrapper := &mock.ApplicationsMockWrapper{} |
| 46 | + |
| 47 | + tests := []struct { |
| 48 | + description string |
| 49 | + applicationName string |
| 50 | + projectName string |
| 51 | + error string |
| 52 | + }{ |
| 53 | + {"Project association to Application should fail with 403 forbidden permission error", mock.FakeForbidden403, "random-project", errorConstants.NoPermissionToUpdateApplication}, |
| 54 | + {"Project association to Application should fail with 401 unauthorized error", mock.FakeUnauthorized401, "random-project", errorConstants.StatusUnauthorized}, |
| 55 | + {"Project association to Application should fail with 400 BadRequest error", mock.FakeBadRequest400, "random-project", errorConstants.FailedToUpdateApplication}, |
| 56 | + } |
| 57 | + |
| 58 | + for _, test := range tests { |
| 59 | + tt := test |
| 60 | + t.Run(tt.description, func(t *testing.T) { |
| 61 | + err := associateProjectToApplication(tt.applicationName, tt.projectName, []string{}, applicationWrapper) |
| 62 | + assert.Assert(t, strings.Contains(err.Error(), tt.error), err.Error()) |
| 63 | + }) |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +func Test_ProjectAssociation_ToApplicationWithoutDirectAssociation(t *testing.T) { |
| 68 | + applicationModel := wrappers.ApplicationConfiguration{} |
| 69 | + applicationWrapper := &mock.ApplicationsMockWrapper{} |
| 70 | + |
| 71 | + tests := []struct { |
| 72 | + description string |
| 73 | + applicationId string |
| 74 | + projectName string |
| 75 | + error string |
| 76 | + }{ |
| 77 | + {"Application update should fail with 403 forbidden permission error", mock.FakeForbidden403, "random-project", errorConstants.NoPermissionToUpdateApplication}, |
| 78 | + {"Application update should fail with 401 unauthorized error", mock.FakeUnauthorized401, "random-project", errorConstants.StatusUnauthorized}, |
| 79 | + {"Application update should fail with 400 BadRequest error", mock.FakeBadRequest400, "random-project", errorConstants.FailedToUpdateApplication}, |
| 80 | + } |
| 81 | + |
| 82 | + for _, test := range tests { |
| 83 | + tt := test |
| 84 | + t.Run(tt.description, func(t *testing.T) { |
| 85 | + err := updateApplication(&applicationModel, applicationWrapper, tt.applicationId) |
| 86 | + assert.Assert(t, strings.Contains(err.Error(), tt.error), err.Error()) |
| 87 | + }) |
| 88 | + } |
| 89 | +} |
0 commit comments