1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Integration test for ModEventSystem subscribe functionality
//!
//! Verifies that ModEventSystem dispatches DynamicEvents from EventBus to MOD callbacks.
use issun::context::ResourceContext;
use issun::event::EventBus;
use issun::modding::{DynamicEvent, ModEventSystem};
#[tokio::test]
async fn test_mod_event_system_collects_from_eventbus() {
// This test verifies that ModEventSystem can collect DynamicEvents from EventBus
// Note: Full E2E test with RhaiLoader is in issun-mod-rhai crate tests
// Setup ResourceContext
let mut resources = ResourceContext::new();
resources.insert(EventBus::new());
// Publish DynamicEvents to EventBus
{
let mut event_bus = resources
.get_mut::<EventBus>()
.await
.expect("EventBus not found");
event_bus.publish(DynamicEvent {
event_type: "PlayerDamaged".to_string(),
data: serde_json::json!({
"damage": 10,
"source": "goblin"
}),
});
event_bus.publish(DynamicEvent {
event_type: "ItemCollected".to_string(),
data: serde_json::json!({
"item": "health_potion",
"quantity": 1
}),
});
event_bus.dispatch();
}
// Create ModEventSystem and run update
let mut mod_event_system = ModEventSystem::new();
mod_event_system.update_resources(&mut resources).await;
// Verify: The test passes if ModEventSystem can read DynamicEvents without panicking
// In a full E2E test with actual MOD subscribers, this would invoke callbacks
println!("Test passed - ModEventSystem can collect DynamicEvents from EventBus");
}