|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | + |
| 3 | +import type { ReportFormatMetadata } from './reportAdapters' |
| 4 | +import { |
| 5 | + NATIVE_AI_CREDITS_STANDARD_INCLUDED_CREDITS_POLICY, |
| 6 | + NATIVE_AI_CREDITS_SUMMER_PROMO_INCLUDED_CREDITS_POLICY, |
| 7 | + TRANSITION_PERIOD_INCLUDED_CREDITS_POLICY, |
| 8 | + resolveIncludedCreditsPolicy, |
| 9 | +} from './includedCreditsPolicy' |
| 10 | + |
| 11 | +const TRANSITION_PERIOD_REPORT_METADATA = { |
| 12 | + format: 'transition-period-billing-preview', |
| 13 | + label: 'Transition Period Billing Preview report', |
| 14 | + supported: true, |
| 15 | +} satisfies ReportFormatMetadata |
| 16 | + |
| 17 | +const NATIVE_AI_CREDITS_REPORT_METADATA = { |
| 18 | + format: 'native-ai-credits', |
| 19 | + label: 'Native AI Credits report', |
| 20 | + supported: false, |
| 21 | +} satisfies ReportFormatMetadata |
| 22 | + |
| 23 | +describe('resolveIncludedCreditsPolicy', () => { |
| 24 | + it('returns the transition-period billing preview policy for transition reports', () => { |
| 25 | + expect(resolveIncludedCreditsPolicy(TRANSITION_PERIOD_REPORT_METADATA)).toBe( |
| 26 | + TRANSITION_PERIOD_INCLUDED_CREDITS_POLICY, |
| 27 | + ) |
| 28 | + expect(resolveIncludedCreditsPolicy('transition-period-billing-preview', { |
| 29 | + startDate: '2026-09-01', |
| 30 | + endDate: '2026-09-30', |
| 31 | + })).toBe(TRANSITION_PERIOD_INCLUDED_CREDITS_POLICY) |
| 32 | + }) |
| 33 | + |
| 34 | + it('returns the native AI Credits summer promo policy for native report periods before September 2026', () => { |
| 35 | + expect(resolveIncludedCreditsPolicy(NATIVE_AI_CREDITS_REPORT_METADATA, { |
| 36 | + startDate: '2026-06-01', |
| 37 | + endDate: '2026-06-30', |
| 38 | + })).toBe(NATIVE_AI_CREDITS_SUMMER_PROMO_INCLUDED_CREDITS_POLICY) |
| 39 | + }) |
| 40 | + |
| 41 | + it('uses period start to keep native report periods starting on 2026-08-31 in the summer promo policy', () => { |
| 42 | + expect(resolveIncludedCreditsPolicy(NATIVE_AI_CREDITS_REPORT_METADATA, { |
| 43 | + startDate: '2026-08-31', |
| 44 | + endDate: '2026-09-30', |
| 45 | + })).toBe(NATIVE_AI_CREDITS_SUMMER_PROMO_INCLUDED_CREDITS_POLICY) |
| 46 | + }) |
| 47 | + |
| 48 | + it('returns the native AI Credits standard policy for native report periods starting on 2026-09-01 onward', () => { |
| 49 | + expect(resolveIncludedCreditsPolicy(NATIVE_AI_CREDITS_REPORT_METADATA, { |
| 50 | + startDate: '2026-09-01', |
| 51 | + endDate: '2026-09-30', |
| 52 | + })).toBe(NATIVE_AI_CREDITS_STANDARD_INCLUDED_CREDITS_POLICY) |
| 53 | + expect(resolveIncludedCreditsPolicy(NATIVE_AI_CREDITS_REPORT_METADATA, { |
| 54 | + startDate: '2026-10-01', |
| 55 | + endDate: '2026-10-31', |
| 56 | + })).toBe(NATIVE_AI_CREDITS_STANDARD_INCLUDED_CREDITS_POLICY) |
| 57 | + }) |
| 58 | + |
| 59 | + it('defaults native AI Credits reports without a valid period start to the standard policy', () => { |
| 60 | + expect(resolveIncludedCreditsPolicy(NATIVE_AI_CREDITS_REPORT_METADATA)).toBe( |
| 61 | + NATIVE_AI_CREDITS_STANDARD_INCLUDED_CREDITS_POLICY, |
| 62 | + ) |
| 63 | + expect(resolveIncludedCreditsPolicy(NATIVE_AI_CREDITS_REPORT_METADATA, { |
| 64 | + endDate: '2026-08-31', |
| 65 | + })).toBe(NATIVE_AI_CREDITS_STANDARD_INCLUDED_CREDITS_POLICY) |
| 66 | + expect(resolveIncludedCreditsPolicy(NATIVE_AI_CREDITS_REPORT_METADATA, { |
| 67 | + startDate: '8/31/26', |
| 68 | + endDate: '2026-08-31', |
| 69 | + })).toBe(NATIVE_AI_CREDITS_STANDARD_INCLUDED_CREDITS_POLICY) |
| 70 | + }) |
| 71 | +}) |
0 commit comments