Skip to content

Commit

Permalink
Move tests to e2e modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Nov 10, 2024
1 parent 9ccbdf8 commit cf000a9
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 83 deletions.
9 changes: 3 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ lazy val app = project
logback,
otel4sMetricts,
otel4sSdk,
otel4sPrometheusExporter,
weaver,
testContainers
otel4sPrometheusExporter
),
Compile / run / fork := true
)
Expand All @@ -161,9 +159,9 @@ val e2e = project
.settings(
publish := {},
publish / skip := true,
libraryDependencies ++= Seq(weaver)
libraryDependencies ++= Seq(testContainers, weaver)
)
.dependsOn(client, app)
.dependsOn(client, app, ingestor)

lazy val root = project
.in(file("."))
Expand All @@ -172,4 +170,3 @@ lazy val root = project

addCommandAlias("prepare", "scalafixAll; scalafmtAll")
addCommandAlias("check", "; scalafixAll --check ; scalafmtCheckAll")

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package test
import cats.effect.{ IO, Resource }
import cats.syntax.all.*
import com.comcast.ip4s.*
import lila.search.ingestor.given
import lila.search.spec.*
import org.http4s.Uri
import org.typelevel.log4cats.noop.{ NoOpFactory, NoOpLogger }
Expand Down Expand Up @@ -51,76 +52,70 @@ object IntegrationSuite extends IOSuite:
_.healthCheck()
.map(expect.same(_, HealthCheckOutput(ElasticStatus.green)))

test("forum"): _ =>
test("forum"): res =>
Clients
.search(uri)
.use: service =>
for
_ <- service.mapping(Index.Forum)
_ <- service
.store(
"forum_id",
Source.forum(
ForumSource(
body = "a forum post",
topic = "chess",
topicId = "chess",
troll = false,
date = Instant.now().toEpochMilli(),
author = "nt9".some
)
)
_ <- res.esClient.putMapping(Index.Forum)
_ <- res.esClient.store(
Index.Forum,
Id("forum_id"),
ingestor.ForumSource(
body = "a forum post",
topic = "chess",
topicId = "chess",
troll = false,
date = Instant.now().toEpochMilli(),
author = "nt9".some
)
_ <- service.refresh(Index.Forum)
)
_ <- res.esClient.refreshIndex(Index.Forum)
x <- service.search(Query.forum("chess", false), from, size)
y <- service.search(Query.forum("nt9", false), from, size)
yield expect(x.hitIds.size == 1 && x == y)

test("team"): _ =>
test("team"): res =>
Clients
.search(uri)
.use: service =>
for
_ <- service.mapping(Index.Team)
_ <- service
.store(
"team_id",
Source.team(
TeamSource(
name = "team name",
description = "team description",
100
)
)
_ <- res.esClient.putMapping(Index.Team)
_ <- res.esClient.store(
Index.Team,
Id("team_id"),
ingestor.TeamSource(
name = "team name",
description = "team description",
100
)
_ <- service.refresh(Index.Team)
)
_ <- res.esClient.refreshIndex(Index.Team)
x <- service.search(Query.team("team name"), from, size)
y <- service.search(Query.team("team description"), from, size)
yield expect(x.hitIds.size == 1 && x == y)

test("study"): _ =>
test("study"): res =>
Clients
.search(uri)
.use: service =>
for
_ <- service.mapping(Index.Study)
_ <- service
.store(
"study_id",
Source.study(
StudySource(
name = "study name",
owner = "study owner",
members = List("member1", "member2"),
chapterNames = "names",
chapterTexts = "texts",
likes = 100,
public = true,
topics = List("topic1", "topic2")
)
)
_ <- res.esClient.putMapping(Index.Study)
_ <- res.esClient.store(
Index.Study,
Id("study_id"),
ingestor.StudySource(
name = "study name",
owner = "study owner",
members = List("member1", "member2"),
chapterNames = "names",
chapterTexts = "texts",
likes = 100,
public = true,
topics = List("topic1", "topic2")
)
_ <- service.refresh(Index.Study)
)
_ <- res.esClient.refreshIndex(Index.Study)
a <- service.search(Query.study("name"), from, size)
b <- service.search(Query.study("study description"), from, size)
c <- service.search(Query.study("topic1"), from, size)
Expand All @@ -136,38 +131,36 @@ object IntegrationSuite extends IOSuite:
duration = defaultIntRange,
sorting = Sorting("field", "asc")
)
test("game"): _ =>
test("game"): res =>
Clients
.search(uri)
.use: service =>
for
_ <- service.mapping(Index.Game)
_ <- service
.store(
"game_id",
Source.game(
GameSource(
status = 1,
turns = 100,
rated = true,
perf = 1,
winnerColor = 1,
date = SearchDateTime.fromInstant(Timestamp(1999, 10, 20, 12, 20, 20).toInstant),
analysed = false,
uids = List("uid1", "uid2").some,
winner = "uid1".some,
loser = "uid2".some,
averageRating = 150.some,
ai = none,
duration = 100.some,
clockInit = 100.some,
clockInc = 200.some,
whiteUser = "white".some,
blackUser = "black".some
)
)
_ <- res.esClient.putMapping(Index.Game)
_ <- res.esClient.store(
Index.Game,
Id("game_id"),
ingestor.GameSource(
status = 1,
turns = 100,
rated = true,
perf = 1,
winnerColor = 1,
date = SearchDateTime.fromInstant(Timestamp(1999, 10, 20, 12, 20, 20).toInstant),
analysed = false,
uids = List("uid1", "uid2").some,
winner = "uid1".some,
loser = "uid2".some,
averageRating = 150.some,
ai = none,
duration = 100.some,
clockInit = 100.some,
clockInc = 200.some,
whiteUser = "white".some,
blackUser = "black".some
)
_ <- service.refresh(Index.Game)
)
_ <- res.esClient.refreshIndex(Index.Game)
a <- service.search(defaultGame.copy(perf = List(1)), from, size)
b <- service.search(defaultGame.copy(loser = "uid2".some), from, size)
c <- service.search(defaultGame, from, size)
Expand Down
7 changes: 4 additions & 3 deletions modules/elastic/src/main/scala/study.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ case class Study(text: String, userId: Option[String]):
val matcher: Query =
if parsed.terms.isEmpty then matchAllQuery()
else
multiMatchQuery(
parsed.terms.mkString(" ")
).fields(Study.searchableFields*).analyzer("english").matchType("most_fields")
multiMatchQuery(parsed.terms.mkString(" "))
.fields(Study.searchableFields*)
.analyzer("english")
.matchType("most_fields")
boolQuery()
.must:
matcher :: List(
Expand Down

0 comments on commit cf000a9

Please sign in to comment.