diff --git a/modules/search-provision/src/test/scala/io/renku/search/provision/group/GroupAddedProvisioningSpec.scala b/modules/search-provision/src/test/scala/io/renku/search/provision/group/GroupAddedProvisioningSpec.scala index e7eea68d..6cb9a61c 100644 --- a/modules/search-provision/src/test/scala/io/renku/search/provision/group/GroupAddedProvisioningSpec.scala +++ b/modules/search-provision/src/test/scala/io/renku/search/provision/group/GroupAddedProvisioningSpec.scala @@ -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())