import { buildFanavaranOtherPeoplePayload, pickFanavaranRecordId, pickLookupIdByCaption, splitPersianFullName, } from "./fanavaran-other-people"; describe("fanavaran other people (GEN.44)", () => { it("builds a civil-registry create payload from local case + user fields", () => { const payload = buildFanavaranOtherPeoplePayload( { nationalCode: "3392645966", birthday: "1364/09/01", fullName: "الهام مهدوی نیا", mobile: "9366666666", address: "گاندی ک نهم", cityName: "تهران", gender: "female", }, { cities: [{ Id: 9131, Caption: "تهران", IsActive: 1 }], gender: [ { Id: 26, Caption: "مرد", IsActive: 1 }, { Id: 27, Caption: "زن", IsActive: 1 }, ], ans: [ { Id: 1, Caption: "بله", IsActive: 1 }, { Id: 0, Caption: "خیر", IsActive: 1 }, ], personKind: [{ Id: 46, Caption: "حقیقی", IsActive: 1 }], }, ); expect(payload).toMatchObject({ NationalCode: "3392645966", Name: "الهام", LastName: "مهدوی نیا", BirthYear: 1364, BirthMonth: 9, BirthDay: 1, Mobile: "09366666666", Address: "گاندی ک نهم", CityId: 9131, GenderId: 27, IsIranian: 1, PersonKindId: 46, ADBirthYear: null, NationalityId: null, }); }); it("returns null when national code or birthday is missing", () => { expect( buildFanavaranOtherPeoplePayload({ nationalCode: "3392645966", }), ).toBeNull(); }); it("picks the created person Id from a wrapped Fanavaran response", () => { expect(pickFanavaranRecordId({ data: { Id: 4553876 } })).toBe(4553876); expect(pickFanavaranRecordId([{ Id: "4553876" }])).toBe(4553876); }); it("matches lookup captions ignoring yeh/keheh and extra spaces", () => { expect( pickLookupIdByCaption( [{ Id: 701, Caption: "ايران", IsActive: 1 }], ["ایران"], ), ).toBe(701); }); it("splits a Persian full name into first and last name", () => { expect(splitPersianFullName("الهام مهدوی نیا")).toEqual({ name: "الهام", lastName: "مهدوی نیا", }); }); });