54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
|
import { slugify, formatCentsToCurrency } from "../src/kijiji";
|
|
|
|
describe("Utility Functions", () => {
|
|
describe("slugify", () => {
|
|
test("should convert basic strings to slugs", () => {
|
|
expect(slugify("Hello World")).toBe("hello-world");
|
|
expect(slugify("iPhone 13 Pro")).toBe("iphone-13-pro");
|
|
});
|
|
|
|
test("should handle special characters", () => {
|
|
expect(slugify("Café & Restaurant")).toBe("cafe-restaurant");
|
|
expect(slugify("100% New")).toBe("100-new");
|
|
});
|
|
|
|
test("should handle empty and edge cases", () => {
|
|
expect(slugify("")).toBe("");
|
|
expect(slugify(" ")).toBe("-");
|
|
expect(slugify("---")).toBe("-");
|
|
});
|
|
|
|
test("should preserve numbers and valid characters", () => {
|
|
expect(slugify("iPhone 13")).toBe("iphone-13");
|
|
expect(slugify("item123")).toBe("item123");
|
|
});
|
|
});
|
|
|
|
describe("formatCentsToCurrency", () => {
|
|
test("should format valid cent values", () => {
|
|
expect(formatCentsToCurrency(100)).toBe("$1.00");
|
|
expect(formatCentsToCurrency(1999)).toBe("$19.99");
|
|
expect(formatCentsToCurrency(0)).toBe("$0.00");
|
|
});
|
|
|
|
test("should handle string inputs", () => {
|
|
expect(formatCentsToCurrency("100")).toBe("$1.00");
|
|
expect(formatCentsToCurrency("1999")).toBe("$19.99");
|
|
});
|
|
|
|
test("should handle null/undefined inputs", () => {
|
|
expect(formatCentsToCurrency(null)).toBe("");
|
|
expect(formatCentsToCurrency(undefined)).toBe("");
|
|
});
|
|
|
|
test("should handle invalid inputs", () => {
|
|
expect(formatCentsToCurrency("invalid")).toBe("");
|
|
expect(formatCentsToCurrency(Number.NaN)).toBe("");
|
|
});
|
|
|
|
test("should use en-US locale formatting", () => {
|
|
expect(formatCentsToCurrency(123456)).toBe("$1,234.56");
|
|
});
|
|
});
|
|
}); |