Skip to content

test(campaign): add route/controller tests for POST /api/v1/campaigns - #84

Open
Chrisland-ui wants to merge 1 commit into
Fundable-Protocol:devfrom
Chrisland-ui:feat/campaign-route-controller-tests-67
Open

Chrisland-ui wants to merge 1 commit into
Fundable-Protocol:devfrom
Chrisland-ui:feat/campaign-route-controller-tests-67

Conversation

@Chrisland-ui

Copy link
Copy Markdown

Summary

Adds route/controller-level tests for POST /api/v1/campaigns covering 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.ts

Tests 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 with campaignRoutes mounted, patches AppDataSource with in-memory repos, and uses CAIRO_MOCK=true — no real DB or chain connection required.

Auth tests (4)

  • 401 AUTH_MISSING_TOKEN — no Authorization header
  • 401 AUTH_INVALID_TOKEN — malformed JWT
  • 401 AUTH_INVALID_TOKEN — token signed with wrong secret
  • 401 AUTH_INVALID_TOKEN — token with no user identifier claim

Validation tests (6)

  • 400 VALIDATION_ERROR — missing campaign_ref
  • 400 VALIDATION_ERROR — campaign_ref not exactly 5 characters
  • 400 VALIDATION_ERROR — missing target_amount
  • 400 VALIDATION_ERROR — target_amount is zero
  • 400 VALIDATION_ERROR — donation_token not a valid Starknet address
  • 400 VALIDATION_ERROR — title exceeds 255 characters

DB and service error tests (4)

  • 500 DB_NOT_READY — AppDataSource.isInitialized is false
  • 400 WALLET_NOT_FOUND — wallet address from JWT not in the wallet repo
  • 400 INSUFFICIENT_BALANCE — wallet exists but balance is zero
  • 409 DUPLICATE_CAMPAIGN_REF — campaign_ref already has a completed campaign

Success tests (2)

  • 201 — verifies all required fields: campaign_id, campaign_ref, target_amount, donation_token, transaction_hash, created_at (valid ISO string)
  • 201 — optional title is reflected in the response

Rate-limit tests (2)

  • 429 RATE_LIMITED after 5 requests from same user — verifies error.code, error.details.limit, and error.details.windowSeconds
  • Per-user key isolation — a second user's first request succeeds after the first user exhausts their budget

Closes

Closes #67

…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.
@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b72fb9f6-d922-4237-a039-d27e373f3848


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Chrisland-ui

Copy link
Copy Markdown
Author

@pragmaticAweds my boss please merge i really need the point

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.

Add campaign API route tests for auth, validation, and rate limits

1 participant