feat: add daily report list preview

This commit is contained in:
richjohnrambo
2026-08-27 10:08:03 +08:00
parent a0fc553c6f
commit b2e5097708
3 changed files with 39 additions and 2 deletions
+1
View File
@@ -7168,6 +7168,7 @@ func dailyReportListPayload(report types.DailyReport) map[string]any {
"report_id": report.ReportID,
"author_id": report.AuthorID.UserId(),
"report_date": report.ReportDate.Format("2006-01-02"),
"content_short": monthlyReportPreview(report.Content),
"status": report.Status,
"draft_updated_at": report.UpdatedAt.UTC().Format(time.RFC3339Nano),
"read_state": report.ReadState,
+36
View File
@@ -2419,6 +2419,42 @@ func TestServeIMDailyReportStatisticsAndReminders(t *testing.T) {
}
}
func TestServeIMDailyReportsListIncludesContentPreview(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
expectIMBearer(t, ctrl, "token-1", 7, 42)
oldDailyReports := store.DailyReports
now := time.Now().UTC().Round(time.Millisecond)
reports := &testDailyReportsStore{report: &types.DailyReport{
ReportID: "dr_test",
AuthorID: 42,
ReportDate: time.Date(2026, 8, 14, 0, 0, 0, 0, time.UTC),
Content: strings.Repeat("日报", 80),
Status: types.DailyReportStatusDraft,
ReadState: "unread",
Version: 1,
CreatedAt: now,
UpdatedAt: now,
}}
store.DailyReports = reports
defer func() { store.DailyReports = oldDailyReports }()
req := httptest.NewRequest(http.MethodGet, "/v1/im/reports/daily?scope=mine", nil)
req.Header.Set("Authorization", "Bearer token-1")
rec := httptest.NewRecorder()
serveIMDailyReports(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status: got %d, want %d; body=%s", rec.Code, http.StatusOK, rec.Body.String())
}
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
items := data["items"].([]any)
item := items[0].(map[string]any)
if item["content_short"] != strings.Repeat("日报", 60)+"..." {
t.Fatalf("unexpected daily report preview: %#v", item["content_short"])
}
}
func TestServeIMMonthlyReportsCreate(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()