Skip to content

Commit

Permalink
test(amazonq): update tests for messages at different remaining itera…
Browse files Browse the repository at this point in the history
…tion counts (#5271)

* test(amazonq): update tests for messages at different remaining iteration counts

* test(amazonq): update tests for messages at different remaining iteration counts
  • Loading branch information
siakmun-aws authored Jan 21, 2025
1 parent 5bceb99 commit 48fc68a
Showing 1 changed file with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,121 @@ class FeatureDevControllerTest : FeatureDevTestBase() {
}
}

@Test
fun `test handleChat onCodeGeneration sends correct add code messages`() = runTest {
val totalIterations = 10

for (remainingIterations in 0 until totalIterations) {
val message = if (remainingIterations > 2) {
message("amazonqFeatureDev.code_generation.iteration_counts_ask_to_add_code_or_feedback")
} else if (remainingIterations > 0) {
message(
"amazonqFeatureDev.code_generation.iteration_counts",
remainingIterations,
totalIterations,
)
} else {
message(
"amazonqFeatureDev.code_generation.iteration_counts_ask_to_add_code",
remainingIterations,
totalIterations,
)
}
val mockSession = mock<Session>()
val featureDevService = mockk<FeatureDevService>()
val repoContext = mock<FeatureDevSessionContext>()
val sessionStateConfig = SessionStateConfig(testConversationId, repoContext, featureDevService)
val mockInteraction = mock<Interaction>()
whenever(mockSession.send(userMessage)).thenReturn(mockInteraction)
whenever(mockSession.sessionState).thenReturn(
PrepareCodeGenerationState(
testTabId,
CancellationTokenSource(),
"test-command",
sessionStateConfig,
newFileContents,
deletedFiles,
testReferences,
testUploadId,
1,
messenger,
remainingIterations,
totalIterations,
diffMetricsProcessed = DiffMetricsProcessed(HashSet(), HashSet()),
),
)

controller.onCodeGeneration(mockSession, userMessage, testTabId)

coVerify {
messenger.sendAnswer(
tabId = testTabId,
messageType = FeatureDevMessageType.Answer,
message = message
)
}
}
}

@Test
fun `test handleChat onCodeGeneration sends correct messages after cancellation`() = runTest {
val totalIterations = 10

for (remainingIterations in -1 until totalIterations) {
// remainingIterations < 0 is to represent the null case
val message = if (remainingIterations > 2 || remainingIterations < 0) {
message("amazonqFeatureDev.code_generation.stopped_code_generation_no_iteration_count_display")
} else if (remainingIterations > 0) {
message(
"amazonqFeatureDev.code_generation.stopped_code_generation",
remainingIterations,
totalIterations,
)
} else {
message(
"amazonqFeatureDev.code_generation.stopped_code_generation_no_iterations",
remainingIterations,
totalIterations,
)
}
val mockSession = mock<Session>()
val featureDevService = mockk<FeatureDevService>()
val repoContext = mock<FeatureDevSessionContext>()
val sessionStateConfig = SessionStateConfig(testConversationId, repoContext, featureDevService)
val mockInteraction = mock<Interaction>()
val token = CancellationTokenSource()
token.cancel()
whenever(mockSession.send(userMessage)).thenReturn(mockInteraction)
whenever(mockSession.sessionState).thenReturn(
PrepareCodeGenerationState(
testTabId,
token,
"test-command",
sessionStateConfig,
newFileContents,
deletedFiles,
testReferences,
testUploadId,
1,
messenger,
(if (remainingIterations < 0) null else remainingIterations),
totalIterations,
diffMetricsProcessed = DiffMetricsProcessed(HashSet(), HashSet()),
),
)

controller.onCodeGeneration(mockSession, userMessage, testTabId)

coVerify {
messenger.sendAnswer(
tabId = testTabId,
messageType = FeatureDevMessageType.Answer,
message = message
)
}
}
}

@Test
fun `test handleChat onCodeGeneration sends success metrics`() = runTest {
val mockSession = mock<Session>()
Expand Down

0 comments on commit 48fc68a

Please sign in to comment.