Add Poll#LastUpdatedAt processing
This commit is contained in:
parent
ddb16c9e64
commit
ab89d53cc6
@ -22,7 +22,7 @@ type Poll struct {
|
|||||||
VotingDuration int // In seconds
|
VotingDuration int // In seconds
|
||||||
VotingEndsAt time.Time
|
VotingEndsAt time.Time
|
||||||
|
|
||||||
LastScrapedAt time.Time
|
LastUpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseAPIPoll(apiCard APICard) Poll {
|
func ParseAPIPoll(apiCard APICard) Poll {
|
||||||
@ -30,11 +30,16 @@ func ParseAPIPoll(apiCard APICard) Poll {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
last_updated_at, err := time.Parse(time.RFC3339, apiCard.BindingValues.LastUpdatedAt.StringValue)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
ret := Poll{}
|
ret := Poll{}
|
||||||
ret.NumChoices = parse_num_choices(apiCard.Name)
|
ret.NumChoices = parse_num_choices(apiCard.Name)
|
||||||
ret.VotingDuration = int_or_panic(apiCard.BindingValues.DurationMinutes.StringValue) * 60
|
ret.VotingDuration = int_or_panic(apiCard.BindingValues.DurationMinutes.StringValue) * 60
|
||||||
ret.VotingEndsAt = voting_ends_at
|
ret.VotingEndsAt = voting_ends_at
|
||||||
|
ret.LastUpdatedAt = last_updated_at
|
||||||
|
|
||||||
ret.Choice1 = apiCard.BindingValues.Choice1.StringValue
|
ret.Choice1 = apiCard.BindingValues.Choice1.StringValue
|
||||||
ret.Choice1_Votes = int_or_panic(apiCard.BindingValues.Choice1_Count.StringValue)
|
ret.Choice1_Votes = int_or_panic(apiCard.BindingValues.Choice1_Count.StringValue)
|
||||||
|
@ -30,6 +30,13 @@ func TestParsePoll2Choices(t *testing.T) {
|
|||||||
if poll.VotingEndsAt.Unix() != expected_ending {
|
if poll.VotingEndsAt.Unix() != expected_ending {
|
||||||
t.Errorf("Expected closing time %d, got %d", expected_ending, poll.VotingEndsAt.Unix())
|
t.Errorf("Expected closing time %d, got %d", expected_ending, poll.VotingEndsAt.Unix())
|
||||||
}
|
}
|
||||||
|
expected_last_updated := int64(1636318755)
|
||||||
|
if poll.LastUpdatedAt.Unix() != expected_last_updated {
|
||||||
|
t.Errorf("Expected last-updated time %d, got %d", expected_last_updated, poll.LastUpdatedAt.Unix())
|
||||||
|
}
|
||||||
|
if expected_last_updated > expected_ending {
|
||||||
|
t.Errorf("Last updated should be before poll closes!")
|
||||||
|
}
|
||||||
|
|
||||||
if poll.Choice1 != "Yes" || poll.Choice2 != "No" {
|
if poll.Choice1 != "Yes" || poll.Choice2 != "No" {
|
||||||
t.Errorf("Expected %q and %q, got %q and %q", "Yes", "No", poll.Choice1, poll.Choice2)
|
t.Errorf("Expected %q and %q, got %q and %q", "Yes", "No", poll.Choice1, poll.Choice2)
|
||||||
@ -64,6 +71,13 @@ func TestParsePoll4Choices(t *testing.T) {
|
|||||||
if poll.VotingEndsAt.Unix() != expected_ending {
|
if poll.VotingEndsAt.Unix() != expected_ending {
|
||||||
t.Errorf("Expected closing time %d, got %d", expected_ending, poll.VotingEndsAt.Unix())
|
t.Errorf("Expected closing time %d, got %d", expected_ending, poll.VotingEndsAt.Unix())
|
||||||
}
|
}
|
||||||
|
expected_last_updated := int64(1635966226)
|
||||||
|
if poll.LastUpdatedAt.Unix() != expected_last_updated {
|
||||||
|
t.Errorf("Expected last-updated time %d, got %d", expected_last_updated, poll.LastUpdatedAt.Unix())
|
||||||
|
}
|
||||||
|
if expected_last_updated < expected_ending {
|
||||||
|
t.Errorf("Last updated should be after poll closes!")
|
||||||
|
}
|
||||||
|
|
||||||
if poll.Choice1 != "Alec Baldwin" || poll.Choice1_Votes != 1669 {
|
if poll.Choice1 != "Alec Baldwin" || poll.Choice1_Votes != 1669 {
|
||||||
t.Errorf("Expected %q with %d, got %q with %d", "Alec Baldwin", 1669, poll.Choice1, poll.Choice1_Votes)
|
t.Errorf("Expected %q with %d, got %q with %d", "Alec Baldwin", 1669, poll.Choice1, poll.Choice1_Votes)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user