Repository navigation
test(campaign): add route/controller tests for POST /api/v1/campaigns - #84
Chrisland-ui wants to merge 1 commit into
Conversation
…Fundable-Protocol#67) - Cover auth: missing token, malformed token, wrong secret, no user id claim - Cover validation: missing/wrong-length campaign_ref, missing/zero target_amount, invalid donation_token, title exceeding 255 chars - Cover DB_NOT_READY (500) when AppDataSource is not initialized - Cover service errors: WALLET_NOT_FOUND (400), INSUFFICIENT_BALANCE (400), DUPLICATE_CAMPAIGN_REF (409) - Cover successful creation (201) verifying all response fields: campaign_id, campaign_ref, title, target_amount, donation_token, transaction_hash, created_at - Cover rate-limit: 429 RATE_LIMITED after 5 requests from same user, verifying error shape with limit and windowSeconds details - Cover rate-limit key isolation: separate users get independent budgets All tests use CAIRO_MOCK=true, patched AppDataSource, and in-memory repos. No real DB or chain connection is required.
|
@Chrisland-ui Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@pragmaticAweds my boss please merge i really need the point |
|
@pragmaticAweds my boss please merge i will be very grateful sirrrr |
Summary
Adds route/controller-level tests for
POST /api/v1/campaignscovering the full request pipeline: JWT auth middleware, rate limiting, Zod validation, mocked service dependencies, and the success response shape.What was implemented
Test file:
src/__tests__/campaign.controller.test.tsTests use Node's built-in test runner and follow the same full-HTTP-server pattern as
donation.controller.test.ts. Each test spins up an Express app withcampaignRoutesmounted, patchesAppDataSourcewith in-memory repos, and usesCAIRO_MOCK=true— no real DB or chain connection required.Auth tests (4)
401 AUTH_MISSING_TOKEN— noAuthorizationheader401 AUTH_INVALID_TOKEN— malformed JWT401 AUTH_INVALID_TOKEN— token signed with wrong secret401 AUTH_INVALID_TOKEN— token with no user identifier claimValidation tests (6)
400 VALIDATION_ERROR— missingcampaign_ref400 VALIDATION_ERROR—campaign_refnot exactly 5 characters400 VALIDATION_ERROR— missingtarget_amount400 VALIDATION_ERROR—target_amountis zero400 VALIDATION_ERROR—donation_tokennot a valid Starknet address400 VALIDATION_ERROR—titleexceeds 255 charactersDB and service error tests (4)
500 DB_NOT_READY—AppDataSource.isInitializedis false400 WALLET_NOT_FOUND— wallet address from JWT not in the wallet repo400 INSUFFICIENT_BALANCE— wallet exists but balance is zero409 DUPLICATE_CAMPAIGN_REF—campaign_refalready has a completed campaignSuccess tests (2)
201— verifies all required fields:campaign_id,campaign_ref,target_amount,donation_token,transaction_hash,created_at(valid ISO string)201— optionaltitleis reflected in the responseRate-limit tests (2)
429 RATE_LIMITEDafter 5 requests from same user — verifieserror.code,error.details.limit, anderror.details.windowSecondsCloses
Closes #67