Files
HealthLog/src/lib/mood/__tests__/note-backfill.test.ts
T
Marc-André Bombeck 3ece95f192 chore(release): v1.4.30
Server-side prep for the next iOS TestFlight build. Five surfaces land together so the iOS engineer can pick them up in one cut-over: a locked externalId shape for daily-aggregated cumulative HealthKit rows, the SyncMode foundation columns + handshake + bulk-backfill endpoints, a first-class MoodEntry.note column that replaces the legacy tag-based workaround, a cross-source workout dedup helper, and two new MeasurementType enums plus the shared category overlay that drives the iOS permission picker and the future Insights nav.
2026-05-16 12:37:55 +02:00

61 lines
1.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { extractNoteAndSlimTags } from "../note-backfill";
describe("extractNoteAndSlimTags", () => {
it("extracts the first note:<text> entry and slims the tag array", () => {
expect(
extractNoteAndSlimTags(JSON.stringify(["coffee", "note:slept poorly", "workout"])),
).toEqual({
note: "slept poorly",
newTags: JSON.stringify(["coffee", "workout"]),
});
});
it("returns null tags when the slimmed array is empty", () => {
expect(extractNoteAndSlimTags(JSON.stringify(["note:lonely entry"]))).toEqual({
note: "lonely entry",
newTags: null,
});
});
it("returns note=null when no entry starts with note:", () => {
expect(extractNoteAndSlimTags(JSON.stringify(["coffee", "workout"]))).toEqual({
note: null,
newTags: JSON.stringify(["coffee", "workout"]),
});
});
it("extracts only the first note:... entry; further note-prefixed entries stay as tags", () => {
expect(
extractNoteAndSlimTags(JSON.stringify(["note:first", "note:second"])),
).toEqual({
note: "first",
newTags: JSON.stringify(["note:second"]),
});
});
it("returns the input string when it is not valid JSON", () => {
expect(extractNoteAndSlimTags("not-a-json-array")).toEqual({
note: null,
newTags: "not-a-json-array",
});
});
it("returns the input string when the JSON is not an array", () => {
expect(extractNoteAndSlimTags(JSON.stringify({ note: "x" }))).toEqual({
note: null,
newTags: JSON.stringify({ note: "x" }),
});
});
it("preserves the note prefix text exactly (no trim, no decode)", () => {
expect(
extractNoteAndSlimTags(JSON.stringify(["note: with leading space "])),
).toEqual({
note: " with leading space ",
newTags: null,
});
});
});