//! Tests for `#[derive(EventData)]` on structs — confirms the derive
//! generates BOTH `EventData` and `EventTypeStatic` impls from a single
//! attribute.

use mire::{EventData, EventTypeStatic};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, EventData)]
#[mire(event_type = "test.something-happened")]
struct SomethingHappened {
    payload: i64,
}

#[derive(Serialize, Deserialize, EventData)]
#[mire(event_type = "test.unit-event")]
struct UnitEvent;

#[test]
fn struct_derive_implements_event_data() {
    let e = SomethingHappened { payload: 42 };
    assert_eq!(e.event_type(), "test.something-happened");
}

#[test]
fn struct_derive_implements_event_type_static() {
    assert_eq!(
        <SomethingHappened as EventTypeStatic>::EVENT_TYPE,
        "test.something-happened"
    );
}

#[test]
fn unit_struct_derive_works_too() {
    let e = UnitEvent;
    assert_eq!(e.event_type(), "test.unit-event");
    assert_eq!(
        <UnitEvent as EventTypeStatic>::EVENT_TYPE,
        "test.unit-event"
    );
}

#[test]
fn both_impls_agree_on_the_string() {
    let e = SomethingHappened { payload: 0 };
    assert_eq!(
        e.event_type(),
        <SomethingHappened as EventTypeStatic>::EVENT_TYPE
    );
}
