Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tpolecat committed Nov 5, 2024
1 parent 29d7221 commit c1b2ec9
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ trait MutationMapping[F[_]] extends Predicates[F] {
private lazy val SetObservationWorkflowState =
MutationField.encodable("setObservationWorkflowState", SetObservationWorkflowStateInput.Binding): input =>
services.useNonTransactionally:
observationWorkflowService.setWorkflowState(input.observationId, input.state, commitHash, itcClient)
observationWorkflowService.setWorkflowState(input.observationId, input.state, commitHash, itcClient, timeEstimateCalculator)

private lazy val SetProgramReference =
MutationField("setProgramReference", SetProgramReferenceInput.Binding): (input, child) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import lucuma.odb.data.OdbErrorExtensions.*
import lucuma.odb.graphql.binding.BooleanBinding
import lucuma.odb.graphql.table.TimingWindowView
import lucuma.odb.json.configurationrequest.query.given
import lucuma.odb.logic.TimeEstimateCalculatorImplementation
import lucuma.odb.sequence.util.CommitHash
import lucuma.odb.service.ItcService
import lucuma.odb.service.Services
Expand All @@ -48,6 +49,7 @@ trait ObservationMapping[F[_]]
def itcClient: ItcClient[F]
def services: Resource[F, Services[F]]
def commitHash: CommitHash
def timeEstimateCalculator: TimeEstimateCalculatorImplementation.ForInstrumentMode

lazy val ObservationMapping: ObjectMapping =
ObjectMapping(ObservationType)(
Expand Down Expand Up @@ -150,7 +152,7 @@ trait ObservationMapping[F[_]]
(_, oid, _) =>
services.use { s =>
s.observationWorkflowService
.getWorkflow(oid, commitHash, itcClient)
.getWorkflow(oid, commitHash, itcClient, timeEstimateCalculator)
}

effectHandler(readEnv, calculate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ sealed trait ObservationWorkflowService[F[_]] {
def getWorkflow(
oid: Observation.Id,
commitHash: CommitHash,
itcClient: ItcClient[F]
itcClient: ItcClient[F],
ptc: TimeEstimateCalculatorImplementation.ForInstrumentMode
)(using NoTransaction[F]): F[Result[ObservationWorkflow]]

def setWorkflowState(
oid: Observation.Id,
state: ObservationWorkflowState,
commitHash: CommitHash,
itcClient: ItcClient[F]
itcClient: ItcClient[F],
ptc: TimeEstimateCalculatorImplementation.ForInstrumentMode
)(using NoTransaction[F]): F[Result[ObservationWorkflow]]

}
Expand Down Expand Up @@ -250,14 +252,14 @@ object ObservationWorkflowService {
private def executionState(
info: ObservationValidationInfo,
commitHash: CommitHash,
itcClient: ItcClient[F]
)(using Enums, NoTransaction[F]): F[Option[ExecutionState]] =
TimeEstimateCalculatorImplementation.fromSession(session, summon).flatMap: ptc =>
generator(commitHash, itcClient, ptc).executionState(info.pid, info.oid).map:
case ObservationExecutionState.NotDefined => None
case ObservationExecutionState.NotStarted => None
case ObservationExecutionState.Ongoing => Some(Ongoing)
case ObservationExecutionState.Completed => Some(Completed)
itcClient: ItcClient[F],
ptc: TimeEstimateCalculatorImplementation.ForInstrumentMode
)(using NoTransaction[F]): F[Option[ExecutionState]] =
generator(commitHash, itcClient, ptc).executionState(info.pid, info.oid).map:
case ObservationExecutionState.NotDefined => None
case ObservationExecutionState.NotStarted => None
case ObservationExecutionState.Ongoing => Some(Ongoing)
case ObservationExecutionState.Completed => Some(Completed)

// Compute the observation status, as well as a list of legal transitions,
private def workflowStateAndTransitions(
Expand Down Expand Up @@ -305,7 +307,7 @@ object ObservationWorkflowService {
val allowedTransitions: List[ObservationWorkflowState] =
if info.role.isDefined then Nil // User can't set the state for calibrations
else state match
case Inactive => List(validationStatus)
case Inactive => List(executionState.getOrElse(validationStatus))
case Undefined => List(Inactive)
case Unapproved => List(Inactive)
case Defined => List(Inactive) ++ Option.when(isAccepted)(Ready)
Expand Down Expand Up @@ -366,21 +368,23 @@ object ObservationWorkflowService {
private def getWorkflowImpl(
oid: Observation.Id,
commitHash: CommitHash,
itcClient: ItcClient[F]
itcClient: ItcClient[F],
ptc: TimeEstimateCalculatorImplementation.ForInstrumentMode
)(using NoTransaction[F]): ResultT[F, ObservationWorkflow] =
getObsInfoAndOtherStuff(oid, itcClient).flatMap: (info, errs) =>
for
ex <- ResultT.liftF(executionState(info, commitHash, itcClient))
ex <- ResultT.liftF(executionState(info, commitHash, itcClient, ptc))
pair <- ResultT(workflowStateAndTransitions(info, ex, errs.map(_.code)).pure[F])
(s, ss) = pair
yield ObservationWorkflow(s, ss, errs)

override def getWorkflow(
oid: Observation.Id,
commitHash: CommitHash,
itcClient: ItcClient[F]
itcClient: ItcClient[F],
ptc: TimeEstimateCalculatorImplementation.ForInstrumentMode
)(using NoTransaction[F]): F[Result[ObservationWorkflow]] =
getWorkflowImpl(oid, commitHash, itcClient).value
getWorkflowImpl(oid, commitHash, itcClient, ptc).value

extension (ws: ObservationWorkflowState) def asUserState: Option[UserState] =
ws match
Expand All @@ -392,9 +396,10 @@ object ObservationWorkflowService {
oid: Observation.Id,
state: ObservationWorkflowState,
commitHash: CommitHash,
itcClient: ItcClient[F]
itcClient: ItcClient[F],
ptc: TimeEstimateCalculatorImplementation.ForInstrumentMode
)(using NoTransaction[F]): ResultT[F, ObservationWorkflow] =
getWorkflowImpl(oid, commitHash, itcClient).flatMap: w =>
getWorkflowImpl(oid, commitHash, itcClient, ptc).flatMap: w =>
if w.state === state then ResultT.success(w)
else if !w.validTransitions.contains(state)
then ResultT.failure(OdbError.InvalidWorkflowTransition(w.state, state).asProblem)
Expand All @@ -408,9 +413,10 @@ object ObservationWorkflowService {
oid: Observation.Id,
state: ObservationWorkflowState,
commitHash: CommitHash,
itcClient: ItcClient[F]
itcClient: ItcClient[F],
ptc: TimeEstimateCalculatorImplementation.ForInstrumentMode
)(using NoTransaction[F]): F[Result[ObservationWorkflow]] =
setWorkflowStateImpl(oid, state, commitHash, itcClient).value
setWorkflowStateImpl(oid, state, commitHash, itcClient, ptc).value

}

Expand Down
Loading

0 comments on commit c1b2ec9

Please sign in to comment.