persian-captcha-generator
Version:
A library for generating customizable captchas with Persian numbers and alphabets using node-canvas.
33 lines (32 loc) • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
describe("Captcha Generator", () => {
it("should generate a captcha with Persian numbers", async () => {
const captcha = await (0, index_1.persianCaptchaGenerator)({
length: 6,
characterSet: "numbers",
});
expect(captcha.text).toHaveLength(6);
expect(captcha.text).toMatch(/^[۰-۹]+$/);
expect(Buffer.isBuffer(captcha.imageBuffer)).toBe(true);
});
it("should generate a captcha with Persian alphabets", async () => {
const captcha = await (0, index_1.persianCaptchaGenerator)({
length: 6,
characterSet: "alphabets",
});
expect(captcha.text).toHaveLength(6);
expect(captcha.text).toMatch(/^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنهوی]+$/);
expect(Buffer.isBuffer(captcha.imageBuffer)).toBe(true);
});
it("should generate a captcha with both Persian numbers and alphabets", async () => {
const captcha = await (0, index_1.persianCaptchaGenerator)({
length: 6,
characterSet: "both",
});
expect(captcha.text).toHaveLength(6);
expect(captcha.text).toMatch(/^[۰-۹ابپتثجچحخدذرزژسشصضطظعغفقکگلمنهوی]+$/);
expect(Buffer.isBuffer(captcha.imageBuffer)).toBe(true);
});
});