Skip to content

Commit

Permalink
Feat/finn alle tasker med samme payload og type (#502)
Browse files Browse the repository at this point in the history
* Gjør det mulig å hente alle tasker med samme payload og type

* Endre sql-query t -> *

* Legg til test
  • Loading branch information
halvorbmundal authored Feb 14, 2024
1 parent a41d6e7 commit 83c31de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal interface TaskRepository : PagingAndSortingRepository<Task, Long>, Crud

fun findByPayloadAndType(payload: String, type: String): Task?

@Query("SELECT t FROM task t WHERE t.payload=:payload and t.type=:type")
@Query("SELECT * FROM task t WHERE t.payload=:payload and t.type=:type")
fun findAllByPayloadAndType(payload: String, type: String): List<Task>

@Query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,27 @@ class TaskRepositoryTest : IntegrationRunnerTest() {
assertThat(taskerMedCallId.first().id).isEqualTo(task1.id)
assertThat(taskerMedCallId.last().id).isEqualTo(task4.id)
}


@Test
fun `findAllByPayloadAndType - skal finne tasker for gitt payload og type`() {
val randomString = UUID.randomUUID().toString()

val task1 = Task(type = TaskStep2.TASK_2, payload = randomString)
val task2 = Task(type = TaskStep2.TASK_2, payload = "{'a'='1'}")
val task3 = Task(type = TaskStep2.TASK_2, payload = randomString)
val task4 = Task(type = TaskStep1.TASK_1, payload = "{'a'='b'}")

taskService.save(task1)
taskService.save(task2)
taskService.save(task3)
taskService.save(task4)

val funnedeTasker = repository.findAllByPayloadAndType(task1.payload, TaskStep2.TASK_2)

assertThat(funnedeTasker.size).isEqualTo(2)
assertThat(funnedeTasker.firstOrNull()?.payload).isEqualTo(task1.payload)
assertThat(funnedeTasker.firstOrNull()?.type).isEqualTo(task1.type)
assertThat(funnedeTasker.firstOrNull()?.status).isEqualTo(task1.status)
}
}

0 comments on commit 83c31de

Please sign in to comment.