learning_ai_common_plat/services/growth-service/src/modules/promos/promos.test.ts
saravanakumardb1 b94510aeb9 feat(services): add growth-service (invitations, referrals, promos)
- Copied as-is from learning_voice_ai_agent/services/growth-service
- 33 tests passing (vitest)
- Fastify 5 + Cosmos DB + Stripe + Zod
- Modules: invitations, referrals, promos
- Port 4001
2026-02-12 11:39:11 -08:00

81 lines
2.1 KiB
TypeScript

/**
* Unit tests for promos module — types + validation.
*/
import { describe, it, expect } from "vitest";
import { CreatePromoSchema } from "./types.js";
describe("CreatePromoSchema", () => {
it("accepts valid percent-off promo", () => {
const result = CreatePromoSchema.safeParse({
code: "SUMMER20",
percentOff: 20,
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.duration).toBe("once");
expect(result.data.currency).toBe("usd");
}
});
it("accepts valid amount-off promo", () => {
const result = CreatePromoSchema.safeParse({
code: "FLAT5",
amountOff: 500,
currency: "usd",
});
expect(result.success).toBe(true);
});
it("accepts repeating duration with months", () => {
const result = CreatePromoSchema.safeParse({
code: "REPEAT3",
percentOff: 10,
duration: "repeating",
durationInMonths: 3,
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.duration).toBe("repeating");
expect(result.data.durationInMonths).toBe(3);
}
});
it("accepts promo with max redemptions and expiry", () => {
const result = CreatePromoSchema.safeParse({
code: "LIMITED",
percentOff: 50,
maxRedemptions: 100,
expiresAt: "2026-12-31T23:59:59Z",
createdBy: "admin@lysnr.ai",
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.maxRedemptions).toBe(100);
expect(result.data.createdBy).toBe("admin@lysnr.ai");
}
});
it("rejects missing code", () => {
const result = CreatePromoSchema.safeParse({ percentOff: 20 });
expect(result.success).toBe(false);
});
it("rejects percent over 100", () => {
const result = CreatePromoSchema.safeParse({
code: "TOOMUCH",
percentOff: 101,
});
expect(result.success).toBe(false);
});
it("rejects invalid duration", () => {
const result = CreatePromoSchema.safeParse({
code: "BAD",
percentOff: 10,
duration: "weekly",
});
expect(result.success).toBe(false);
});
});