Skip to content

test: add missing unit tests for message factory functions#470

Merged
cameri merged 4 commits intocameri:mainfrom
d1vyanshu-kumar:test/add-missing-message-factory-tests
Apr 18, 2026
Merged

test: add missing unit tests for message factory functions#470
cameri merged 4 commits intocameri:mainfrom
d1vyanshu-kumar:test/add-missing-message-factory-tests

Conversation

@d1vyanshu-kumar
Copy link
Copy Markdown
Contributor

Summary

This PR adds missing unit coverage for message factory functions in src/utils/messages.ts.

What changed

Added tests in test/unit/utils/messages.spec.ts for:

  • createCommandResult
    Covers both success and rejection cases.

  • createSubscriptionMessage
    Covers single-filter and multi-filter cases.

  • createRelayedEventMessage
    Covers both paths: with and without a secret.

Why

These functions are exported and used by the relay, but they previously had missing test coverage. Adding these tests helps catch regressions in message creation logic before they reach production.

Verification

  • npm run test:unit
  • All unit tests pass

…ionMessage and createRelayedEventMessage

These three message factory functions in src/utils/messages.ts were
exported and used across the relay but had no tests in the spec file.

- createCommandResult (NIP-20): covers success=true with empty reason
  and success=false with a rejection reason string
- createSubscriptionMessage (NIP-01 REQ): covers single-filter and
  multi-filter cases, verifying the spread into index positions 2+
- createRelayedEventMessage: covers both code paths — the branch that
  returns a 2-element tuple when no secret is passed, and the branch
  that appends the secret as a third element
@d1vyanshu-kumar
Copy link
Copy Markdown
Contributor Author

@cameri Could you please review this PR and let me know if it looks good?

@cameri cameri requested a review from Copilot April 18, 2026 11:33
@cameri cameri self-assigned this Apr 18, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds missing unit test coverage for exported message factory helpers in src/utils/messages.ts, ensuring relay message creation behavior is validated and regressions are caught earlier.

Changes:

  • Added unit tests for createCommandResult covering success and rejection outputs.
  • Added unit tests for createSubscriptionMessage covering single- and multi-filter REQ messages.
  • Added unit tests for createRelayedEventMessage covering EVENT messages with and without a secret.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/unit/utils/messages.spec.ts
@cameri cameri merged commit 28022cb into cameri:main Apr 18, 2026
13 checks passed
@d1vyanshu-kumar d1vyanshu-kumar deleted the test/add-missing-message-factory-tests branch April 22, 2026 11:26
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.

3 participants