Skip to content

Commit

Permalink
Add test cases and modify test conf.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-in-a-Jar committed Oct 13, 2023
1 parent 7273a5a commit 872aeca
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/test/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ termsOfService {
enabled = false
version = 1
url = "app.terra.bio/#terms-of-service"
rollingAcceptanceWindowExpirationDatetime = "2019-01-01T00:00:00Z"
rollingAcceptanceWindowPreviousTosVersion = 0
}

petServiceAccount {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ class TosServiceSpec(_system: ActorSystem)
}

val tosVersion = "2"
val rollingAcceptanceWindowPreviousTosVersion = "1"
val withoutGracePeriod = "without the grace period enabled"
val withGracePeriod = " with the grace period enabled"
val withoutRollingAcceptanceWindow = "outside of the rolling acceptance window"
val withRollingAcceptanceWindow = " inside of the rolling acceptance window"
val cannotUseTheSystem = "says the user cannot use the system"
val canUseTheSystem = "says the user can use the system"
val tosServiceV2 = new TosService(dirDAO, TestSupport.tosConfig.copy(version = tosVersion))
val tosServiceV2GracePeriodEnabled =
new TosService(dirDAO, TestSupport.tosConfig.copy(version = tosVersion, isGracePeriodEnabled = true))
val tosServiceV2AcceptanceWindowEnabled = new TosService(dirDAO, TestSupport.tosConfig.copy(isTosEnabled=true, isGracePeriodEnabled=false, version = tosVersion, rollingAcceptanceWindowExpiration = Instant.now().plusSeconds(3600), rollingAcceptanceWindowPreviousTosVersion = rollingAcceptanceWindowPreviousTosVersion))


/** | Case | Grace Period Enabled | Accepted Version | Current Version | User accepted latest | Permits system usage |
* |:-----|:---------------------|:-----------------|:----------------|:---------------------|:---------------------|
Expand Down Expand Up @@ -143,6 +148,24 @@ class TosServiceSpec(_system: ActorSystem)
complianceStatus.permitsSystemUsage shouldBe false
}
}
withRollingAcceptanceWindow - {
cannotUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(None))
// CASE 1
val complianceStatus = tosServiceV2AcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe false
}
}
withoutRollingAcceptanceWindow - {
cannotUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(None))
// CASE 4
val complianceStatus = tosServiceV2.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe false
}
}
}
"when the user has accepted a non-current ToS version" - {
"says the user has not accepted the latest version" in {
Expand All @@ -169,6 +192,33 @@ class TosServiceSpec(_system: ActorSystem)
complianceStatus.permitsSystemUsage shouldBe true
}
}
withRollingAcceptanceWindow - {
canUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, rollingAcceptanceWindowPreviousTosVersion, TosTable.ACCEPT, Instant.now()))))
// CASE 1
val complianceStatus = tosServiceV2AcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe true
}
}
withRollingAcceptanceWindow - {
cannotUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, "0", TosTable.ACCEPT, Instant.now()))))
// CASE 1
val complianceStatus = tosServiceV2AcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe false
}
}
withoutRollingAcceptanceWindow - {
cannotUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, rollingAcceptanceWindowPreviousTosVersion, TosTable.ACCEPT, Instant.now()))))
// CASE 4
val complianceStatus = tosServiceV2.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe false
}
}
}
"when the user has accepted the current ToS version" - {
"says the user has accepted the latest version" in {
Expand All @@ -195,6 +245,24 @@ class TosServiceSpec(_system: ActorSystem)
complianceStatus.permitsSystemUsage shouldBe true
}
}
withRollingAcceptanceWindow - {
canUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.ACCEPT, Instant.now()))))
// CASE 1
val complianceStatus = tosServiceV2AcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe true
}
}
withoutRollingAcceptanceWindow - {
canUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.ACCEPT, Instant.now()))))
// CASE 4
val complianceStatus = tosServiceV2.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe true
}
}
}

"when the user has rejected the latest ToS version" - {
Expand Down Expand Up @@ -222,6 +290,24 @@ class TosServiceSpec(_system: ActorSystem)
complianceStatus.permitsSystemUsage shouldBe false
}
}
withRollingAcceptanceWindow - {
cannotUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.REJECT, Instant.now()))))
// CASE 1
val complianceStatus = tosServiceV2AcceptanceWindowEnabled.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe false
}
}
withoutRollingAcceptanceWindow - {
cannotUseTheSystem in {
when(dirDAO.getLatestUserTos(defaultUser.id, samRequestContext))
.thenReturn(IO.pure(Option(SamUserTos(defaultUser.id, tosVersion, TosTable.REJECT, Instant.now()))))
// CASE 4
val complianceStatus = tosServiceV2.getTosComplianceStatus(defaultUser, samRequestContext).unsafeRunSync()
complianceStatus.permitsSystemUsage shouldBe false
}
}
}
"when a service account is using the api" - {
"let it use the api regardless of tos status" in {
Expand Down

0 comments on commit 872aeca

Please sign in to comment.