From 83569881bf3e72b8ca76aec06ec49a2bb2c07fc4 Mon Sep 17 00:00:00 2001 From: sagar23sj Date: Mon, 21 Jun 2021 14:24:25 +0530 Subject: [PATCH 1/2] test-cases: Added test cases for JSON resource marshalling Added test cases for following change events : * ProjectChange * ProjectCardChange * ProjectColumnChange Adds Fixes to : #55 --- github/event_types_test.go | 91 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/github/event_types_test.go b/github/event_types_test.go index 986d9719f78..05fe4c159f1 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -103,3 +103,94 @@ func TestEditChange_Marshal_BaseChange(t *testing.T) { testJSONMarshal(t, u, want) } + +func TestProjectChange_Marshal_NameChange(t *testing.T) { + testJSONMarshal(t, &ProjectChange{}, "{}") + + NameFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("NameFrom"), + } + + u := &ProjectChange{ + Name: &NameFrom, + Body: nil, + } + + want := `{ + "name": { + "from": "NameFrom" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestProjectChange_Marshal_BodyChange(t *testing.T) { + testJSONMarshal(t, &ProjectChange{}, "{}") + + BodyFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("BodyFrom"), + } + + u := &ProjectChange{ + Name: nil, + Body: &BodyFrom, + } + + want := `{ + "body": { + "from": "BodyFrom" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestProjectCardChange_Marshal_NoteChange(t *testing.T) { + testJSONMarshal(t, &ProjectCardChange{}, "{}") + + NoteFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("NoteFrom"), + } + + u := &ProjectCardChange{ + Note: &NoteFrom, + } + + want := `{ + "note": { + "from": "NoteFrom" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestProjectColumnChange_Marshal_NameChange(t *testing.T) { + testJSONMarshal(t, &ProjectColumnChange{}, "{}") + + NameFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("NameFrom"), + } + + u := &ProjectColumnChange{ + Name: &NameFrom, + } + + want := `{ + "name": { + "from": "NameFrom" + } + }` + + testJSONMarshal(t, u, want) + +} From deeb3034b289cecacc79bca1bd6fadb605aaa07a Mon Sep 17 00:00:00 2001 From: sagar23sj Date: Mon, 21 Jun 2021 19:04:02 +0530 Subject: [PATCH 2/2] removed unnecessary blank line --- github/event_types_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/event_types_test.go b/github/event_types_test.go index 05fe4c159f1..347b5a3186c 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -192,5 +192,4 @@ func TestProjectColumnChange_Marshal_NameChange(t *testing.T) { }` testJSONMarshal(t, u, want) - }