Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import jakarta.persistence.GenerationType
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
import uk.gov.communities.prsdb.webapp.helpers.DateTimeHelper
import java.util.UUID

@Entity
Expand Down Expand Up @@ -45,6 +51,15 @@ class JointLandlordInvitation(
this.invitingLandlord = invitingLandlord
}

val expiresOnDate: LocalDate
get() =
DateTimeHelper
.getDateInUK(createdDate.toKotlinInstant())
.plus(DatePeriod(days = JOINT_LANDLORD_INVITATION_LIFETIME_IN_DAYS))

val isExpired: Boolean
get() = DateTimeHelper().getCurrentDateInUK() > expiresOnDate

constructor(
id: Long,
token: UUID,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Comment thread
samyou-softwire marked this conversation as resolved.
@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)
}
}
Loading