71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import { normalizeEntitlement } from '../src/lib/entitlement-context'
|
|
|
|
describe('normalizeEntitlement', () => {
|
|
const now = new Date('2026-08-21T00:00:00Z')
|
|
|
|
it('free 계정은 광고 제거 권한을 만들지 않는다', () => {
|
|
const snapshot = normalizeEntitlement({
|
|
tier: 'free',
|
|
status: 'active',
|
|
provider: 'none',
|
|
payment_provider: 'none',
|
|
overage_credits: 50,
|
|
}, [{ feature: 'stt_transcribe', count: 3 }], [], now)
|
|
|
|
expect(snapshot.tier).toBe('free')
|
|
expect(snapshot.adFree).toBe(false)
|
|
expect(snapshot.overageCredits).toBe(50)
|
|
expect(snapshot.usageToday.stt_transcribe).toBe(3)
|
|
})
|
|
|
|
it('서버가 확인한 유효 paid period만 광고 제거 권한을 준다', () => {
|
|
const active = normalizeEntitlement({
|
|
tier: 'pro',
|
|
status: 'active',
|
|
provider: 'google_play',
|
|
payment_provider: 'google_play',
|
|
current_period_end: '2026-09-21T00:00:00Z',
|
|
}, [], [], now)
|
|
const expired = normalizeEntitlement({
|
|
tier: 'pro',
|
|
status: 'active',
|
|
provider: 'google_play',
|
|
payment_provider: 'google_play',
|
|
current_period_end: '2026-08-20T00:00:00Z',
|
|
}, [], [], now)
|
|
|
|
expect(active.adFree).toBe(true)
|
|
expect(expired.adFree).toBe(false)
|
|
})
|
|
|
|
it('취소된 선불 기간과 안전한 구매 요약을 보존한다', () => {
|
|
const snapshot = normalizeEntitlement({
|
|
tier: 'pro_plus',
|
|
status: 'canceled',
|
|
provider: 'google_play',
|
|
payment_provider: 'google_play',
|
|
current_period_end: '2026-09-21T00:00:00Z',
|
|
auto_renewing: false,
|
|
}, [], [{
|
|
id: 'purchase-1',
|
|
platform: 'google_play',
|
|
product_id: 'd3ro_voice_pro_plus_monthly',
|
|
purchase_state: 'cancelled',
|
|
purchase_at: '2026-08-21T00:00:00Z',
|
|
expires_at: '2026-09-21T00:00:00Z',
|
|
auto_renewing: false,
|
|
verified_at: '2026-08-21T00:01:00Z',
|
|
}, {
|
|
id: 'invalid-receipt',
|
|
platform: 'unknown',
|
|
product_id: 'unknown',
|
|
purchase_state: 'purchased',
|
|
verified_at: 'invalid',
|
|
}], now)
|
|
|
|
expect(snapshot.adFree).toBe(true)
|
|
expect(snapshot.autoRenewing).toBe(false)
|
|
expect(snapshot.purchases).toHaveLength(1)
|
|
expect(snapshot.purchases[0].productId).toBe('d3ro_voice_pro_plus_monthly')
|
|
})
|
|
})
|