peppa/bench/tasks/04-new-field/repo/product/test/patients.test.mjs
2026-11-17 02:09:17 +05:00

36 lines
1.2 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { startApp } from "./helpers.mjs";
test("пациент добавляется и виден в списке", async () => {
const app = await startApp();
try {
const r = await fetch(`${app.url}/api/patients`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ name: "Иван Петров", phone: "+7 701 000 00 01" }),
});
assert.equal(r.status, 201);
const list = await (await fetch(`${app.url}/api/patients`)).json();
assert.equal(list[0].phone, "+77010000001");
assert.match(await (await fetch(`${app.url}/patients`)).text(), /Иван Петров/);
} finally {
app.stop();
}
});
test("без телефона — ошибка", async () => {
const app = await startApp();
try {
const r = await fetch(`${app.url}/api/patients`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ name: "Иван Петров" }),
});
assert.equal(r.status, 400);
assert.ok((await r.json()).errors.phone);
} finally {
app.stop();
}
});