use fluxion_core::{FluxionError, StreamItem};
use fluxion_stream::{MapOrderedExt, TakeItemsExt};
use fluxion_test_utils::{
assert_stream_ended, test_channel_with_errors,
test_data::{person_alice, TestData},
unwrap_stream, Sequenced,
};
#[tokio::test]
async fn test_map_ordered_then_take_items_propagates_error() -> anyhow::Result<()> {
let (tx, stream) = test_channel_with_errors::<Sequenced<TestData>>();
let mut result = stream.map_ordered(|x| x).take_items(2);
tx.unbounded_send(StreamItem::Value(Sequenced::new(person_alice())))?;
assert!(matches!(
unwrap_stream(&mut result, 100).await,
StreamItem::Value(_)
));
tx.unbounded_send(StreamItem::Error(FluxionError::stream_error("Map error")))?;
assert!(matches!(
unwrap_stream(&mut result, 100).await,
StreamItem::Error(_)
));
tx.unbounded_send(StreamItem::Value(Sequenced::new(person_alice())))?;
assert_stream_ended(&mut result, 100).await;
Ok(())
}