Skip to content

Write tests #23

@TheJolman

Description

@TheJolman

https://developers.cloudflare.com/workers/testing/vitest-integration/write-your-first-test/

Possible tests (AI generated):

High Priority - Core Business Logic

  1. Service Endpoint Tests (packages/service)

These are your critical path - the actual link management logic:

// linkCreate.test.ts

  • ✅ Creating link with auto-generated slug
  • ✅ Creating link with custom slug
  • ✅ Rejecting reserved slugs (links, list)
  • ✅ Rejecting duplicate slugs (409 conflict)
  • ✅ Validating auth token (401 if missing/wrong)

// linkUpdate.test.ts

  • ✅ Updating URL
  • ✅ Updating isPermanent flag
  • ✅ 404 for non-existent slug

// linkDelete.test.ts

  • ✅ Deleting existing link
  • ✅ 404 for non-existent slug

// linkRedirect.test.ts

  • ✅ 302 redirect for temporary links
  • ✅ 301 redirect for permanent links
  • ✅ 404 for non-existent slug

Why: These tests protect your data integrity and ensure the API contract. If these break, the whole app breaks.

  1. Bot Command Handler Tests (packages/bot)

Test the Discord interaction parsing and routing:

// commands.test.ts

  • ✅ Discord signature verification (reject invalid signatures)
  • ✅ PING/PONG response
  • ✅ Guild ID validation (reject commands from wrong server)
  • ✅ URL validation (isValidUrl function)
  • ✅ Add command: valid URL
  • ✅ Add command: invalid URL
  • ✅ Delete command parsing
  • ✅ Update command: no modifications provided (error)
  • ✅ Unknown subcommand handling

Why: These ensure you handle Discord's webhook correctly and don't expose security vulnerabilities.

Medium Priority - Integration & Utilities

  1. Client API Tests (packages/bot/src/client.ts)

Test the HTTP client that talks to your service:

// client.test.ts

  • ✅ addLink success (mock fetch)
  • ✅ addLink failure handling
  • ✅ deleteLink success
  • ✅ updateLink success
  • ✅ Proper auth header formatting

Why: Validates error handling and ensures bot gracefully handles service failures

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions