Skip to content

Commit

Permalink
Bug on last update (#197)
Browse files Browse the repository at this point in the history
* Bug on last update
  • Loading branch information
larousso authored Oct 16, 2024
1 parent 017397f commit 0a50648
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions nio-server/app/models/ConsentFact.scala
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ case class PartialConsentFact(
userId: Option[String] = None,
doneBy: Option[DoneBy] = None,
version: Option[Int] = None,
lastUpdate: Option[LocalDateTime] = None,
lastUpdate: Option[LocalDateTime] = Some(LocalDateTime.now(Clock.systemUTC)),
groups: Option[Seq[PartialConsentGroup]] = None,
offers: Option[Seq[PartialConsentOffer]] = None,
orgKey: Option[String] = None,
Expand All @@ -325,7 +325,7 @@ case class PartialConsentFact(
userId = userId.getOrElse(lastConsentFact.userId),
doneBy = doneBy.getOrElse(lastConsentFact.doneBy),
version = version.getOrElse(organisation.version.num),
lastUpdate = lastUpdate.getOrElse(lastConsentFact.lastUpdate),
lastUpdate = lastUpdate.getOrElse(LocalDateTime.now(Clock.systemUTC)),
lastUpdateSystem = LocalDateTime.now(Clock.systemUTC),
groups = groups.map(g => PartialConsentGroup.merge(g, lastConsentFact.groups, organisation.groups)).getOrElse(lastConsentFact.groups),
offers = offers.map(o => PartialConsentOffer.merge(o, lastConsentFact.offers)).getOrElse(lastConsentFact.offers),
Expand Down
11 changes: 7 additions & 4 deletions nio-server/test/controllers/ConsentControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,13 @@ class ConsentControllerSpec extends TestUtils {
"Partial update on consent" in {
val organisationKey: String = "maif"

val path: String =
s"/$tenant/organisations/$organisationKey/users/$userId1"
val putResponse = putJson(path, user1AsJson)
val userId = userId1 + "1"
val user = user1.copy(userId = userId)

val path: String = s"/$tenant/organisations/$organisationKey/users/$userId"
val putResponse = putJson(path, user.asJson())

println(putResponse.json)
putResponse.status mustBe OK

val patchResponse = patchJson(path, Json.obj(
Expand All @@ -840,7 +843,7 @@ class ConsentControllerSpec extends TestUtils {
patchResponse.status mustBe OK

val expectedDate: LocalDateTime = (json \ "lastUpdate").validate(DateUtils.utcDateTimeReads).get
json mustBe user1.copy(
json mustBe user.copy(
orgKey = Some("maif"),
lastUpdate = expectedDate,
groups = user1.groups.updated(0, user1.groups(0).copy(
Expand Down

0 comments on commit 0a50648

Please sign in to comment.