feat: add cost estimation API and service tests - #1036
Open
Chideraakude wants to merge 1 commit into
Open
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#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