[IGS] Ask for consent only 5 times

^KTI-1443 In Progress
This commit is contained in:
Alexander.Likhachev
2023-11-08 18:02:14 +01:00
committed by Space Team
parent b0254add6d
commit ab5699f106
2 changed files with 13 additions and 4 deletions
@@ -32,6 +32,8 @@ internal val USER_CONSENT_DETAILS_LINK_TEMPLATE = "You can read more details her
internal const val PROMPT_REQUEST = "Do you agree with this? Please answer with 'yes' or 'no': "
private const val MAX_REQUEST_ATTEMPTS = 5
internal fun String.formatWithLink(link: String) = replace(linkPlaceholder, link)
internal class ConsentManager(
@@ -56,7 +58,7 @@ internal class ConsentManager(
if (consentDetailsLink != null) {
output.println(USER_CONSENT_DETAILS_LINK_TEMPLATE.formatWithLink(consentDetailsLink))
}
while (true) {
repeat(MAX_REQUEST_ATTEMPTS) {
output.println(PROMPT_REQUEST)
when (input.readLine()) {
"yes" -> {
@@ -77,5 +79,7 @@ internal class ConsentManager(
}
}
}
// we didn't receive an answer, let's ask next time
return false
}
}
@@ -67,10 +67,13 @@ class ConsentManagerTest {
@Test
fun testConsentRequestAnswerAfterBadInput() = testUserDecision("\nasdasd\nno", false, USER_REFUSAL_MARKER, 3)
@Test
fun testConsentRequestAnswerAfterTooManyBadInput() = testUserDecision("\n\n\n\n\n\n\n\nasdasd\nyes", false, null, 5)
private fun testUserDecision(
prompt: String,
expectedDecision: Boolean,
expectedLine: String,
expectedLine: String?,
promptCount: Int = 1,
consentDetailsLink: String? = null,
) {
@@ -80,8 +83,10 @@ class ConsentManagerTest {
val consentManager = ConsentManager(modifier, null, input, printStream)
val userDecision = consentManager.askForConsent(consentDetailsLink)
assertEquals(expectedDecision, userDecision)
val content = Files.readAllLines(localPropertiesFile)
assertTrue(content.contains(expectedLine))
if (expectedLine != null) {
val content = Files.readAllLines(localPropertiesFile)
assertTrue(content.contains(expectedLine))
}
val output = String(outputStream.toByteArray())
assertContainsExactTimes(output, USER_CONSENT_REQUEST, 1)
assertContainsExactTimes(output, PROMPT_REQUEST, promptCount)