From 561e1de905357fbf9b7d3beee5fb0d411421fc8b Mon Sep 17 00:00:00 2001 From: smit-modi Date: Mon, 10 Apr 2023 14:36:29 -0700 Subject: [PATCH] Added TestCommitCommentEventUnmarshal --- event_webhook_types_test.go | 42 ++++++++++++++++++++++++++++++ testdata/webhooks/note_commit.json | 1 + 2 files changed, 43 insertions(+) diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go index 421e3c685..e9614c426 100644 --- a/event_webhook_types_test.go +++ b/event_webhook_types_test.go @@ -64,6 +64,48 @@ func TestBuildEventUnmarshal(t *testing.T) { } } +func TestCommitCommentEventUnmarshal(t *testing.T) { + jsonObject := loadFixture("testdata/webhooks/note_commit.json") + + var event *CommitCommentEvent + err := json.Unmarshal(jsonObject, &event) + if err != nil { + t.Errorf("Commit Comment Event can not unmarshaled: %v\n ", err.Error()) + } + + if event == nil { + t.Errorf("Commit Comment Event is null") + } + + if event.ObjectKind != string(NoteEventTargetType) { + t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, NoteEventTargetType) + } + + if event.EventType != "note" { + t.Errorf("EventType is %v, want %v", event.EventType, "note") + } + + if event.ProjectID != 5 { + t.Errorf("ProjectID is %v, want %v", event.ProjectID, 5) + } + + if event.User.ID != 42 { + t.Errorf("User ID is %d, want %d", event.User.ID, 42) + } + + if event.Repository.Name != "Gitlab Test" { + t.Errorf("Repository name is %v, want %v", event.Repository.Name, "Gitlab Test") + } + + if event.ObjectAttributes.NoteableType != "Commit" { + t.Errorf("NoteableType is %v, want %v", event.ObjectAttributes.NoteableType, "Commit") + } + + if event.Commit.Title != "Add submodule" { + t.Errorf("Issue title is %v, want %v", event.Commit.Title, "Add submodule") + } +} + func TestJobEventUnmarshal(t *testing.T) { jsonObject := loadFixture("testdata/webhooks/job.json") diff --git a/testdata/webhooks/note_commit.json b/testdata/webhooks/note_commit.json index cc268b3b4..a976b78fb 100644 --- a/testdata/webhooks/note_commit.json +++ b/testdata/webhooks/note_commit.json @@ -1,5 +1,6 @@ { "object_kind": "note", + "event_type": "note", "user": { "id": 42, "name": "User1",