Skip to content

Commit

Permalink
Ability for using path segments from state predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Jan 11, 2023
1 parent dd84e04 commit 75948bd
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
import ru.tinkoff.tcb.utils.id.SID
import ru.tinkoff.tcb.utils.regex.*

final class StubResolver(stubDAO: HttpStubDAO[Task], stateDAO: PersistentStateDAO[Task]) {
private val log = MDCLogging.`for`[WLD](this)
Expand Down Expand Up @@ -82,7 +83,16 @@ final class StubResolver(stubDAO: HttpStubDAO[Task], stateDAO: PersistentStateDA
candidates4 <- candidates3.traverse { stubc =>
val bodyJson = stubc.request.extractJson(body)
val bodyXml = stubc.request.extractXML(body)
computeStateSpec(stubc.state.map(_.fill(Json.obj("__query" -> queryObject))), bodyJson, bodyXml)
val groups = for {
pattern <- stubc.pathPattern
mtch <- pattern.findFirstMatchIn(path)
} yield pattern.groups.map(g => g -> mtch.group(g)).to(Map)
val segments = groups.map(segs => Json.fromFields(segs.view.mapValues(Json.fromString))).getOrElse(Json.Null)
computeStateSpec(
stubc.state.map(_.fill(Json.obj("__query" -> queryObject, "__segments" -> segments))),
bodyJson,
bodyXml
)
.cata(
spec => findStates(stubc.id, spec).map(stubc -> _),
ZIO.succeed(stubc -> Vector.empty[PersistentState])
Expand Down

0 comments on commit 75948bd

Please sign in to comment.