admin/services/bookings.test.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

46 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { calculateCancellationPreview, resolveCancellationTicketPrice } from '@/services/bookings'
describe('booking cancellation preview', () => {
it('matches the backend floor-based commission formula', () => {
// 7% mirrors the platform default (backend/src/common/constants/business.constants.ts#COMMISSION_PERCENT);
// commissionPercent is always passed in from the booking's resolved rate, never hardcoded here.
expect(calculateCancellationPreview(101_000, 10, 7)).toEqual({
ticketPrice: 101_000,
platformCommission: 7_070,
commissionPercent: 7,
hostCancellationFee: 10_100,
refundToGuest: 83_830,
})
})
it('does not produce fractional Toman values', () => {
// A different rate here (5%) than the test above (7%) is deliberate — it
// exercises an event-level commission override, not just the platform default.
expect(calculateCancellationPreview(999, 7, 5)).toEqual({
ticketPrice: 999,
platformCommission: 49,
commissionPercent: 5,
hostCancellationFee: 69,
refundToGuest: 881,
})
})
it('uses post-discount paid amount so fees match refund.service gross', () => {
// List 10_000, discount 2_000 → paid 8_000; 7% + 10% → refund 6_640
expect(calculateCancellationPreview(8_000, 10, 7)).toEqual({
ticketPrice: 8_000,
platformCommission: 560,
commissionPercent: 7,
hostCancellationFee: 800,
refundToGuest: 6_640,
})
})
it('resolves ticket price from payableAmount when a discount was applied', () => {
expect(resolveCancellationTicketPrice({ eventPrice: 10_000, payableAmount: 8_000 })).toBe(8_000)
expect(resolveCancellationTicketPrice({ eventPrice: 10_000, payableAmount: null })).toBe(10_000)
})
})