fix(frontend): keep entity and message deletes in sync

This commit is contained in:
2026-03-27 03:38:41 -03:00
parent 726c8f3afd
commit 433874d11e
7 changed files with 112 additions and 4 deletions

View File

@@ -21,7 +21,7 @@ class EntityService(
/** Returns all virtual entities. */
fun findAll(): List<VirtualEntityResponseDto> =
virtualEntityRepository.findAll().map { VirtualEntityResponseDto.from(it) }
virtualEntityRepository.findAllByActiveTrue().map { VirtualEntityResponseDto.from(it) }
/** Returns one entity by ID, or null if not found. */
fun findById(id: UUID): VirtualEntityResponseDto? =

View File

@@ -138,4 +138,32 @@ class TaskGeneratedMessageControllerTest {
.andExpect(jsonPath("$").isArray)
.andExpect(jsonPath("$.length()").value(0))
}
@Test
fun should_deleteOnlySelectedHistoryItem_when_multipleMessagesExist() {
val task = createTask()
val firstMessage = generatedMessageHistoryRepository.save(
GeneratedMessageHistory(
task = task,
label = "Message #1",
content = "SUBJECT: First\nBODY:\nHello"
)
)
val secondMessage = generatedMessageHistoryRepository.save(
GeneratedMessageHistory(
task = task,
label = "Message #2",
content = "SUBJECT: Second\nBODY:\nHi"
)
)
mockMvc.perform(delete("/api/v1/tasks/${task.id}/generated-messages/${firstMessage.id}").cookie(authCookie()))
.andExpect(status().isNoContent)
mockMvc.perform(get("/api/v1/tasks/${task.id}/generated-messages").cookie(authCookie()))
.andExpect(status().isOk)
.andExpect(jsonPath("$.length()").value(1))
.andExpect(jsonPath("$[0].id").value(secondMessage.id.toString()))
.andExpect(jsonPath("$[0].label").value("Message #2"))
}
}

View File

@@ -62,6 +62,17 @@ class VirtualEntityControllerTest {
.andExpect(status().isOk).andExpect(jsonPath("$").isArray).andExpect(jsonPath("$[0].name").value("Test Entity"))
}
@Test
fun should_returnOnlyActiveEntities_when_getAllEntities() {
virtualEntityRepository.save(VirtualEntity(name = "Active Entity", email = "active@condado.com", jobTitle = "Tester", active = true))
virtualEntityRepository.save(VirtualEntity(name = "Inactive Entity", email = "inactive@condado.com", jobTitle = "Tester", active = false))
mockMvc.perform(get("/api/v1/virtual-entities").cookie(authCookie()))
.andExpect(status().isOk)
.andExpect(jsonPath("$.length()").value(1))
.andExpect(jsonPath("$[0].name").value("Active Entity"))
}
@Test
fun should_return200AndEntity_when_getById() {
val entity = virtualEntityRepository.save(VirtualEntity(name = "Test Entity", email = "entity@condado.com", jobTitle = "Test Job"))