Skip to content

test(plugins): add vitest test coverage for cron and resend plugins - #307

Open
RizulChauhan wants to merge 1 commit into
outerbase:mainfrom
RizulChauhan:test/cron-and-resend-plugins-coverage
Open

RizulChauhan wants to merge 1 commit into
outerbase:mainfrom
RizulChauhan:test/cron-and-resend-plugins-coverage

Conversation

@RizulChauhan

Copy link
Copy Markdown

/claim #71

Summary of Changes

Adds comprehensive Vitest unit test coverage for plugins/cron and plugins/resend without changing any production behavior:

  1. plugins/cron/utils.test.ts (6 tests):

    • Validates standard 5-part cron expressions and hourly parsing with cron-parser.
    • Tests timezone-resilient getNextExecutionTime calculation for interval and daily midnight triggers.
    • Tests error handling and rejection of malformed or out-of-range cron strings.
  2. plugins/cron/index.test.ts (6 tests):

    • Verifies CronPlugin initialization (name, pathPrefix, opts.requiresAuth).
    • Verifies register() middleware setup: table creation (tmp_cron_tasks) and initial alarm scheduling.
    • Tests POST /cron/callback endpoint parsing CronEventPayload[] and invoking registered callbacks.
    • Tests addEvent(): enforces datasource initialization guard, inserts tasks with JSON stringified payload, and reschedules alarms.
    • Tests onEvent(): verifies async promise execution wrapped in ctx.waitUntil() when an ExecutionContext is provided.
  3. plugins/resend/index.test.ts (4 tests):

    • Verifies ResendPlugin initialization with optional apiKey and requiresAuth: false.
    • Tests sendEmail(): asserts correct POST URL, Bearer authorization header, Content-Type, and request body JSON structure.
    • Tests error handling: asserts custom API error propagation (data.message) and default fallback error message ('Failed to send email').

Verification & Test Run

  • All 16 tests pass cleanly:
 ✓ plugins/resend/index.test.ts (4 tests)
 ✓ plugins/cron/utils.test.ts (6 tests)
 ✓ plugins/cron/index.test.ts (6 tests)

 Test Files  3 passed (3)
      Tests  16 passed (16)
   Duration  265ms
  • Strictly test-only scope: 0 production files modified.
  • Formatting: Verified with Prettier.

Demo Video

Payout Base Wallet (if needed): 0xB0fc11e067c57aa0DCEB398747847c6F25a369A1

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.

2 participants