You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
package gitea |
|
|
|
import "testing" |
|
|
|
func TestPullRequestAssigned(t *testing.T) { |
|
body := []byte(`{ |
|
"action": "assigned", |
|
"repository": {"full_name": "team/repo"}, |
|
"sender": {"login": "alice"}, |
|
"pull_request": { |
|
"number": 7, "title": "Add feature", "html_url": "http://g/7", |
|
"user": {"login": "alice", "email": "alice@x.com"}, |
|
"assignees": [{"login": "bob", "email": "bob@x.com"}] |
|
} |
|
}`) |
|
notes, err := BuildNotifications("pull_request", body) |
|
if err != nil { |
|
t.Fatal(err) |
|
} |
|
if len(notes) != 1 || notes[0].Email != "bob@x.com" { |
|
t.Fatalf("expected one note to bob@x.com, got %+v", notes) |
|
} |
|
} |
|
|
|
func TestReviewRequested(t *testing.T) { |
|
body := []byte(`{ |
|
"action": "review_requested", |
|
"repository": {"full_name": "team/repo"}, |
|
"sender": {"login": "alice"}, |
|
"pull_request": {"number": 8, "title": "Fix", "html_url": "u"}, |
|
"requested_reviewer": {"login": "carol", "email": "carol@x.com"} |
|
}`) |
|
notes, _ := BuildNotifications("pull_request", body) |
|
if len(notes) != 1 || notes[0].Email != "carol@x.com" { |
|
t.Fatalf("expected note to carol@x.com, got %+v", notes) |
|
} |
|
} |
|
|
|
func TestIssueCommentExcludesCommenter(t *testing.T) { |
|
body := []byte(`{ |
|
"action": "created", |
|
"repository": {"full_name": "team/repo"}, |
|
"sender": {"login": "alice"}, |
|
"issue": { |
|
"number": 3, "title": "Bug", "html_url": "u", |
|
"user": {"login": "alice", "email": "alice@x.com"}, |
|
"assignees": [{"login": "bob", "email": "bob@x.com"}] |
|
}, |
|
"comment": {"body": "hi", "html_url": "u#c"} |
|
}`) |
|
notes, _ := BuildNotifications("issue_comment", body) |
|
if len(notes) != 1 || notes[0].Email != "bob@x.com" { |
|
t.Fatalf("expected only bob@x.com (alice is commenter), got %+v", notes) |
|
} |
|
} |
|
|
|
func TestUnhandledEvent(t *testing.T) { |
|
notes, _ := BuildNotifications("push", []byte(`{"repository":{"full_name":"t/r"}}`)) |
|
if len(notes) != 0 { |
|
t.Fatalf("expected no notes for push, got %+v", notes) |
|
} |
|
}
|
|
|