Using a test driven approach for group membership: Part 2

I’m working on adding functionality to dmvboardgames.com which will allow users to join groups and see information about the groups they are a part of. After implementing test cases as described in my previous post, I worked on implementing the logic to make sure the tests pass.

Here are a couple of notes about design decisions I made with the code:

  • The service layer logic does permission checking, and calls a UserRepository instance to get the data. While writing unit tests on UserMemberService.java wouldn’t be complicated if I mocked the dependencies, I don’t think they are worth writing. The value of the unit tests isn’t high. On the other hand, the unit tests will have ongoing costs due to making automated tests harder to run, and adding additional code that needs to be maintained. They will also be duplicating test coverage from the integration tests.
  • In the service layer, for the joinGroup and leaveGroup functions, I pass in a user object to the UserRepository instance which runs a database query. Although only the user id is necessary, I decide to pass the whole user object to avoid parameter confusion with the group id which is also an integer.



The code changes are here: https://github.com/gatherspiel/backend/pull/243. The next step will be adding API endpoints, creating a UI, and then testing end-to-end