Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Add tests for authentication types
Browse files Browse the repository at this point in the history
  • Loading branch information
deepflame committed Jul 11, 2024
1 parent 456b12b commit e43897f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 21 deletions.
2 changes: 1 addition & 1 deletion services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ type SetJiraServiceOptions struct {
JiraAuthType *int `url:"jira_auth_type,omitempty" json:"jira_auth_type,omitempty"`
JiraIssuePrefix *string `url:"jira_issue_prefix,omitempty" json:"jira_issue_prefix,omitempty"`
JiraIssueRegex *string `url:"jira_issue_regex,omitempty" json:"jira_issue_regex,omitempty"`
JiraIssueTransitionAutomatic *string `url:"jira_issue_transition_automatic,omitempty" json:"jira_issue_transition_automatic,omitempty"`
JiraIssueTransitionAutomatic *bool `url:"jira_issue_transition_automatic,omitempty" json:"jira_issue_transition_automatic,omitempty"`
JiraIssueTransitionID *string `url:"jira_issue_transition_id,omitempty" json:"jira_issue_transition_id,omitempty"`
CommitEvents *bool `url:"commit_events,omitempty" json:"commit_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
Expand Down
89 changes: 69 additions & 20 deletions services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,21 @@ func TestSetJiraService(t *testing.T) {
})

opt := &SetJiraServiceOptions{
URL: Ptr("asd"),
APIURL: Ptr("asd"),
ProjectKey: Ptr("as"),
Username: Ptr("aas"),
Password: Ptr("asd"),
Active: Ptr(true),
JiraIssueTransitionID: Ptr("2,3"),
CommitEvents: Ptr(true),
CommentOnEventEnabled: Ptr(true),
MergeRequestsEvents: Ptr(true),
URL: Ptr("asd"),
APIURL: Ptr("asd"),
ProjectKey: Ptr("as"),
Username: Ptr("aas"),
Password: Ptr("asd"),
Active: Ptr(true),
JiraIssuePrefix: Ptr("ASD"),
JiraIssueRegex: Ptr("ASD"),
JiraIssueTransitionAutomatic: Ptr(true),
JiraIssueTransitionID: Ptr("2,3"),
CommitEvents: Ptr(true),
MergeRequestsEvents: Ptr(true),
CommentOnEventEnabled: Ptr(true),
IssuesEnabled: Ptr(true),
UseInheritedSettings: Ptr(true),
}

_, err := client.Services.SetJiraService(1, opt)
Expand All @@ -467,16 +472,60 @@ func TestSetJiraServiceProjecKeys(t *testing.T) {
})

opt := &SetJiraServiceOptions{
URL: Ptr("asd"),
APIURL: Ptr("asd"),
ProjectKeys: Ptr([]string{"as"}),
Username: Ptr("aas"),
Password: Ptr("asd"),
Active: Ptr(true),
JiraIssueTransitionID: Ptr("2,3"),
CommitEvents: Ptr(true),
CommentOnEventEnabled: Ptr(true),
MergeRequestsEvents: Ptr(true),
URL: Ptr("asd"),
APIURL: Ptr("asd"),
Username: Ptr("aas"),
Password: Ptr("asd"),
Active: Ptr(true),
JiraIssuePrefix: Ptr("ASD"),
JiraIssueRegex: Ptr("ASD"),
JiraIssueTransitionAutomatic: Ptr(true),
JiraIssueTransitionID: Ptr("2,3"),
CommitEvents: Ptr(true),
MergeRequestsEvents: Ptr(true),
CommentOnEventEnabled: Ptr(true),
IssuesEnabled: Ptr(true),
ProjectKeys: Ptr([]string{"as"}),
UseInheritedSettings: Ptr(true),
}

_, err := client.Services.SetJiraService(1, opt)
if err != nil {
t.Fatalf("Services.SetJiraService returns an error: %v", err)
}
}

func TestSetJiraServiceAuthTypeBasicAuth(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/services/jira", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
})

opt := &SetJiraServiceOptions{
URL: Ptr("asd"),
Username: Ptr("aas"),
Password: Ptr("asd"),
JiraAuthType: Ptr(0),
}

_, err := client.Services.SetJiraService(1, opt)
if err != nil {
t.Fatalf("Services.SetJiraService returns an error: %v", err)
}
}

func TestSetJiraServiceAuthTypeTokenAuth(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/services/jira", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
})

opt := &SetJiraServiceOptions{
URL: Ptr("asd"),
Password: Ptr("asd"),
JiraAuthType: Ptr(1),
}

_, err := client.Services.SetJiraService(1, opt)
Expand Down

0 comments on commit e43897f

Please sign in to comment.