Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The changes in
TestUtils.kt
reflect improvements in code style, sec…
…urity, database interaction, and testing utilities. Let's break down the key modifications: **1. Constants Usage and Visibility:** * Constants are now directly imported and used, like `ADMIN`, `DOMAIN_DEV_URL`, role constants etc. improving readability and reducing reliance on the `Constants` object. * `@file:Suppress("MemberVisibilityCanBePrivate")` This annotation suppresses warnings about members that could be private. It suggests that these members are intentionally made public, likely for testing purposes where direct access is beneficial. **2. Insert User Script Enhancement:** * The SQL script for inserting users has been significantly improved. It now uses a more robust random password generator function directly within PostgreSQL. The previous approach used a less secure and potentially problematic method of generating random passwords. The new function utilizes PostgreSQL's built-in random functions and character manipulation capabilities. * The script is now a constant (`INSERT_USERS_SCRIPT`) rather than a calculated value. This makes it easier to manage and understand. * The SQL syntax has been cleaned up, using double quotes consistently for identifiers (`"user"` instead of `` `user` ``), adhering to better SQL practices. **3. String Formatting and Logging:** * Log messages for displaying the insert script and request bodies now use Kotlin's string interpolation, which is more concise and readable. **4. Code Style and Readability:** * Comments are used more effectively to explain sections of the code. * The code is generally cleaner and more idiomatic Kotlin, such as using `run` for scoping and side effects. **Summary of Improvements:** * **Security:** More robust password generation. * **Database Interaction:** More efficient and standard SQL. * **Code Style:** Cleaner, more readable Kotlin. * **Testability:** Improved access to test data and utilities. * **Maintainability:** Constants improve clarity and reduce reliance on a single `Constants` object. These changes represent a good progression in code quality and maintainability, demonstrating a shift towards best practices and improved security measures. The improvements to the user insertion script are particularly noteworthy, addressing potential security vulnerabilities.
- Loading branch information