Skip to content

feat: add cost estimation API and service tests - #1036

Open
Chideraakude wants to merge 1 commit into
StellerCraft:mainfrom
Chideraakude:feat/template-complexity-scoring
Open

feat: add cost estimation API and service tests#1036
Chideraakude wants to merge 1 commit into
StellerCraft:mainfrom
Chideraakude:feat/template-complexity-scoring

Conversation

@Chideraakude

Copy link
Copy Markdown
Contributor

#closes
#756

PR Documentation
Summary
Adds predictive deployment cost estimation based on template complexity for CRAFT. The new feature calculates per-deployment estimates using Soroban contract invocation count, enabled customization features, and estimated Vercel compute usage.

Motivation
Users need realtime cost feedback as they configure deployment templates, and the platform needs billing predictions that better align with Stripe charges.

What changed
cost-estimation.service.ts

Enhanced the cost estimation logic with:
Soroban contract invocation scoring
enabled feature scoring
fractional Vercel compute cost handling
Preserved tiered base costs while adding complexity-driven estimate components
route.ts

Maintains realtime cost estimation during customization preview updates
route.ts

Exposes GET /api/deployments/[id]/estimate-cost
Uses deployment customization config and optional query params:
tier
vercelComputeHours
Tests added / updated
cost-estimation.service.test.ts

Validates complexity scoring composition
Verifies premium estimate behavior
Adds a reconciliation accuracy regression fixture
route.test.ts

Validates estimate endpoint response and factors
route.test.ts

Ensures preview updates continue to return cost estimates
Adds auth-compatible next/headers cookie mocking for route tests
Verification
npm exec -- vitest run --config vitest.config.ts src/services/billing/cost-estimation.service.test.ts src/app/api/deployments/[id]/estimate-cost/route.test.ts src/app/api/preview/update/route.test.ts
Result: 15 passed

#closes

- Implemented GET endpoint for estimating deployment costs with user authentication.
- Created a cost estimation service to calculate costs based on customization configurations and pricing tiers.
- Added unit tests for the cost estimation service to validate complexity score calculations and ensure estimates align with expected values.
- Included tests for various scenarios including standard and premium tiers, as well as billing reconciliation against known charges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant