Skip to content

Commit

Permalink
Add test case for fix #219
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Oct 30, 2024
1 parent 5d262ec commit da1a45c
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,58 @@ import cats.effect.IO

import io.renku.events.EventsGenerators
import io.renku.search.GeneratorSyntax.*
import io.renku.search.events.GroupAdded
import io.renku.search.events.{GroupAdded, GroupUpdated}
import io.renku.search.model.ModelGenerators
import io.renku.search.model.{Id, Name, Namespace}
import io.renku.search.provision.ProvisioningSuite
import io.renku.search.provision.events.syntax.*
import io.renku.search.solr.documents.{CompoundId, EntityDocument, Group as GroupDocument}
import io.renku.search.solr.documents.{Group as GroupDocument, *}
import io.renku.solr.client.DocVersion
import org.scalacheck.Gen

class GroupAddedProvisioningSpec extends ProvisioningSuite:

test("merge partial groups"):
for
services <- IO(testServices())
handler = services.syncHandler(queueConfig.dataServiceAllEvents)
queueClient = services.queueClient
solrClient = services.searchClient

id <- IO(ModelGenerators.idGen.generateOne)
_ <- solrClient.deleteIds(NonEmptyList.of(id))
add1 <- queueClient.enqueue(
queueConfig.dataServiceAllEvents,
EventsGenerators
.eventMessageGen(
Gen.const(GroupUpdated(id, Name("SDSC"), Namespace("sdsc-namespace"), None))
)
.generateOne
)
_ <- handler.create.map(_.asUpsert).unNone.take(1).compile.toList
pdoc <- solrClient.findById[PartialEntityDocument](CompoundId.groupPartial(id))
_ = assert(pdoc.isDefined, "no (partial) document found")
_ = assert(pdoc.get.isInstanceOf[PartialEntityDocument.Group])

add2 <- queueClient.enqueue(
queueConfig.dataServiceAllEvents,
EventsGenerators
.eventMessageGen(
Gen.const(
GroupAdded(id, Name("Renku"), Namespace("sdsc-namespace"), None)
)
)
.generateOne
)
results <- handler.create.map(_.asUpsert).unNone.take(1).compile.toList

_ = assert(results.nonEmpty && results.forall(_.isSuccess))
doc <- solrClient.findById[EntityDocument](CompoundId.groupEntity(id))
_ = assert(doc.isDefined, "group not found")
group = doc.get.asInstanceOf[GroupDocument]
_ = assertEquals(group.name, Name("SDSC"))
yield ()

test("overwrite data for duplicate events"):
for
services <- IO(testServices())
Expand Down

0 comments on commit da1a45c

Please sign in to comment.