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

483/shav-mailjet-stage-segments #329

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

sxpydo
Copy link

@sxpydo sxpydo commented Jan 21, 2025

Description:
This PR introduces a new invokePrivateMethod utility in our ReflectionUtils class, enabling safer testing of private methods. I demonstrated its use by implementing comprehensive unit tests for PgExternalAccountPersistenceManager, focusing on the buildUserExternalAccountChanges method. Then, I updated this method to properly parse JSON data for registered contexts, improving our handling of user account information. The changes include new test methods in ReflectionUtilsTest and a complete test suite for PgExternalAccountPersistenceManager. These enhancements could significantly improve our test coverage and ensure more robust processing of user data from the database.

Ticket: https://github.com/isaaccomputerscience/isaac-cs-issues/issues/483

Media Attachement(s):
Screenshot of all of the unit test suite passing
Screenshot 2025-02-04 at 11 02 49

A screen recording demonstrating the steps from the Mailjet Documentation on how to create separate segments for A-Level and GCSE students and setting up distinct segments using the "stage" property..

Screen.Recording.2025-01-03.at.12.03.08.mov

- Extend updateUserProperties method to include stage parameter
- Add stage to the JSON data sent in Mailjet API request
- Ensure consistent formatting and error handling

This change allows for updating user stage information in Mailjet.
- Verify ExternalAccountManager throws ExternalAccountSynchronisationException
  when MailjetException occurs during account retrieval
- Test covers scenario of Mailjet API communication failure
- Ensures proper error propagation in synchroniseChangedUsers method
- Implement tests for getAccountByIdOrEmail and addNewUserOrGetUserIfExists methods
- Use EasyMock for mocking MailjetClient and MailjetResponse
- Include test for handling null email input
- Set up test environment with mock injection in setUp method
- Add new utility method `invokePrivateMethod` to ReflectionUtils
- Extend ReflectionUtilsTest with additional test cases
- Improve test coverage for getClasses and getSubTypes methods
- Ensure consistent naming and structure across test methods
- Update documentation for ReflectionUtils class

This commit enhances the capabilities of our reflection utilities
and strengthens our test suite, improving overall code quality
and maintainability.
- Create PgExternalAccountPersistenceManagerTest class
- Implement test for buildUserExternalAccountChanges method
- Use ReflectionUtils to access private method for testing
- Mock ResultSet to simulate database interaction
- Verify correct creation of UserExternalAccountChanges object

This commit improves test coverage for the PgExternalAccountPersistenceManager
class, ensuring the correct handling of user account data from the database.
}

@Test
void synchroniseChangedUsers_existingUser() throws SegueDatabaseException, MailjetException, ExternalAccountSynchronisationException {

Choose a reason for hiding this comment

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

I'm struggling a little to see what the difference in behaviour between the existing and newuser cases are. Could you insert a comment or something in the test data to make that clearer?

@@ -102,6 +103,9 @@ public void updateExternalAccount(final Long userId, final String providerUserId
}

private UserExternalAccountChanges buildUserExternalAccountChanges(final ResultSet results) throws SQLException {
String registeredContextsJson = results.getString("registered_contexts");

Choose a reason for hiding this comment

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

Is this all working OK in your local database? It looks like it requires db schema changes to include the registered contexts.

I might be wrong - I don't remember how that information was stored when we looked at it

- Updated test expectations in PgExternalAccountPersistenceManagerTest to align with method behavior
- Correctly mock ResultSet to handle registered_contexts JSON data
- Added assertions to verify proper JSON parsing and stage extraction
- Removed invalid expectations for ResultSet.getString() calls
- Improved test readability and ensured consistency with the method logic

These changes resolve mismatched expectations and improve the accuracy of the tests, ensuring proper handling of registered_contexts JSON data
@sxpydo sxpydo marked this pull request as ready for review February 10, 2025 14:52
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.

2 participants