mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 23:33:29 +00:00
release: v1.32.0 — hardening and scalability (#580)
* release: prepare v1.32.0 * test: stabilize water capture re-entry
This commit is contained in:
1 parent
b01822be48
commit
62eb431d66
372 files changed
+25178
-8561
No files matched your search
@@ -17,6 +17,9 @@ import { NextRequest } from "next/server";
|
||||
|
||||
vi.mock("@/lib/db", () => ({
|
||||
prisma: {
|
||||
user: {
|
||||
update: vi.fn(),
|
||||
},
|
||||
measurement: {
|
||||
findMany: vi.fn(),
|
||||
createManyAndReturn: vi.fn(),
|
||||
|
||||
@@ -3,6 +3,9 @@ import { NextRequest } from "next/server";
|
||||
|
||||
vi.mock("@/lib/db", () => ({
|
||||
prisma: {
|
||||
user: {
|
||||
update: vi.fn(),
|
||||
},
|
||||
measurement: {
|
||||
findMany: vi.fn(),
|
||||
createManyAndReturn: vi.fn(),
|
||||
|
||||
@@ -12,6 +12,9 @@ const reconcileOverrideMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("@/lib/db", () => ({
|
||||
prisma: {
|
||||
user: {
|
||||
update: vi.fn(),
|
||||
},
|
||||
measurement: {
|
||||
findMany: vi.fn(),
|
||||
createManyAndReturn: vi.fn(),
|
||||
@@ -130,6 +133,7 @@ beforeEach(() => {
|
||||
externalId,
|
||||
}));
|
||||
}) as never);
|
||||
vi.mocked(prisma.user.update).mockResolvedValue({} as never);
|
||||
});
|
||||
|
||||
describe("POST /api/measurements/batch — PR detection enqueue (v1.4.25 W16c)", () => {
|
||||
@@ -142,6 +146,28 @@ describe("POST /api/measurements/batch — PR detection enqueue (v1.4.25 W16c)",
|
||||
});
|
||||
});
|
||||
|
||||
it("stamps HealthKit sync status after a durable Apple Health write", async () => {
|
||||
const res = await POST(makeRequest({ entries: [validStepEntry("ext-a")] }));
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(prisma.user.update).toHaveBeenCalledTimes(1);
|
||||
expect(prisma.user.update).toHaveBeenCalledWith({
|
||||
where: { id: "user-1" },
|
||||
data: { healthKitLastSyncedAt: expect.any(Date) },
|
||||
});
|
||||
});
|
||||
|
||||
it("does not stamp HealthKit sync status for a manual-only batch", async () => {
|
||||
const res = await POST(
|
||||
makeRequest({
|
||||
entries: [{ ...validStepEntry("ext-manual"), source: "MANUAL" }],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(prisma.user.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("surfaces a hard reconciliation failure without checkpointing it", async () => {
|
||||
reconcileOverrideMock.mockResolvedValueOnce({
|
||||
status: "failed",
|
||||
@@ -163,6 +189,7 @@ describe("POST /api/measurements/batch — PR detection enqueue (v1.4.25 W16c)",
|
||||
error: null,
|
||||
});
|
||||
expect(enqueuePrDetection).not.toHaveBeenCalled();
|
||||
expect(prisma.user.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sets silent=true once the batch crosses the 50-entry threshold", async () => {
|
||||
|
||||
@@ -571,6 +571,26 @@ async function postBatch(request: NextRequest): Promise<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
const healthKitSyncSucceeded =
|
||||
failedCount === 0 &&
|
||||
prepared.some((p) => {
|
||||
if ((p.entry.source ?? "APPLE_HEALTH") !== "APPLE_HEALTH") return false;
|
||||
const status = results[p.index]?.status;
|
||||
return (
|
||||
status === "inserted" || status === "updated" || status === "duplicate"
|
||||
);
|
||||
});
|
||||
|
||||
// This batch route is the native HealthKit ingestion boundary. Stamp only
|
||||
// after every attempted write has reached a durable, non-failed verdict;
|
||||
// MANUAL-only and skipped-only batches are not HealthKit syncs.
|
||||
if (healthKitSyncSucceeded) {
|
||||
await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { healthKitLastSyncedAt: new Date() },
|
||||
});
|
||||
}
|
||||
|
||||
const freshlyInsertedRows = insertedPrepared.map((p) => ({
|
||||
type: p.row.type as MeasurementType,
|
||||
measuredAt:
|
||||
|
||||
Reference in new issue
Block a user