mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 06:06:10 +00:00
fix(documents): date Papra search rows by their document date only
Papra's date: filter matches the document date, so a row now shows that date or none, and an undated document falls out of a date range in the list as it does on the server. Import still files an undated document under the day it was added.
This commit is contained in:
1 parent
bb5d0ab933
commit
656542b040
2 files changed
+69
-3
No files matched your search
@@ -402,6 +402,68 @@ describe("Papra, as it answers for real", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("dates a search row by its document date only, as Papra's date filter does", async () => {
|
||||
serve({
|
||||
"/api/organizations/org_a1b2c3d4e5f6g7h8i9j0k1l2/documents": () =>
|
||||
json({
|
||||
documentsCount: 2,
|
||||
documents: [
|
||||
{
|
||||
id: "doc_dated",
|
||||
name: "A.pdf",
|
||||
documentDate: "2024-05-01",
|
||||
createdAt: "2025-01-01T00:00:00.000Z",
|
||||
},
|
||||
{
|
||||
id: "doc_undated",
|
||||
name: "B.pdf",
|
||||
createdAt: "2025-01-01T00:00:00.000Z",
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
const all = await sourceClient(PAPRA).search({
|
||||
q: "",
|
||||
tagId: null,
|
||||
from: null,
|
||||
to: null,
|
||||
page: 1,
|
||||
});
|
||||
expect(all.items.map((i) => [i.sourceId, i.date])).toEqual([
|
||||
["doc_dated", "2024-05-01"],
|
||||
["doc_undated", null],
|
||||
]);
|
||||
const ranged = await sourceClient(PAPRA).search({
|
||||
q: "",
|
||||
tagId: null,
|
||||
from: "2024-01-01",
|
||||
to: "2025-12-31",
|
||||
page: 1,
|
||||
});
|
||||
// Papra's date: filter never matches a document without a document date;
|
||||
// the per-row check agrees instead of re-admitting it by upload day.
|
||||
expect(ranged.items.map((i) => i.sourceId)).toEqual(["doc_dated"]);
|
||||
});
|
||||
|
||||
it("still files an undated Papra document under the day it was added on import", async () => {
|
||||
serve({
|
||||
"/api/organizations/org_a1b2c3d4e5f6g7h8i9j0k1l2/documents/doc_undated":
|
||||
() =>
|
||||
json({
|
||||
document: {
|
||||
id: "doc_undated",
|
||||
name: "B.pdf",
|
||||
createdAt: "2025-01-01T09:00:00.000Z",
|
||||
},
|
||||
}),
|
||||
});
|
||||
await expect(
|
||||
sourceClient(PAPRA).document("doc_undated"),
|
||||
).resolves.toMatchObject({
|
||||
date: "2025-01-01",
|
||||
});
|
||||
});
|
||||
|
||||
it("refuses an organization id Papra would not issue", () => {
|
||||
for (const org of ["org_123", "../admin", "ORG_A1B2C3D4E5F6G7H8I9J0K1L2"]) {
|
||||
expect(() => sourceClient({ ...PAPRA, organizationId: org })).toThrow(
|
||||
@@ -471,6 +533,7 @@ describe("Papra", () => {
|
||||
name: "Blood test.pdf",
|
||||
originalName: "Blood test.pdf",
|
||||
originalSize: 1234,
|
||||
documentDate: "2025-03-04",
|
||||
createdAt: "2025-03-04T09:00:00.000Z",
|
||||
tags: [{ id: "tag_b", name: "Lab results" }],
|
||||
},
|
||||
|
||||
@@ -464,9 +464,12 @@ function papra(connection: SourceConnection): SourceClient {
|
||||
if (params.tagId && !tags.some((t) => asText(t.id) === params.tagId)) {
|
||||
continue;
|
||||
}
|
||||
// Papra's search date syntax differs between versions; the range is
|
||||
// applied here instead of trusting a query syntax.
|
||||
const date = dayOf(doc.documentDate) ?? dayOf(doc.createdAt);
|
||||
// The row shows the document date only, the field Papra's `date:`
|
||||
// filter reads, so the list and the filter agree: an undated document
|
||||
// shows no date and falls out of any range. The check below is the net
|
||||
// for a server that ignores the filter. The upload day is used only
|
||||
// on import, where a filing date is needed (see `document()`).
|
||||
const date = dayOf(doc.documentDate);
|
||||
if (!withinRange(date, params.from, params.to)) continue;
|
||||
const size = doc.originalSize;
|
||||
items.push({
|
||||
|
||||
Reference in new issue
Block a user