batch_mode_batch_reconciliation/
recalculate_recommended_actions.rs

1// ---------------- [ File: batch-mode-batch-reconciliation/src/recalculate_recommended_actions.rs ]
2crate::ix!();
3
4pub trait RecalculateRecommendedActions {
5    fn recalculate_recommended_actions(&self) 
6        -> Result<BatchFileReconciliationRecommendedCourseOfAction, BatchReconciliationError>;
7}
8
9impl RecalculateRecommendedActions for BatchFileTriple {
10
11    // Implement recalculate_recommended_actions method
12    fn recalculate_recommended_actions(&self) -> Result<BatchFileReconciliationRecommendedCourseOfAction, BatchReconciliationError> {
13        // Re-run the logic to determine the next steps based on the updated triple
14        BatchFileReconciliationRecommendedCourseOfAction::try_from(self)
15    }
16}
17
18#[cfg(test)]
19mod recalculate_recommended_actions_tests {
20    use super::*;
21
22    #[traced_test]
23    async fn test_recalculate_recommended_actions() {
24
25        let workspace: Arc<dyn BatchWorkspaceInterface> = BatchWorkspace::new_temp().await.expect("expected workspace");
26
27        let triple = BatchFileTripleBuilder::default()
28            .index(BatchIndex::from(999u64))
29            .input::<PathBuf>("input.json".into())
30            .workspace(workspace)
31            .build()
32            .unwrap();
33
34        let recommended = triple.recalculate_recommended_actions();
35        assert!(recommended.is_ok());
36        let steps = recommended.unwrap().steps().to_vec();
37        pretty_assert_eq!(
38            steps,
39            vec![
40                BatchFileTripleReconciliationOperation::CheckForBatchOutputAndErrorFileOnline,
41                BatchFileTripleReconciliationOperation::RecalculateRecommendedCourseOfActionIfTripleChanged,
42            ]
43        );
44    }
45
46    #[traced_test]
47    fn test_recalculate_recommended_actions_failure() {
48        // If the triple is all None => recalc should fail
49        let triple = BatchFileTriple::new_for_test_empty();
50        let recommended = triple.recalculate_recommended_actions();
51        assert!(recommended.is_err());
52        match recommended.err().unwrap() {
53            BatchReconciliationError::BatchWorkspaceError(BatchWorkspaceError::NoBatchFileTripleAtIndex{index}) => {
54                // This is correct
55                pretty_assert_eq!(index.as_u64(), triple.index().as_u64());
56            },
57            other => panic!("Unexpected error variant: {:?}", other),
58        }
59    }
60}