Skip to content

Commit

Permalink
The provided code changes implement the following:
Browse files Browse the repository at this point in the history
1. **Constant for Signup API Path:**
    - A new object `Signup` is created within the `SignupController` class.
    - This object contains two constants:
        - `API_ACCOUNT`: Holds the base API path for account-related operations (`/api/account`).
        - `SIGNUP_API_PATH`: Combines the base path with the specific signup endpoint (`/api/account/signup`).

2. **Using the Constant in Tests:**
    - The `SignupIntegrationTests` class now imports the `SIGNUP_API_PATH` constant.
    - The test case `SignupController - test signup avec un account valide` now uses this constant when making a POST request to the signup endpoint.

**Benefits of these changes:**

- **Improved Code Readability:** Using constants for API paths makes the code easier to understand and maintain.
- **Reduced Duplication:** Defining the API path in one place avoids repetition and ensures consistency across the codebase.
- **Easier Refactoring:** If the API path needs to change in the future, it only needs to be updated in one location.

**Overall:** These changes are a good practice and improve the quality and maintainability of the code.
  • Loading branch information
cheroliv committed Sep 27, 2024
1 parent c6f256e commit 2c104f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import webapp.users.signup.AccountRestApis.API_ACCOUNT
@RestController
@RequestMapping(API_ACCOUNT)
class SignupController {
internal class SignupException(message: String) : RuntimeException(message)

internal class SignupException(message: String) : RuntimeException(message)
object Signup {
const val API_ACCOUNT = "/api/account"
const val SIGNUP_API_PATH = "$API_ACCOUNT/signup"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import webapp.tests.TestUtils.deleteAllUsersOnly
import webapp.users.User.UserDao.Fields.EMAIL_FIELD
import webapp.users.User.UserDao.Fields.LOGIN_FIELD
import webapp.users.User.UserDao.Fields.PASSWORD_FIELD
import webapp.users.signup.SignupController.Signup.SIGNUP_API_PATH
import kotlin.test.*

@SpringBootTest(properties = ["spring.main.web-application-type=reactive"])
Expand Down Expand Up @@ -121,22 +122,23 @@ class SignupIntegrationTests {


@Test //TODO: mock sendmail
fun `SignupController - test signup avec un account valide`() = runBlocking {
fun `SignupController - test signup avec un account valide`(): Unit = runBlocking {
val countUserBefore = context.countUsers()
val countUserAuthBefore = context.countUserAuthority()
assertEquals(0, countUserBefore)
assertEquals(0, countUserAuthBefore)
// client
// .post()
// .uri(SIGNUP_API_PATH)
// .contentType(APPLICATION_JSON)
// .bodyValue(user)
// .exchange()
// .expectStatus()
// .isCreated
// .returnResult<Unit>()
// .responseBodyContent!!
// .isEmpty()
client
.post()
.uri(SIGNUP_API_PATH)
.contentType(APPLICATION_JSON)
.bodyValue(user)
.exchange()
.expectStatus()
.isCreated
.returnResult<Unit>()
.responseBodyContent!!
.isEmpty()
.let(::assertTrue)
// .run { assertTrue(this) }
// assertEquals(countUserBefore + 1, countAccount(dao))
// assertEquals(countUserAuthBefore + 1, countAccountAuthority(dao))
Expand Down

0 comments on commit 2c104f4

Please sign in to comment.