40 lines
2.0 KiB
TypeScript
40 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildApp } from "../src/app.js";
|
|
import { openDb } from "../src/db.js";
|
|
|
|
const auth = { authorization: "Bearer t0ken" };
|
|
const app = () => buildApp({ db: openDb(), apiToken: "t0ken" });
|
|
|
|
describe("vacancy-profiles", () => {
|
|
it("Scenario: Создание вакансии — описание отдельным полем", async () => {
|
|
const a = app();
|
|
const res = await a.inject({ method: "POST", url: "/api/vacancies", headers: auth, payload: {
|
|
title: "Оператор call-центра", description: "Работа в смену…", targetCount: 10,
|
|
requirements: [{ text: "продажи", weight: 8, mandatory: true }] } });
|
|
expect(res.statusCode).toBe(201);
|
|
const v = res.json();
|
|
expect(v.description).toBe("Работа в смену…");
|
|
expect(v.requirements[0]).toMatchObject({ text: "продажи", weight: 8, mandatory: true });
|
|
});
|
|
|
|
it("Scenario: Вакансия без названия", async () => {
|
|
const a = app();
|
|
const res = await a.inject({ method: "POST", url: "/api/vacancies", headers: auth, payload: { title: " ", targetCount: 1 } });
|
|
expect(res.statusCode).toBe(400);
|
|
expect((await a.inject({ method: "GET", url: "/api/vacancies", headers: auth })).json()).toEqual([]);
|
|
});
|
|
|
|
it("Scenario: Обязательное требование — вес вне диапазона", async () => {
|
|
const res = await app().inject({ method: "POST", url: "/api/vacancies", headers: auth, payload: {
|
|
title: "X", targetCount: 1, requirements: [{ text: "Опыт продаж", weight: 15, mandatory: true }] } });
|
|
expect(res.statusCode).toBe(400);
|
|
expect(res.json().error).toContain("от 1 до 10");
|
|
});
|
|
|
|
it("без токена — 401, /healthz открыт", async () => {
|
|
const a = app();
|
|
expect((await a.inject({ method: "GET", url: "/api/vacancies" })).statusCode).toBe(401);
|
|
expect((await a.inject({ method: "GET", url: "/healthz" })).statusCode).toBe(200);
|
|
});
|
|
});
|