Fix PocketBase date format - use YYYY-MM-DD instead of ISO
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
PocketBase filters don't accept ISO format with T separator (causes 400). Changed both garmin-sync storage and today route query to use simple YYYY-MM-DD format, matching the working /api/history pattern. TDD approach: wrote failing tests first, then implemented the fix. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,9 @@ let currentMockUser: User | null = null;
|
||||
// Module-level variable to control mock daily log in tests
|
||||
let currentMockDailyLog: DailyLog | null = null;
|
||||
|
||||
// Track the filter string passed to getFirstListItem
|
||||
let lastDailyLogFilter: string | null = null;
|
||||
|
||||
// Create mock PocketBase client
|
||||
const mockPb = {
|
||||
collection: vi.fn((collectionName: string) => ({
|
||||
@@ -30,7 +33,11 @@ const mockPb = {
|
||||
}
|
||||
throw new Error("Record not found");
|
||||
}),
|
||||
getFirstListItem: vi.fn(async () => {
|
||||
getFirstListItem: vi.fn(async (filter: string) => {
|
||||
// Capture the filter for testing
|
||||
if (collectionName === "dailyLogs") {
|
||||
lastDailyLogFilter = filter;
|
||||
}
|
||||
if (!currentMockDailyLog) {
|
||||
const error = new Error("No DailyLog found");
|
||||
(error as { status?: number }).status = 404;
|
||||
@@ -100,6 +107,7 @@ describe("GET /api/today", () => {
|
||||
vi.clearAllMocks();
|
||||
currentMockUser = null;
|
||||
currentMockDailyLog = null;
|
||||
lastDailyLogFilter = null;
|
||||
// Mock current date to 2025-01-10 for predictable testing
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2025-01-10T12:00:00Z"));
|
||||
@@ -508,6 +516,24 @@ describe("GET /api/today", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("dailyLog query", () => {
|
||||
it("queries dailyLogs with YYYY-MM-DD date format using contains operator", async () => {
|
||||
// PocketBase filters don't accept ISO format with T separator
|
||||
// Must use simple YYYY-MM-DD with ~ contains operator
|
||||
currentMockUser = createMockUser();
|
||||
currentMockDailyLog = createMockDailyLog();
|
||||
|
||||
await GET(mockRequest);
|
||||
|
||||
// Verify filter uses YYYY-MM-DD format (2025-01-10) not ISO format
|
||||
// The filter should use ~ contains operator, not >= range
|
||||
expect(lastDailyLogFilter).toBeDefined();
|
||||
expect(lastDailyLogFilter).toContain('date~"2025-01-10"');
|
||||
// Should NOT contain ISO format with T separator
|
||||
expect(lastDailyLogFilter).not.toContain("T");
|
||||
});
|
||||
});
|
||||
|
||||
describe("biometrics data", () => {
|
||||
it("returns biometrics from daily log when available", async () => {
|
||||
currentMockUser = createMockUser();
|
||||
|
||||
Reference in New Issue
Block a user