Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add comprehensive unit tests for Helpers.ts utility functions #445

Merged
merged 2 commits into from
Mar 29, 2025

Conversation

ahmxdiqbal
Copy link
Member

@ahmxdiqbal ahmxdiqbal commented Mar 25, 2025

User description

Add comprehensive unit tests for src/types/Helpers.ts file

(cherry picked from commit b27c65b)


PR Type

Tests


Description

  • Add comprehensive unit tests for Helpers.ts utility functions

  • Mock dependencies and console outputs for testing

  • Validate serialization and deserialization processes

  • Test error handling and logging mechanisms


Changes walkthrough 📝

Relevant files
Tests
Helpers.test.ts
Add unit tests for Helpers.ts utility functions                   

test/unit/src/types/Helpers.test.ts

  • Added unit tests for responseSerializer and responseDeserializer
  • Implemented tests for requestSerializer and requestErrorHandler
  • Included tests for verificationDataCombiner and
    verificationDataSplitter
  • Mocked dependencies and console outputs for accurate testing
  • +438/-0 

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🏅 Score: 95
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    const mockDeserializerFunc = jest.fn()

    // Act & Assert
    expect(() => responseDeserializer(stream, mockDeserializerFunc)).toThrow('Invalid response stream')

    Choose a reason for hiding this comment

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

    Suggestion: Ensure that the error message in the toThrow assertion matches the actual error message thrown by the responseDeserializer function to avoid false negatives in the test. [general, importance: 7]

    Suggested change
    expect(() => responseDeserializer(stream, mockDeserializerFunc)).toThrow('Invalid response stream')
    expect(() => responseDeserializer(stream, mockDeserializerFunc)).toThrow(new Error('Invalid response stream'))

    const mockDeserializerFunc = jest.fn()

    // Act & Assert
    expect(() => responseDeserializer(stream, mockDeserializerFunc)).toThrow(ResponseError)

    Choose a reason for hiding this comment

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

    Suggestion: Verify that the ResponseError being thrown includes the correct error message and properties to ensure the test accurately reflects the function's behavior. [general, importance: 6]

    Suggested change
    expect(() => responseDeserializer(stream, mockDeserializerFunc)).toThrow(ResponseError)
    expect(() => responseDeserializer(stream, mockDeserializerFunc)).toThrow(expect.objectContaining({ message: 'Test error message' }))


    // Assert
    // 2 bytes for length + string length * 2 bytes
    expect(result).toBe(2 + testString.length * 2)

    Choose a reason for hiding this comment

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

    Suggestion: Confirm that the calculation for string size estimation accounts for any additional encoding overhead that might affect the byte size. [general, importance: 8]

    Suggested change
    expect(result).toBe(2 + testString.length * 2)
    expect(result).toBe(2 + Buffer.byteLength(testString, 'utf16le'))

    @mhanson-github mhanson-github merged commit 3ce06b9 into mainnet-launch Mar 29, 2025
    5 checks passed
    @mhanson-github mhanson-github deleted the unit-test/Helpers.ts branch March 29, 2025 04:29
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants