Skip to content

Commit

Permalink
Update for defaults on actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier committed Jul 24, 2019
1 parent 1833de9 commit e172882
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion functions/update_bill/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/models/bill.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions pkg/models/bill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) {
Expand Down

0 comments on commit e172882

Please sign in to comment.