just testing the environment
Some checks failed
Tests / test (push) Has been cancelled

This commit is contained in:
tom.hempel
2026-05-20 07:10:08 +02:00
parent 2a11dfd0d1
commit 06fc134299
56 changed files with 1890 additions and 361 deletions

View File

@ -0,0 +1,28 @@
import { describe, it, expect } from 'vitest';
import { unwrap } from '../../js/api-envelope.js';
describe('unwrap', () => {
it('unwraps ok:true object data', () => {
const r = unwrap({ ok: true, data: { token: 'abc', role: 'admin' } });
expect(r.success).toBe(true);
expect(r.token).toBe('abc');
expect(r.role).toBe('admin');
});
it('unwraps ok:true array data as items', () => {
const r = unwrap({ ok: true, data: [{ id: 1 }] });
expect(r.success).toBe(true);
expect(r.items).toEqual([{ id: 1 }]);
});
it('unwraps ok:false errors', () => {
const r = unwrap({ ok: false, error: { code: 'X', message: 'Failed' } });
expect(r.success).toBe(false);
expect(r.error).toBe('Failed');
});
it('passes through legacy body', () => {
const legacy = { success: true, questionnaires: [] };
expect(unwrap(legacy)).toBe(legacy);
});
});