C2 — Volunteer profile sliders (self_comfort; verified_level untouched)
Adds the user_skills record and slider save path so a volunteer can rate their own comfort without ever moving the verified level, which stays C3's to write.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { validateSelfComfort } from "./userSkills";
|
||||
|
||||
describe("validateSelfComfort", () => {
|
||||
it("accepts null (not yet rated)", () => {
|
||||
expect(validateSelfComfort(null)).toEqual([]);
|
||||
});
|
||||
|
||||
it("accepts the full 0..100 range", () => {
|
||||
expect(validateSelfComfort(0)).toEqual([]);
|
||||
expect(validateSelfComfort(50)).toEqual([]);
|
||||
expect(validateSelfComfort(100)).toEqual([]);
|
||||
});
|
||||
|
||||
it("rejects a value above 100", () => {
|
||||
expect(validateSelfComfort(101)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("rejects a negative value", () => {
|
||||
expect(validateSelfComfort(-1)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("rejects a non-integer", () => {
|
||||
expect(validateSelfComfort(42.5)).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Volunteer competency validation (ARCHITECTURE §4.3, unit C2). Pure — no DB,
|
||||
* no imports from `src/db`.
|
||||
*
|
||||
* `self_comfort` is the volunteer's own 0-100 rating. It is nullable (null =
|
||||
* not yet rated) and must be an integer in 0..100 when present. This never
|
||||
* touches `verified_level` — that is the gate, owned by C3.
|
||||
*/
|
||||
export function validateSelfComfort(value: number | null): string[] {
|
||||
const problems: string[] = [];
|
||||
if (value === null) return problems; // not yet rated — allowed
|
||||
if (!Number.isInteger(value) || value < 0 || value > 100) {
|
||||
problems.push("self_comfort must be an integer between 0 and 100");
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
Reference in New Issue
Block a user