Files
waggle-os/packages/server/tests/local/identity.test.ts
shumeiko.it 16eaf01e14 chore: scrub personal names, maintainer URLs and local paths (P2.2)
Sample data in tests, prompts and UI placeholders uses Alex Morgan
instead of the maintainer's name; decision attributions say "owner".
Personal details in two test fixtures are replaced. Local paths
(D:/Projects/...) and paths into the maintainer's planning repository
are reworded. Clone and install URLs in CONTRIBUTING.md and the getting
started guide use placeholders until the public repository location is
decided (Q9). The Benchmarks page no longer names the maintainer's
hive-mind repository, and the upstream fixes log names the main Waggle
repository instead of an internal git host.
2026-11-01 00:50:13 +01:00

90 lines
3.2 KiB
TypeScript

// CC Sesija A §2.5 Task A15 — identity sidecar route smoke + shape tests.
//
// Brief: briefs/2026-04-30-cc-sesija-A-waggle-apps-web-integration.md §2.5 Task A15
//
// Validates the A1.1 follow-up route exports a plugin function and the
// placeholder shape it returns matches the contract Tauri command +
// adapter.getIdentity() expect.
import { describe, it, expect, afterEach } from 'vitest';
import Fastify from 'fastify';
import { WaggleDB } from '@waggle/core';
import { identityRoutes } from '../../src/local/routes/identity.js';
describe('POST /api/identity — merge-on-update', () => {
let db: WaggleDB;
let server: ReturnType<typeof Fastify>;
afterEach(async () => {
await server.close();
db.close();
});
function boot() {
db = new WaggleDB(':memory:');
server = Fastify({ logger: false });
server.decorate('waggleDb', db);
server.register(identityRoutes);
}
it('a partial write keeps the stored values for omitted fields', async () => {
boot();
const first = await server.inject({
method: 'POST', url: '/api/identity',
payload: { name: 'Alex', role: 'Founder', department: 'Egzakta' },
});
expect(first.statusCode).toBe(200);
// The onboarding wizard re-run sends name only — role/department must
// survive (the old `body.x ?? ''` semantics silently wiped them).
const partial = await server.inject({
method: 'POST', url: '/api/identity',
payload: { name: 'Alex M.' },
});
expect(partial.statusCode).toBe(200);
const body = partial.json();
expect(body.name).toBe('Alex M.');
expect(body.role).toBe('Founder');
expect(body.department).toBe('Egzakta');
});
it('an explicit empty string still clears a field', async () => {
boot();
await server.inject({
method: 'POST', url: '/api/identity',
payload: { name: 'Alex', role: 'Founder' },
});
const cleared = await server.inject({
method: 'POST', url: '/api/identity',
payload: { role: '' },
});
expect(cleared.json().role).toBe('');
expect(cleared.json().name).toBe('Alex');
});
});
describe('identity.ts route module', () => {
it('exports identityRoutes plugin function', async () => {
const mod = await import('../../src/local/routes/identity.js');
expect(mod.identityRoutes).toBeDefined();
expect(typeof mod.identityRoutes).toBe('function');
});
it('IdentityLayer is exported from @waggle/core for the route to consume', async () => {
const { IdentityLayer } = await import('@waggle/core');
expect(IdentityLayer).toBeDefined();
expect(typeof IdentityLayer).toBe('function'); // class constructor
});
it('IdentityLayer exposes the API the identity route uses', async () => {
const { IdentityLayer } = await import('@waggle/core');
// Verify the methods the route calls actually exist on the prototype —
// catches schema drift before the route fails at runtime in production.
const proto = IdentityLayer.prototype as Record<string, unknown>;
expect(typeof proto.exists).toBe('function');
expect(typeof proto.get).toBe('function');
expect(typeof proto.create).toBe('function');
expect(typeof proto.update).toBe('function');
});
});