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

Unit tests for ajv helpers #430

Open
wants to merge 1 commit into
base: mainnet-launch
Choose a base branch
from

Conversation

S0naliThakur
Copy link
Member

No description provided.

@BelfordZ
Copy link
Contributor

/review

Copy link

Preparing review...

@shanejonas
Copy link

/review

Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

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

@shanejonas
Copy link

/improve

Comment on lines +106 to +111
// Mock implementation for initAjvSchemas that throws an error
const mockInitAjvSchemasWithError = () => {
const mockFn = mockRegistry.get('initGetAccountData3Req')
if (mockFn) {
mockFn()
}

Choose a reason for hiding this comment

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

Suggestion: Ensure that the mockInitAjvSchemasWithError function actually throws an error to properly test error handling in schema initialization. [possible issue, importance: 8]

Suggested change
// Mock implementation for initAjvSchemas that throws an error
const mockInitAjvSchemasWithError = () => {
const mockFn = mockRegistry.get('initGetAccountData3Req')
if (mockFn) {
mockFn()
}
const mockInitAjvSchemasWithError = () => {
const mockFn = mockRegistry.get('initGetAccountData3Req')
if (mockFn) {
mockFn()
}
throw new Error('Schema initialization error')
}

Comment on lines +90 to +93
const createMockVerifyFn = (isValid: boolean, errors: ErrorObject[] | null) => {
const mockFn = jest.fn().mockReturnValue(isValid) as jest.Mock & { errors: ErrorObject[] | null }
mockFn.errors = errors
return mockFn

Choose a reason for hiding this comment

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

Suggestion: Ensure that the createMockVerifyFn function correctly assigns the errors property to the mock function to avoid potential issues with error handling. [possible issue, importance: 7]

Suggested change
const createMockVerifyFn = (isValid: boolean, errors: ErrorObject[] | null) => {
const mockFn = jest.fn().mockReturnValue(isValid) as jest.Mock & { errors: ErrorObject[] | null }
mockFn.errors = errors
return mockFn
const createMockVerifyFn = (isValid: boolean, errors: ErrorObject[] | null) => {
const mockFn = jest.fn().mockReturnValue(isValid) as jest.Mock & { errors: ErrorObject[] | null }
Object.defineProperty(mockFn, 'errors', { value: errors, writable: true })
return mockFn
}


// Cleanup - Restore the original implementation
spy.mockRestore()
})

Choose a reason for hiding this comment

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

This test mocks out initAjvSchemas implementation then calls it. it shouldnt not mock the implementation its testing.

Spy is fine since we could check how many times it was called but we shouldn't mock the implementation that we want to test.


// Cleanup - Restore the original implementation
spy.mockRestore()
})

Choose a reason for hiding this comment

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

same with this test. mocks out initAjvSchemas throwing an error then calls it expecting an error.

dont mock out the implementation

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.

5 participants