feat: add daily report list preview
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user