Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: cover MortalLoom health export route (#6902)

[._.]/ Adam Eivy490f560c9111
diff --git a/server/routes/meatspaceExportRoutes.test.js b/server/routes/meatspaceExportRoutes.test.js
new file mode 100644
index 0000000000..775d0f7306
--- /dev/null
+++ b/server/routes/meatspaceExportRoutes.test.js
@@ -0,0 +1,67 @@
+import { describe, expect, it, vi, beforeEach } from 'vitest';
+import express from 'express';
+import { request } from '../lib/testHelper.js';
+import { errorMiddleware } from '../lib/errorHandler.js';
+
+vi.mock('../services/meatspaceDailyLog.js', () => ({ readLocalDailyLog: vi.fn() }));
+vi.mock('../services/meatspace.js', () => ({ getConfig: vi.fn() }));
+vi.mock('../services/meatspaceAlcohol.js', () => ({ getCustomDrinks: vi.fn() }));
+vi.mock('../services/meatspaceNicotine.js', () => ({ getCustomProducts: vi.fn() }));
+vi.mock('../services/meatspaceHealth.js', () => ({
+ getBloodTests: vi.fn(), getEpigeneticTests: vi.fn(), getEyeExams: vi.fn(),
+}));
+vi.mock('../services/identity.js', () => ({ getGoals: vi.fn() }));
+
+import meatspaceExportRoutes from './meatspaceExportRoutes.js';
+import { readLocalDailyLog } from '../services/meatspaceDailyLog.js';
+import { getConfig } from '../services/meatspace.js';
+import { getCustomDrinks } from '../services/meatspaceAlcohol.js';
+import { getCustomProducts } from '../services/meatspaceNicotine.js';
+import { getBloodTests, getEpigeneticTests, getEyeExams } from '../services/meatspaceHealth.js';
+import { getGoals } from '../services/identity.js';
+
+function makeApp() {
+ const app = express();
+ app.use('/api/meatspace', meatspaceExportRoutes);
+ app.use(errorMiddleware);
+ return app;
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ getConfig.mockResolvedValue({
+ birthDate: '1980-02-03', sex: 'female',
+ lifestyle: { smokingStatus: 'never', exerciseMinutesPerWeek: 180 },
+ });
+ getBloodTests.mockResolvedValue({ tests: [{ date: '2026-01-02', glucose: 91 }] });
+ getEpigeneticTests.mockResolvedValue({ tests: [{ date: '2026-01-03', chronologicalAge: 46, biologicalAge: 44 }] });
+ getEyeExams.mockResolvedValue({ exams: [{ date: '2026-01-04', leftSphere: -1.25 }] });
+ readLocalDailyLog.mockResolvedValue({ entries: [
+ { date: '2026-01-05', alcohol: { drinks: [{ name: 'Wine', oz: 5, abv: 13, count: 0 }] }, nicotine: { items: [{ product: 'gum', mgPerUnit: 2, count: 2 }] }, body: { weightLbs: 150, fatPct: 20 } },
+ ] });
+ getCustomDrinks.mockResolvedValue([{ name: 'Beer', oz: 12, abv: 5 }]);
+ getCustomProducts.mockResolvedValue([{ name: 'Patch', mgPerUnit: 7 }]);
+ getGoals.mockResolvedValue({ goals: [{ title: 'Run', description: 'Daily', status: 'active', urgency: 0.8, createdAt: '2026-01-01T12:00:00Z', checkIns: [{ date: '2026-01-05', value: 25 }], milestones: [{ title: 'Start', completedAt: null }] }] });
+});
+
+describe('GET /api/meatspace/export/mortalloom', () => {
+ it('aggregates configured health sources and daily entries into the export schema', async () => {
+ const response = await request(makeApp()).get('/api/meatspace/export/mortalloom');
+
+ expect(response.status).toBe(200);
+ expect(response.headers['content-disposition']).toContain('MortalLoom-export.json');
+ expect(response.body.profile).toMatchObject({ birthDate: '1980-02-03', biologicalSex: 'female' });
+ expect(response.body.profile.lifestyle).toMatchObject({ exerciseMinutesPerWeek: 180, sleepHoursPerNight: 7.5 });
+ expect(response.body.alcoholDrinks[0]).toMatchObject({ name: 'Wine', count: 1, date: '2026-01-05' });
+ expect(response.body.nicotineEntries[0]).toMatchObject({ product: 'gum', count: 2 });
+ expect(response.body.bloodTests[0]).toMatchObject({ date: '2026-01-02', markers: { glucose: 91 } });
+ expect(response.body.epigeneticTests[0]).toMatchObject({ chronologicalAge: 46, biologicalAge: 44, paceOfAging: null });
+ expect(response.body.eyeExams[0]).toMatchObject({ leftSphere: -1.25, rightSphere: null });
+ expect(response.body.bodyEntries).toEqual([{ id: expect.any(String), date: '2026-01-05', weightLbs: 150, bodyFatPct: 20 }]);
+ expect(response.body.goals[0]).toMatchObject({ title: 'Run', status: 'active', priority: 'high', checkInIntervalDays: 7 });
+ expect(getConfig).toHaveBeenCalledOnce();
+ expect(getBloodTests).toHaveBeenCalledOnce();
+ expect(getEpigeneticTests).toHaveBeenCalledOnce();
+ expect(getEyeExams).toHaveBeenCalledOnce();
+ });
+});