85 lines
3.1 KiB
TypeScript
85 lines
3.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import {
|
||
DEFAULT_AVAILABLE_SLOTS,
|
||
buildPublicInvitationView,
|
||
getClientInvitationStateFromOrderStatus,
|
||
getOrderUpdateForDeliveryInvitationAction,
|
||
isInvitationExpired,
|
||
normalizeAvailableSlots,
|
||
} from "./delivery-invitations";
|
||
|
||
describe("delivery invitation helpers", () => {
|
||
it("maps invitation creation to awaiting customer response", () => {
|
||
expect(getOrderUpdateForDeliveryInvitationAction("create_delivery_invitation")).toEqual({
|
||
status: "Ожидает ответа клиента",
|
||
deliveryAgreementStatus: "Отправлено клиенту",
|
||
});
|
||
});
|
||
|
||
it("maps manual logistics transfer to the logistics handoff status", () => {
|
||
expect(getOrderUpdateForDeliveryInvitationAction("transfer_to_logistics")).toEqual({
|
||
status: "Передан логисту",
|
||
deliveryAgreementStatus: "Нет ответа",
|
||
});
|
||
});
|
||
|
||
it("derives public client state from the current order status", () => {
|
||
expect(getClientInvitationStateFromOrderStatus("Ожидает ответа клиента")).toBe("awaiting_choice");
|
||
expect(getClientInvitationStateFromOrderStatus("Передан логисту")).toBe("transferred_to_logistics");
|
||
expect(getClientInvitationStateFromOrderStatus("Платное хранение")).toBe("paid_storage");
|
||
expect(getClientInvitationStateFromOrderStatus("Доставлен")).toBe("delivered");
|
||
});
|
||
|
||
it("normalizes delivery slots and falls back to the default list", () => {
|
||
expect(normalizeAvailableSlots([" Утро ", "", "Вечер", "Утро"])).toEqual(["Утро", "Вечер"]);
|
||
expect(normalizeAvailableSlots([])).toEqual(DEFAULT_AVAILABLE_SLOTS);
|
||
});
|
||
|
||
it("marks expired and revoked invitations as inactive", () => {
|
||
expect(
|
||
isInvitationExpired({
|
||
order_id: "order-1",
|
||
token_hash: "token",
|
||
state: "awaiting_choice",
|
||
expires_at: "2026-04-01T00:00:00.000Z",
|
||
}, new Date("2026-04-02T00:00:00.000Z")),
|
||
).toBe(true);
|
||
|
||
expect(
|
||
isInvitationExpired({
|
||
order_id: "order-1",
|
||
token_hash: "token",
|
||
state: "awaiting_choice",
|
||
revoked_at: "2026-04-01T00:00:00.000Z",
|
||
}),
|
||
).toBe(true);
|
||
});
|
||
|
||
it("masks customer contact details in the public invitation view", () => {
|
||
const invitation = buildPublicInvitationView(
|
||
{
|
||
order_id: "order-1",
|
||
token_hash: "token",
|
||
state: "awaiting_choice",
|
||
customer_name: "Мария Волкова",
|
||
customer_phone: "+7 978 123-45-67",
|
||
order_number: "CD-240031",
|
||
available_slots: ["2026-04-15, До обеда"],
|
||
},
|
||
{
|
||
order_number: "CD-240031",
|
||
customer: {
|
||
name: "Мария Волкова",
|
||
phone: "+7 978 123-45-67",
|
||
items: [{ name: "Кухонный гарнитур", quantity: "1 комплект" }],
|
||
},
|
||
},
|
||
);
|
||
|
||
expect(invitation.customerName).toBe("Мария В.");
|
||
expect(invitation.customerPhone).toContain("***");
|
||
expect(invitation.orderStatus).toBeNull();
|
||
expect(invitation.deliveryAgreementStatus).toBeNull();
|
||
});
|
||
});
|