summaryrefslogtreecommitdiffstats
path: root/services/webhook
diff options
context:
space:
mode:
authoroliverpool <git@olivier.pfad.fr>2024-06-05 15:17:11 +0200
committeroliverpool <git@olivier.pfad.fr>2024-06-05 15:58:51 +0200
commit1013da463f4c84c55ba4f5672c916c0763aa89da (patch)
tree6c367258ed819406f9d7667686d949f14979a274 /services/webhook
parentMerge pull request 'test(avatar): deleting a user avatar is idempotent' (#402... (diff)
downloadforgejo-1013da463f4c84c55ba4f5672c916c0763aa89da.tar.xz
forgejo-1013da463f4c84c55ba4f5672c916c0763aa89da.zip
test: webhook open project expected fields
Diffstat (limited to 'services/webhook')
-rw-r--r--services/webhook/default_test.go36
-rw-r--r--services/webhook/general_test.go11
2 files changed, 47 insertions, 0 deletions
diff --git a/services/webhook/default_test.go b/services/webhook/default_test.go
index 29f1521cca..e6e59fed03 100644
--- a/services/webhook/default_test.go
+++ b/services/webhook/default_test.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/json"
webhook_module "code.gitea.io/gitea/modules/webhook"
+ jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -222,3 +223,38 @@ func TestForgejoPayload(t *testing.T) {
assert.Equal(t, "refs/heads/test", body.Ref) // full ref
})
}
+
+func TestOpenProjectPayload(t *testing.T) {
+ t.Run("PullRequest", func(t *testing.T) {
+ p := pullRequestTestPayload()
+ data, err := p.JSONPayload()
+ require.NoError(t, err)
+
+ // adapted from https://github.com/opf/openproject/blob/4c5c45fe995da0060902bc8dd5f1bf704d0b8737/modules/github_integration/lib/open_project/github_integration/services/upsert_pull_request.rb#L56
+ j := jsoniter.Get(data, "pull_request")
+
+ assert.Equal(t, 12, j.Get("id").MustBeValid().ToInt())
+ assert.Equal(t, "user1", j.Get("user", "login").MustBeValid().ToString())
+ assert.Equal(t, 12, j.Get("number").MustBeValid().ToInt())
+ assert.Equal(t, "http://localhost:3000/test/repo/pulls/12", j.Get("html_url").MustBeValid().ToString())
+ assert.Equal(t, jsoniter.NilValue, j.Get("updated_at").ValueType())
+ assert.Equal(t, "", j.Get("state").MustBeValid().ToString())
+ assert.Equal(t, "Fix bug", j.Get("title").MustBeValid().ToString())
+ assert.Equal(t, "fixes bug #2", j.Get("body").MustBeValid().ToString())
+
+ assert.Equal(t, "test/repo", j.Get("base", "repo", "full_name").MustBeValid().ToString())
+ assert.Equal(t, "http://localhost:3000/test/repo", j.Get("base", "repo", "html_url").MustBeValid().ToString())
+
+ assert.Equal(t, false, j.Get("draft").MustBeValid().ToBool())
+ assert.Equal(t, jsoniter.NilValue, j.Get("merge_commit_sha").ValueType())
+ assert.Equal(t, false, j.Get("merged").MustBeValid().ToBool())
+ assert.Equal(t, jsoniter.NilValue, j.Get("merged_by").ValueType())
+ assert.Equal(t, jsoniter.NilValue, j.Get("merged_at").ValueType())
+ assert.Equal(t, 0, j.Get("comments").MustBeValid().ToInt())
+ assert.Equal(t, 0, j.Get("review_comments").MustBeValid().ToInt())
+ assert.Equal(t, 0, j.Get("additions").MustBeValid().ToInt())
+ assert.Equal(t, 0, j.Get("deletions").MustBeValid().ToInt())
+ assert.Equal(t, 0, j.Get("changed_files").MustBeValid().ToInt())
+ // assert.Equal(t,"labels:", j.Get("labels").map { |values| extract_label_values(values) )
+ })
+}
diff --git a/services/webhook/general_test.go b/services/webhook/general_test.go
index 41bac3fd04..5b9bfdc1b2 100644
--- a/services/webhook/general_test.go
+++ b/services/webhook/general_test.go
@@ -281,6 +281,17 @@ func pullRequestTestPayload() *api.PullRequestPayload {
Title: "Milestone Title",
Description: "Milestone Description",
},
+ Base: &api.PRBranchInfo{
+ Name: "branch1",
+ Ref: "refs/pull/2/head",
+ Sha: "4a357436d925b5c974181ff12a994538ddc5a269",
+ RepoID: 1,
+ Repository: &api.Repository{
+ HTMLURL: "http://localhost:3000/test/repo",
+ Name: "repo",
+ FullName: "test/repo",
+ },
+ },
},
Review: &api.ReviewPayload{
Content: "good job",