check / check (push) Waiting to run
In the event log and on an event's page, attempts and deliveries showed no time, event times had no zone, and a replay looked like the original it repeated. Each attempt now shows when its result was recorded and each delivery when it was created, as how long ago with the full UTC time on hover, and the event log's event times read the same way. A delivery created by Replay records it in a new `replay` column and is labelled a replay in the event's summary line and its delivery list; replays made before this change are not labelled. A delivery's row is now drawn by one template, `delivery_row`, that both pages share. Model: opus-5-5
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package handlers_test
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"sneak.berlin/go/webhooker/internal/database"
|
|
)
|
|
|
|
// TestEventLog_TimesCarryTheirZone proves that the event log shows
|
|
// when an event arrived, and that it and the event's page show when
|
|
// each delivery was created and each attempt recorded: each as how
|
|
// long ago, with the full UTC time on hover.
|
|
func TestEventLog_TimesCarryTheirZone(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
f := newRecentEventsFixture(t)
|
|
target := seedTarget(t, f.db, f.webhook.ID, database.TargetTypeHTTP)
|
|
|
|
now := time.Now().UTC().Truncate(time.Second)
|
|
receivedAt := now.Add(-3 * time.Hour)
|
|
createdAt := now.Add(-90 * time.Minute)
|
|
ranAt := now.Add(-30 * time.Minute)
|
|
|
|
event := f.event(t, contentTypeJSON, "{}", receivedAt)
|
|
dlv := f.deliveryQueuedAt(
|
|
t, event, target.ID, database.DeliveryStatusDelivered, createdAt,
|
|
)
|
|
f.attempt(t, dlv, http.StatusOK, ranAt.Sub(createdAt))
|
|
|
|
w := serveEventPage(t, f.h, f.sess, f.webhook.ID, event.ID)
|
|
require.Equal(t, http.StatusOK, w.Code)
|
|
|
|
eventPage := w.Body.String()
|
|
eventLog := renderSourceLogsPage(t, f.h, f.sess, f.webhook.ID)
|
|
|
|
received := receivedAt.Format(time.DateTime)
|
|
assert.Contains(t, eventLog, `title="`+received+` UTC">3 hours ago</span>`)
|
|
assert.NotContains(t, eventLog, received+"</span>",
|
|
"an event's time must not be written without its zone")
|
|
assert.Contains(t, eventPage, received+" UTC")
|
|
|
|
for _, page := range []string{eventLog, eventPage} {
|
|
assert.Contains(t, page, `title="`+createdAt.Format(time.DateTime)+
|
|
` UTC">created 1 hour ago</span>`)
|
|
assert.Contains(t, page, `title="`+ranAt.Format(time.DateTime)+
|
|
` UTC">30 minutes ago</span>`)
|
|
}
|
|
}
|