Skip to content

Commit

Permalink
Don't throw errors for duplicate tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier committed Aug 7, 2019
1 parent 459ef0b commit 8743450
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 4 additions & 1 deletion functions/post_tweet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"log"
"strings"

"github.com/City-Bureau/chi-bill-bot/pkg/svc"
"github.com/aws/aws-lambda-go/events"
Expand All @@ -26,7 +27,9 @@ func handler(request events.SNSEvent) error {
twttr := svc.NewTwitterClient()
err = twttr.PostTweet(data.Text, &data.Params)
if err != nil {
log.Fatal(err)
if !strings.Contains(err.Error(), "duplicate") {
log.Fatal(err)
}
}
return err
}
Expand Down
8 changes: 3 additions & 5 deletions functions/query_mentions/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import (
"github.com/stretchr/testify/mock"
)

const TIME_FORMAT = "Mon Jan 2 15:04:05 -0700 2006"

func TestQueryMentionsIgnoresEmptyBillID(t *testing.T) {
tweets := []twitter.Tweet{
twitter.Tweet{
ID: 1,
Text: "Testing bill",
User: &twitter.User{ScreenName: "testuser"},
CreatedAt: time.Now().Format(TIME_FORMAT),
CreatedAt: time.Now().Format(time.RubyDate),
},
}
twttrMock := new(mocks.TwitterMock)
Expand All @@ -35,7 +33,7 @@ func TestQueryMentionsIgnoresOldTweet(t *testing.T) {
ID: 1,
Text: "@chicagoledger O2010-11 Testing bill",
User: &twitter.User{ScreenName: "testuser"},
CreatedAt: time.Now().Add(time.Hour * -72).Format(TIME_FORMAT),
CreatedAt: time.Now().UTC().Add(time.Hour * -72).Format(time.RubyDate),
},
}
twttrMock := new(mocks.TwitterMock)
Expand All @@ -53,7 +51,7 @@ func TestQueryMentionsTweetsBill(t *testing.T) {
ID: 1,
Text: "@chicagoledger O2010-11 Testing bill",
User: &twitter.User{ScreenName: "testuser"},
CreatedAt: time.Now().Format(TIME_FORMAT),
CreatedAt: time.Now().Format(time.RubyDate),
},
}
twttrMock := new(mocks.TwitterMock)
Expand Down

0 comments on commit 8743450

Please sign in to comment.