|
| 1 | +package no.java.conf |
| 2 | + |
| 3 | +import com.jillesvangurp.ktsearch.SearchClient |
| 4 | +import io.ktor.client.request.get |
| 5 | +import io.ktor.client.statement.bodyAsText |
| 6 | +import io.ktor.http.HttpStatusCode |
| 7 | +import io.ktor.server.testing.testApplication |
| 8 | +import io.mockk.every |
| 9 | +import io.mockk.mockk |
| 10 | +import kotlinx.coroutines.runBlocking |
| 11 | +import no.java.conf.plugins.configureSearchRouting |
| 12 | +import no.java.conf.service.SearchService |
| 13 | +import kotlin.test.Test |
| 14 | +import kotlin.test.assertEquals |
| 15 | +import kotlin.test.assertTrue |
| 16 | + |
| 17 | +class StateTest { |
| 18 | + @Test |
| 19 | + fun testNewState() { |
| 20 | + val searchClient = mockk<SearchClient>() |
| 21 | + |
| 22 | + val service = SearchService(searchClient, false) |
| 23 | + |
| 24 | + testApplication { |
| 25 | + |
| 26 | + application { |
| 27 | + configureSearchRouting(service) |
| 28 | + } |
| 29 | + |
| 30 | + client.get("/api/search/state").apply { |
| 31 | + assertEquals(HttpStatusCode.OK, status) |
| 32 | + assertEquals(bodyAsText(), "NEW") |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | + @Test |
| 39 | + fun testSkipIndex() { |
| 40 | + val searchClient = mockk<SearchClient>() |
| 41 | + |
| 42 | + val service = SearchService(searchClient, true) |
| 43 | + |
| 44 | + testApplication { |
| 45 | + |
| 46 | + application { |
| 47 | + configureSearchRouting(service) |
| 48 | + } |
| 49 | + |
| 50 | + client.get("/api/search/state").apply { |
| 51 | + assertEquals(HttpStatusCode.OK, status) |
| 52 | + assertEquals(bodyAsText(), "NEW") |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + fun testSkipIndexMapped() { |
| 59 | + val searchClient = mockk<SearchClient>() |
| 60 | + |
| 61 | + val service = SearchService(searchClient, true) |
| 62 | + |
| 63 | + runBlocking { |
| 64 | + service.setup() |
| 65 | + } |
| 66 | + |
| 67 | + testApplication { |
| 68 | + |
| 69 | + application { |
| 70 | + configureSearchRouting(service) |
| 71 | + } |
| 72 | + |
| 73 | + client.get("/api/search/state").apply { |
| 74 | + assertEquals(HttpStatusCode.OK, status) |
| 75 | + assertEquals(bodyAsText(), "MAPPED") |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + @Test |
| 82 | + fun testSkipIndexIndexed() { |
| 83 | + val searchClient = mockk<SearchClient>() |
| 84 | + |
| 85 | + val service = SearchService(searchClient, true) |
| 86 | + |
| 87 | + runBlocking { |
| 88 | + service.setup() |
| 89 | + service.ingest(emptyList()) |
| 90 | + } |
| 91 | + |
| 92 | + testApplication { |
| 93 | + |
| 94 | + application { |
| 95 | + configureSearchRouting(service) |
| 96 | + } |
| 97 | + |
| 98 | + client.get("/api/search/state").apply { |
| 99 | + assertEquals(HttpStatusCode.OK, status) |
| 100 | + assertEquals(bodyAsText(), "INDEXED") |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +} |
0 commit comments