From 841d4e559cebbb0d3c4ffc920d86e929777451fd Mon Sep 17 00:00:00 2001 From: BernhardBuckel <33808384+BernhardBuckel@users.noreply.github.com> Date: Sun, 4 Oct 2026 11:10:49 +0200 Subject: [PATCH] test(import): add a synthetic export.xml fixture for the origin marker The fixture is invented, in the shape Apple's DTD documents, and says so in its header and its file name. It shows the parser reads a file laid out like an export; it cannot show that Apple writes a custom metadata key verbatim. --- .../export-own-origin.synthetic.xml | 56 +++++++++++++++++++ .../apple-health-import-own-samples.test.ts | 29 ++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/fixtures/apple-health/export-own-origin.synthetic.xml diff --git a/tests/fixtures/apple-health/export-own-origin.synthetic.xml b/tests/fixtures/apple-health/export-own-origin.synthetic.xml new file mode 100644 index 000000000..aff5f87ac --- /dev/null +++ b/tests/fixtures/apple-health/export-own-origin.synthetic.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + diff --git a/tests/integration/apple-health-import-own-samples.test.ts b/tests/integration/apple-health-import-own-samples.test.ts index d97d0dda8..240cf7195 100644 --- a/tests/integration/apple-health-import-own-samples.test.ts +++ b/tests/integration/apple-health-import-own-samples.test.ts @@ -116,6 +116,35 @@ describe("a record HealthLog wrote itself (the origin marker)", () => { }); }); +describe("the synthetic export fixture", () => { + // `export-own-origin.synthetic.xml` is invented, in the shape Apple's DTD + // documents. It shows the parser reads a file laid out like an export; it + // cannot show that Apple writes a custom metadata key verbatim. + it("leaves out the two marked records and imports the other three", async () => { + const user = await prisma.user.create({ + data: { username: "own-fixture", email: "fx@example.test", role: "USER" }, + }); + const result = await streamParseExportXml({ + xmlPath: join( + process.cwd(), + "tests/fixtures/apple-health/export-own-origin.synthetic.xml", + ), + userId: user.id, + userTimezone: "Europe/Berlin", + prisma, + }); + const rows = await prisma.measurement.findMany({ + where: { userId: user.id, type: "WEIGHT", source: "APPLE_HEALTH" }, + orderBy: { measuredAt: "asc" }, + }); + expect(rows.map((r) => r.value)).toEqual([80.2, 80.4, 80.5]); + expect(result.writtenByHealthLog).toEqual({ + byMarker: 2, + matchedManual: 0, + }); + }); +}); + describe("a manual entry mirrored before the marker existed", () => { async function runAgainst( manual: { value: number; at: string; source?: "MANUAL" | "WITHINGS" },