From c80707bca6c565f16609c9ed04b4f2dfcb3e59b9 Mon Sep 17 00:00:00 2001 From: samyou-softwire <108681823+samyou-softwire@users.noreply.github.com> Date: Wed, 3 Jun 2026 10:47:32 +0100 Subject: [PATCH 1/3] PDJB-NONE: add isExpired accessor for JL invitation --- .../constants/InvitationLifetimeConstants.kt | 2 +- .../database/entity/JointLandlordInvitation.kt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/uk/gov/communities/prsdb/webapp/constants/InvitationLifetimeConstants.kt b/src/main/kotlin/uk/gov/communities/prsdb/webapp/constants/InvitationLifetimeConstants.kt index c6a0469de7..a0be34b51d 100644 --- a/src/main/kotlin/uk/gov/communities/prsdb/webapp/constants/InvitationLifetimeConstants.kt +++ b/src/main/kotlin/uk/gov/communities/prsdb/webapp/constants/InvitationLifetimeConstants.kt @@ -1,4 +1,4 @@ package uk.gov.communities.prsdb.webapp.constants const val LOCAL_COUNCIL_INVITATION_LIFETIME_IN_HOURS: Int = 48 -const val JOINT_LANDLORD_INVITATION_LIFETIME_IN_HOURS: Int = 672 // 28 days +const val JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS = 28 diff --git a/src/main/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitation.kt b/src/main/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitation.kt index 3c9376ce79..57099b8e85 100644 --- a/src/main/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitation.kt +++ b/src/main/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitation.kt @@ -7,6 +7,11 @@ import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne +import kotlinx.datetime.DatePeriod +import kotlinx.datetime.plus +import kotlinx.datetime.toKotlinInstant +import uk.gov.communities.prsdb.webapp.constants.JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS +import uk.gov.communities.prsdb.webapp.helpers.DateTimeHelper import java.util.UUID @Entity @@ -45,6 +50,18 @@ class JointLandlordInvitation( this.invitingLandlord = invitingLandlord } + val isExpired: Boolean + get() { + val dateTimeHelper = DateTimeHelper() + + val expiresOnDate = + DateTimeHelper + .getDateInUK(createdDate.toKotlinInstant()) + .plus(DatePeriod(days = JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS)) + + return dateTimeHelper.getCurrentDateInUK() > expiresOnDate + } + constructor( id: Long, token: UUID, From 4ac2827f8bb6493f96d326f546fa319f44409f6a Mon Sep 17 00:00:00 2001 From: samyou-softwire <108681823+samyou-softwire@users.noreply.github.com> Date: Thu, 4 Jun 2026 14:50:41 +0100 Subject: [PATCH 2/3] PDJB-NONE: Add isExpired tests --- .../entity/JointLandlordInvitationTests.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/test/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitationTests.kt diff --git a/src/test/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitationTests.kt b/src/test/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitationTests.kt new file mode 100644 index 0000000000..bc15372639 --- /dev/null +++ b/src/test/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitationTests.kt @@ -0,0 +1,35 @@ +package uk.gov.communities.prsdb.webapp.database.entity + +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import uk.gov.communities.prsdb.webapp.constants.JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS +import uk.gov.communities.prsdb.webapp.testHelpers.mockObjects.MockJointLandlordData +import java.time.Instant +import java.time.temporal.ChronoUnit + +class JointLandlordInvitationTests { + @Test + fun `isExpired returns false when the current day is earlier than the expiry date`() { + val createdDate = Instant.now().minus((JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS - 1).toLong(), ChronoUnit.DAYS) + val invitation = MockJointLandlordData.createJointLandlordInvitation(createdDate = createdDate) + + assertFalse(invitation.isExpired) + } + + @Test + fun `isExpired returns false when the current day equals the expiry date`() { + val createdDate = Instant.now().minus(JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS.toLong(), ChronoUnit.DAYS) + val invitation = MockJointLandlordData.createJointLandlordInvitation(createdDate = createdDate) + + assertFalse(invitation.isExpired) + } + + @Test + fun `isExpired returns true when the current day is later than the expiry date`() { + val createdDate = Instant.now().minus((JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS + 1).toLong(), ChronoUnit.DAYS) + val invitation = MockJointLandlordData.createJointLandlordInvitation(createdDate = createdDate) + + assertTrue(invitation.isExpired) + } +} From 49e037593be74fa8f1facb78915b08d83f17f34c Mon Sep 17 00:00:00 2001 From: samyou-softwire <108681823+samyou-softwire@users.noreply.github.com> Date: Thu, 4 Jun 2026 14:51:55 +0100 Subject: [PATCH 3/3] PDJB-NONE: Extract expiresOnDate as well to a method --- .../database/entity/JointLandlordInvitation.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitation.kt b/src/main/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitation.kt index 57099b8e85..a8004502d9 100644 --- a/src/main/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitation.kt +++ b/src/main/kotlin/uk/gov/communities/prsdb/webapp/database/entity/JointLandlordInvitation.kt @@ -8,6 +8,7 @@ import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne import kotlinx.datetime.DatePeriod +import kotlinx.datetime.LocalDate import kotlinx.datetime.plus import kotlinx.datetime.toKotlinInstant import uk.gov.communities.prsdb.webapp.constants.JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS @@ -50,17 +51,14 @@ class JointLandlordInvitation( this.invitingLandlord = invitingLandlord } - val isExpired: Boolean - get() { - val dateTimeHelper = DateTimeHelper() - - val expiresOnDate = - DateTimeHelper - .getDateInUK(createdDate.toKotlinInstant()) - .plus(DatePeriod(days = JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS)) + val expiresOnDate: LocalDate + get() = + DateTimeHelper + .getDateInUK(createdDate.toKotlinInstant()) + .plus(DatePeriod(days = JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS)) - return dateTimeHelper.getCurrentDateInUK() > expiresOnDate - } + val isExpired: Boolean + get() = DateTimeHelper().getCurrentDateInUK() > expiresOnDate constructor( id: Long,