Skip to content

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

Open
d1vyanshu-kumar wants to merge 1 commit intocameri:mainfrom
d1vyanshu-kumar:test/add-missing-message-factory-tests
Open

test: add missing unit tests for message factory functions#470
d1vyanshu-kumar wants to merge 1 commit intocameri:mainfrom
d1vyanshu-kumar:test/add-missing-message-factory-tests

Conversation

@d1vyanshu-kumar
Copy link
Copy Markdown

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
Author

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

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.

1 participant