-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This code introduces several improvements and fixes related to user s…
…ignup, activation, and database interaction within a Kotlin application using Spring and R2DBC. Here's a breakdown of the changes: **api/src/test/kotlin/users/TestUtils.kt:** * **`tripleCounts()` function:** This new function efficiently retrieves counts for users, user authorities, and user activations in a single database interaction, returning them as a `Triple`. This simplifies test setup and assertions by checking all three counts are zero initially. **api/src/test/kotlin/users/DaoTests.kt:** * **Simplified SQL Queries:** Several SQL queries have been simplified by using Kotlin's trimIndent() for cleaner formatting and directly using named parameters instead of string concatenation, improving readability and reducing the risk of SQL injection vulnerabilities. * **Removal of Unnecessary Suppression:** The `@Suppress("SqlResolve")` and `@Suppress("SqlSourceToSinkFlow")` annotations have been removed where they are no longer necessary, likely due to updated dependencies or Kotlin versions. * **Use of `tripleCounts()`:** The new `tripleCounts()` function from TestUtils is used to streamline assertions about initial database state, making the tests more concise. * **Direct Use of Constant for Binding:** Using `LOGIN_ATTR` constant instead of the string literal for binding improves consistency and reduces potential errors. * **More Idiomatic Kotlin:** The code uses more Kotlin idioms (e.g., `run`, `let`) for more concise and expressive code. * **Improved Test for User Activation:** The test for user activation (`test find userActivation by key`) has been significantly improved. The previous version had a lot of debugging code and manual parsing of results. The new version is cleaner and easier to understand. The logic now checks for `null` activation dates before signup and verifies the activation date after successful activation. * **Test for User Activation:** A new test, `test activate user by key`, has been added to specifically test the activation mechanism. This test also leverages the `tripleCounts()` function and clearly demonstrates the activation process. It checks the activation date in the database is updated after calling `activateUser()`. **api/src/main/kotlin/users/signup/UserActivationDao.kt:** * **`FIND_ALL_USERACTIVATION` Constant:** A new constant `FIND_ALL_USERACTIVATION` has been added to retrieve all user activations, likely for testing or debugging purposes. It's generally better to use constants for SQL queries to avoid typographical errors and improve maintainability. * **Simplified `UPDATE_ACTIVATION_BY_KEY`:** The `UPDATE_ACTIVATION_BY_KEY` SQL query is simplified. It no longer explicitly sets `activated = true` (this flag might not exist anymore or be handled differently) and uses direct column names instead of parameters for conciseness. These changes demonstrate a clear focus on improving code quality, readability, and maintainability. The tests are more concise and cover more edge cases, leading to greater confidence in the functionality. The use of constants for SQL queries and more idiomatic Kotlin constructs contribute to a more robust and maintainable codebase.
- Loading branch information
Showing
3 changed files
with
151 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters