From e1728822d65fadcdc72928eeb5f44ac5fe8ead2f Mon Sep 17 00:00:00 2001 From: pjsier Date: Wed, 24 Jul 2019 10:26:09 -0500 Subject: [PATCH] Update for defaults on actions --- functions/update_bill/main.go | 4 +++- pkg/models/bill.go | 3 +++ pkg/models/bill_test.go | 10 +++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/functions/update_bill/main.go b/functions/update_bill/main.go index 856a6a7..7fe440d 100644 --- a/functions/update_bill/main.go +++ b/functions/update_bill/main.go @@ -59,10 +59,12 @@ func handler(request events.SNSEvent) error { } // Get new data for bill, check if it's changed - _, _, actions, err := bill.FetchBillData() + title, cls, actions, err := bill.FetchBillData() if err != nil { return err } + bill.Title = title + bill.Classification = cls err = UpdateBill(bill, actions, snsClient) // Only log this error since it just prevented diff --git a/pkg/models/bill.go b/pkg/models/bill.go index 12d51dd..8a2dfc3 100644 --- a/pkg/models/bill.go +++ b/pkg/models/bill.go @@ -200,6 +200,9 @@ func (b *Bill) CreateTweet() string { actionText = " was adopted" case "Approved", "Repealed", "Vetoed", "Tabled", "Withdrawn": actionText = fmt.Sprintf("was %s", strings.ToLower(cls)) + case "": + default: + actionText = fmt.Sprintf(" %s", strings.ToLower(cls)) } tweetContent := fmt.Sprintf("%s%s.", billTitle, actionText) diff --git a/pkg/models/bill_test.go b/pkg/models/bill_test.go index fd899ee..2f50309 100644 --- a/pkg/models/bill_test.go +++ b/pkg/models/bill_test.go @@ -61,7 +61,7 @@ func TestSetNextRun(t *testing.T) { func TestCreateTweet(t *testing.T) { bill := Bill{ - Title: "Testing bill", + Title: "Testing bill", Classification: "Ordinance", URL: "https://chicago.legistar.com", BillID: "O201011", @@ -71,9 +71,13 @@ func TestCreateTweet(t *testing.T) { if bill.CreateTweet() != fmt.Sprintf("O2010-11: Testing bill. %s", tweetEnd) { t.Errorf("Tweet with no actions is incorrect: %s", bill.CreateTweet()) } - bill.Data = `[{"action": "fake"}]` + bill.Data = `[{"action": "Add Co-Sponsor(s)"}]` + if bill.CreateTweet() != fmt.Sprintf("O2010-11: Testing bill add co-sponsor(s). %s", tweetEnd) { + t.Errorf("Tweet with alternate action is incorrect: %s", bill.CreateTweet()) + } + bill.Data = `[{"action": ""}]` if bill.CreateTweet() != fmt.Sprintf("O2010-11: Testing bill. %s", tweetEnd) { - t.Errorf("Tweet with invalid action is incorrect: %s", bill.CreateTweet()) + t.Errorf("Tweet with empty action is incorrect: %s", bill.CreateTweet()) } bill.Data = `[{"action": "Introduced", "actor": "Chicago City Council"}]` if bill.CreateTweet() != fmt.Sprintf("O2010-11: Testing bill was introduced in Chicago City Council. %s", tweetEnd) {