- gti-scheduling-mcp: MCP server com ZProAdapter e KlingoAdapter (agendar() completo pros dois) - Workflow n8n 'Agendamento - GChat - Z-PRO': webhook -> AI Agent -> MCP -> Z-PRO, testado com sucesso real - Documentacao: specs, plano, runbook de problemas reais e export do workflow Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
107 lines
2.7 KiB
TypeScript
107 lines
2.7 KiB
TypeScript
/**
|
|
* test/analyze.test.ts
|
|
*
|
|
* Testes unitários para a identificação da estrutura de uma resposta JSON.
|
|
*/
|
|
|
|
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { analyzeStructure } from "../src/diagnostics/analyze.js";
|
|
|
|
describe("analyzeStructure", () => {
|
|
it("descreve a raiz quando é um objeto", () => {
|
|
const summary = analyzeStructure({
|
|
data: [],
|
|
message: "ok",
|
|
});
|
|
|
|
assert.equal(summary.rootType, "object");
|
|
assert.deepEqual(summary.rootKeys.sort(), ["data", "message"]);
|
|
assert.equal(summary.arrayItemCount, undefined);
|
|
});
|
|
|
|
it("descreve um array: quantidade de itens, chaves e tipos do primeiro item", () => {
|
|
const summary = analyzeStructure([
|
|
{
|
|
id: "app-1",
|
|
status: "confirmed",
|
|
patient: { name: "Maria" },
|
|
startAt: "2026-04-15T14:00:00.000Z",
|
|
},
|
|
]);
|
|
|
|
assert.equal(summary.rootType, "array");
|
|
assert.equal(summary.arrayItemCount, 1);
|
|
assert.deepEqual(summary.firstItemKeys.sort(), [
|
|
"id",
|
|
"patient",
|
|
"startAt",
|
|
"status",
|
|
]);
|
|
assert.deepEqual(summary.fieldTypes, {
|
|
id: "string",
|
|
status: "string",
|
|
patient: "object",
|
|
startAt: "string",
|
|
});
|
|
});
|
|
|
|
it("detecta possíveis campos de paginação", () => {
|
|
const summary = analyzeStructure({
|
|
page: 1,
|
|
limit: 20,
|
|
totalCount: 42,
|
|
items: [],
|
|
});
|
|
|
|
assert.deepEqual(summary.possiblePaginationFields.sort(), [
|
|
"limit",
|
|
"page",
|
|
"totalCount",
|
|
]);
|
|
});
|
|
|
|
it("detecta possíveis campos de identificação", () => {
|
|
const summary = analyzeStructure({
|
|
id: "x",
|
|
appointmentId: "app-1",
|
|
uuid: "abc",
|
|
createdAt: "2026-04-15T14:00:00.000Z",
|
|
});
|
|
|
|
assert.deepEqual(summary.possibleIdFields.sort(), [
|
|
"appointmentId",
|
|
"id",
|
|
"uuid",
|
|
]);
|
|
});
|
|
|
|
it("detecta possíveis campos de data e de status", () => {
|
|
const summary = analyzeStructure({
|
|
createdAt: "2026-04-15T14:00:00.000Z",
|
|
startAt: "2026-04-15T14:00:00.000Z",
|
|
status: "pending",
|
|
state: "active",
|
|
});
|
|
|
|
assert.deepEqual(summary.possibleDateFields.sort(), [
|
|
"createdAt",
|
|
"startAt",
|
|
]);
|
|
assert.deepEqual(summary.possibleStatusFields.sort(), ["state", "status"]);
|
|
});
|
|
|
|
it("não inventa campos que não existem na resposta", () => {
|
|
const summary = analyzeStructure({
|
|
id: "x",
|
|
status: "ok",
|
|
});
|
|
|
|
assert.deepEqual(summary.possiblePaginationFields, []);
|
|
assert.deepEqual(summary.possibleDateFields, []);
|
|
assert.equal(summary.arrayItemCount, undefined);
|
|
assert.deepEqual(summary.firstItemKeys.sort(), ["id", "status"]);
|
|
});
|
|
});
|