Viniciustda/OiTenta / .agents/skills/config-package-shared
config-package-shared
VerifiedReconstrói o pacote compartilhado base da aplicação, concentrando contratos reutilizáveis, classes base, erros de domínio, casos de uso e validações consumidas pelo backend, frontend e módulos de negócio.
assets/shared-template/test/validation/validator.test.ts
View on GitHubimport {
EmailRule,
MinLengthRule,
RangeLengthRule,
RequiredRule,
ValidationField,
ValidationException,
Validator,
} from "../../src/index";
describe("Validator", () => {
test("deve passar sem retornar nada quando nao houver erros", () => {
const fields: ValidationField[] = [
{
code: "name",
value: "John Doe",
rules: [new RequiredRule()],
},
{
code: "email",
value: "john@doe.com",
rules: [new RequiredRule(), new EmailRule()],
},
];
expect(Validator.validate(fields)).toBeUndefined();
});
test("deve agregar erros de varios campos em uma unica execucao", () => {
const fields: ValidationField[] = [
{
code: "id",
value: "",
rules: [new RequiredRule()],
},
{
code: "name",
value: "ab",
rules: [new RequiredRule(), new RangeLengthRule(3, 10)],
},
{
code: "email",
value: "email-invalido",
rules: [new RequiredRule(), new EmailRule()],
},
{
code: "description",
value: "curta",
rules: [new MinLengthRule(10)],
},
];
try {
Validator.validate(fields);
fail("era esperado lancar ValidationException");
} catch (error) {
expect(error).toBeInstanceOf(ValidationException);
expect(
(error as ValidationException).errors.map((item) => item.message),
).toEqual([
"id.required",
"name.range.length",
"email.invalid.email",
"description.min.length",
]);
}
});
test("deve acumular todos os erros de um mesmo campo", () => {
const fields: ValidationField[] = [
{
code: "email",
value: "abc",
rules: [new EmailRule(), new MinLengthRule(10)],
},
];
expect(() => Validator.validate(fields)).toThrow(ValidationException);
try {
Validator.validate(fields);
} catch (error) {
expect(
(error as ValidationException).errors.map((item) => item.message),
).toEqual(["email.invalid.email", "email.min.length"]);
}
});
});
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |