| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { strict as assert } from 'node:assert'; |
| import test from 'node:test'; |
|
|
| import { |
| analystDenialMessage, |
| isBillingVerificationDenial, |
| PRO_VERIFICATION_RETRY_MESSAGE, |
| } from '../src/services/analyst-denial.ts'; |
|
|
| test('a 503 carrying X-Billing-Verification is the retryable branch', () => { |
| assert.equal( |
| isBillingVerificationDenial(503, 'entitlement_verification_unavailable'), |
| true, |
| ); |
| assert.equal(isBillingVerificationDenial(503, 'renewal_verification_pending'), true); |
| assert.equal(isBillingVerificationDenial(503, 'renewal_verification_failed'), true); |
| }); |
|
|
| test('a 503 WITHOUT the header is not the billing branch', () => { |
| |
| |
| |
| assert.equal(isBillingVerificationDenial(503, null), false); |
| assert.equal(isBillingVerificationDenial(503, ''), false); |
| }); |
|
|
| test('the header alone does not make a non-503 retryable', () => { |
| |
| |
| assert.equal(isBillingVerificationDenial(403, 'subscription_lapsed'), false); |
| assert.equal(isBillingVerificationDenial(401, 'entitlement_verification_unavailable'), false); |
| assert.equal(isBillingVerificationDenial(200, 'entitlement_verification_unavailable'), false); |
| }); |
|
|
| test('verdict-to-copy mapping covers every PremiumDenialVerdict member', () => { |
| assert.equal(analystDenialMessage(401, 'sign_in_required'), 'Sign in to use the analyst.'); |
| assert.equal(analystDenialMessage(403, 'upgrade_required'), 'Pro subscription required.'); |
| assert.equal( |
| analystDenialMessage(403, 'access_denied'), |
| 'Analyst temporarily unavailable — try again in a moment.', |
| ); |
| }); |
|
|
| test('entitlement_desync shares copy with the billing-verification 503', () => { |
| |
| |
| assert.equal(analystDenialMessage(403, 'entitlement_desync'), PRO_VERIFICATION_RETRY_MESSAGE); |
| }); |
|
|
| test('an unclassified denial falls back to the bare status', () => { |
| assert.equal(analystDenialMessage(503, null), 'Error 503'); |
| assert.equal(analystDenialMessage(500, null), 'Error 500'); |
| }); |
|
|
| test('the retryable copy never tells a paying customer to subscribe', () => { |
| |
| |
| assert.notEqual(PRO_VERIFICATION_RETRY_MESSAGE, 'Pro subscription required.'); |
| assert.ok(!/subscri/i.test(PRO_VERIFICATION_RETRY_MESSAGE)); |
| }); |
|
|