Skip to content

Commit

Permalink
Add forum integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Jun 5, 2024
1 parent d249a5d commit 9a73460
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
28 changes: 27 additions & 1 deletion modules/app/src/test/scala/IntegrationSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package app
package test

import cats.effect.{ IO, Resource }
import cats.syntax.all.*
import com.comcast.ip4s.*
import lila.search.spec.{ ElasticStatus, HealthCheckOutput }
import lila.search.spec.*
import org.http4s.Uri
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.noop.NoOpLogger
import smithy4s.Timestamp
import weaver.*

object IntegrationSuite extends IOSuite:
Expand Down Expand Up @@ -38,3 +40,27 @@ object IntegrationSuite extends IOSuite:
.use:
_.healthCheck()
.map(expect.same(_, HealthCheckOutput(ElasticStatus.green)))

test("forum"): _ =>
Clients
.search(uri)
.use: service =>
for
_ <- service.mapping(lila.search.spec.Index.Forum)
_ <- service
.store(
"forum_id",
Source.forum(
ForumSource(
body = "a forum post",
topic = "chess",
topicId = "chess",
troll = false,
date = Timestamp(2021, 1, 1, 0, 0, 0),
author = "nt9".some
)
)
)
_ <- service.refresh(Index.Forum)
x <- service.search(Query.forum("chess", false), 0, 12)
yield expect(x.hitIds.size == 1)
8 changes: 2 additions & 6 deletions modules/core/src/main/scala/ESClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ object ESClient:
dropIndex(index) >> client
.execute {
createIndex(index.name)
.mapping(
properties(fields).source(false) // all false
)
.mapping(properties(fields).source(false)) // all false
.shards(5)
.replicas(0)
.refreshInterval(Which.refreshInterval(index))
Expand All @@ -110,6 +108,4 @@ object ESClient:
.flatMap(unitOrFail)

private def dropIndex(index: Index) =
client
.execute(deleteIndex(index.name))
.flatMap(unitOrFail)
client.execute(deleteIndex(index.name))

0 comments on commit 9a73460

Please sign in to comment.