Export reusable iconRef zod validator (set:<set>:<name> | brand:<slug> | null) and add it as an optional field to patchBody so PATCH /devices/:mac accepts icon. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
16 lines
593 B
JavaScript
16 lines
593 B
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { z } from 'zod';
|
|
import { iconRef } from '../../lib/api/routes/devices.js';
|
|
|
|
describe('icon ref validation', () => {
|
|
it('accepts set + brand refs and null', () => {
|
|
expect(iconRef.safeParse('set:devices:router').success).toBe(true);
|
|
expect(iconRef.safeParse('brand:apple').success).toBe(true);
|
|
expect(iconRef.safeParse(null).success).toBe(true);
|
|
});
|
|
it('rejects junk', () => {
|
|
expect(iconRef.safeParse('set:bad').success).toBe(false);
|
|
expect(iconRef.safeParse('javascript:alert').success).toBe(false);
|
|
});
|
|
});
|