mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 16:12:11 +00:00
fix(backups): preserve canonical restore identity
This commit is contained in:
1 parent
8b7cbddd72
commit
cd6b5f0cc6
10 files changed
+1722
-215
No files matched your search
@@ -18,7 +18,12 @@
|
||||
* of bubbling out of `prisma.createMany` with a useless message.
|
||||
*/
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { backupPayloadSchema, summarizeBackup } from "../backup";
|
||||
import {
|
||||
backupPayloadSchema,
|
||||
isCompatibleSchemaVersion,
|
||||
parseBackupPayload,
|
||||
summarizeBackup,
|
||||
} from "../backup";
|
||||
|
||||
const baseEntry = {
|
||||
date: "2026-05-08",
|
||||
@@ -384,6 +389,52 @@ describe("backupPayloadSchema — v1.28 backup-completeness domains", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("backupPayloadSchema — canonical v2 identity compatibility", () => {
|
||||
const base = {
|
||||
exportedAt: "2026-07-20T00:00:00.000Z",
|
||||
userId: "u1",
|
||||
};
|
||||
|
||||
it("treats an unversioned payload as legacy v1 and accepts measurements without ids", () => {
|
||||
const payload = parseBackupPayload({
|
||||
...base,
|
||||
measurements: [
|
||||
{
|
||||
type: "WEIGHT",
|
||||
value: 75,
|
||||
unit: "kg",
|
||||
measuredAt: "2026-07-19T07:00:00.000Z",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(payload.schemaVersion).toBe("1");
|
||||
expect(isCompatibleSchemaVersion(payload.schemaVersion)).toBe(true);
|
||||
});
|
||||
|
||||
it("requires stable measurement ids in canonical v2 payloads", () => {
|
||||
const result = backupPayloadSchema.safeParse({
|
||||
...base,
|
||||
schemaVersion: "2",
|
||||
measurements: [
|
||||
{
|
||||
type: "SLEEP_DURATION",
|
||||
value: 120,
|
||||
unit: "minutes",
|
||||
measuredAt: "2026-07-19T22:00:00.000Z",
|
||||
source: "IMPORT",
|
||||
sleepStage: "DEEP",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(isCompatibleSchemaVersion("1")).toBe(true);
|
||||
expect(isCompatibleSchemaVersion("2")).toBe(true);
|
||||
expect(isCompatibleSchemaVersion("3")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("backupPayloadSchema — database enum boundaries", () => {
|
||||
const enumPayload = {
|
||||
schemaVersion: "1",
|
||||
|
||||
Reference in new issue
Block a user