generated from ministryofjustice/template-repository
-
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.
Browse files
Browse the repository at this point in the history
* PI-1785: Added get user details by id
- Loading branch information
Showing
6 changed files
with
85 additions
and
17 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
8 changes: 4 additions & 4 deletions
8
...th-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/UserGenerator.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.user.AuditUser | ||
import uk.gov.justice.digital.hmpps.entity.User | ||
|
||
object UserGenerator { | ||
val AUDIT_USER = AuditUser(IdGenerator.getAndIncrement(), "HmppsAuthAndDelius") | ||
val TEST_USER = AuditUser(IdGenerator.getAndIncrement(), "test.user") | ||
val INACTIVE_USER = AuditUser(IdGenerator.getAndIncrement(), "test.user.inactive") | ||
val USER = User(IdGenerator.getAndIncrement(), "HmppsAuthAndDelius") | ||
val TEST_USER = User(IdGenerator.getAndIncrement(), "test.user") | ||
val INACTIVE_USER = User(IdGenerator.getAndIncrement(), "test.user.inactive") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,35 @@ internal class UserDetailsIntegrationTest { | |
) | ||
} | ||
|
||
@Test | ||
fun `calling user by id without userId returns 400`() { | ||
mockMvc.perform(get("/user").withToken()) | ||
.andExpect(status().isBadRequest) | ||
} | ||
|
||
@Test | ||
fun `missing user by id returns 404`() { | ||
mockMvc.perform(get("/user/details/99999").withToken()) | ||
.andExpect(status().isNotFound) | ||
} | ||
|
||
@Test | ||
fun `get user by id`() { | ||
mockMvc.perform(get("/user/details/" + TEST_USER.id).withToken()) | ||
.andExpect(status().isOk) | ||
.andExpectJson( | ||
UserDetails( | ||
userId = TEST_USER.id, | ||
username = "test.user", | ||
firstName = "Test", | ||
surname = "User", | ||
email = "[email protected]", | ||
enabled = true, | ||
roles = listOf("ABC001", "ABC002") | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `search by email`() { | ||
mockMvc.perform(get("/[email protected]").withToken()) | ||
|
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
29 changes: 29 additions & 0 deletions
29
projects/hmpps-auth-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/User.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package uk.gov.justice.digital.hmpps.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import org.hibernate.annotations.Immutable | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
|
||
@Immutable | ||
@Entity | ||
@Table(name = "user_") | ||
class User( | ||
@Id | ||
@Column(name = "user_id") | ||
val id: Long, | ||
|
||
@Column(name = "distinguished_name") | ||
val username: String | ||
) | ||
|
||
interface UserRepository : JpaRepository<User, Long> { | ||
fun findUserById(userId: Long): User? | ||
|
||
@Query("select u from User u where upper(u.username) = upper(:username)") | ||
fun findUserByUsername(username: String): User? | ||
} | ||
|
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