Last week, early in the week, I focused on testing the update command handler for an entity. I conducted a total of 6 tests. The first test verified the successful update of an entity without contact information. I checked the HTTP status code returned by the update API, which should be 200 (OK). I also made assertions on the updated data to ensure the changes were applied correctly.
The second test handled scenarios where an update was attempted on an entity with an invalid ID. The update API was called with an invalid ID, and the application was expected to return a 400 (BadRequest) status code. The test also validated the error message received against the expected error message for an invalid entity.
I also conducted tests focusing on updating entities with various contact scenarios. This included updates involving multiple contacts, a single contact, and adding new contacts while retaining existing ones. The last test addressed cases where duplicate contacts were provided during the update process. By intentionally supplying duplicate contacts, I expected the application to detect this duplication and return a 400 (BadRequest) status code. The error message received was also validated against the expected error message for duplicate contacts.
After completing the tests for the update command handler, I moved on to the next task, which involved implementing the delete command. This command encapsulates the necessary information to delete an entity, including identification, associated user, code, name, creation timestamp, ID, contact details, and default settings. To handle the delete command, I implemented the delete command handler, which is responsible for processing the command.
The handler uses a service interface to perform the deletion of the entity. The delete command is first validated using the delete command validator, ensuring that required fields such as the entity’s ID are provided and valid. If the command passes validation, I retrieve the entity using its ID from the service interface. If the entity is not found, an exception indicating an invalid entity is thrown. If the entity exists, a transaction is initiated to delete the entity by invoking the appropriate method on the service interface. After successful deletion, the transaction is completed by performing an audit using the provided ID.
To ensure the correctness of the implementation, I created two unit tests for the delete command. The first test verifies the successful deletion of a valid entity. It retrieves the entity from the service, sends a delete request to the API endpoint, and asserts that the entity no longer exists after deletion.
The second test checks the behavior when attempting to delete an entity with an invalid ID. It sends a delete request to the API endpoint with an invalid ID and asserts that a BadRequest response is received. The response is then deserialized into an ErrorDto object, and the error message is checked against the expected error message for an invalid ID.
For this week, my focus will be on continuing on Get command implementation. Additionally, I will also begin on learning and familiarizing myself with the UI, as instructed by Mr. Peter.
