use module_runtime::{ RuntimeProfileFieldError, RuntimeProfileInviteCodeSnapshot, RuntimeProfileInviteCodeStatus, build_runtime_profile_invite_code_record, resolve_runtime_profile_invite_code_status, validate_runtime_profile_invite_code_validity_window, }; #[test] fn invite_code_validity_window_rejects_start_after_expire() { let result = validate_runtime_profile_invite_code_validity_window(Some(20), Some(10)); assert_eq!( result, Err(RuntimeProfileFieldError::InvalidInviteCodeValidityWindow) ); } #[test] fn invite_code_validity_window_allows_open_ended_or_equal_boundary() { assert!(validate_runtime_profile_invite_code_validity_window(None, None).is_ok()); assert!(validate_runtime_profile_invite_code_validity_window(Some(10), None).is_ok()); assert!(validate_runtime_profile_invite_code_validity_window(None, Some(10)).is_ok()); assert!(validate_runtime_profile_invite_code_validity_window(Some(10), Some(10)).is_ok()); } #[test] fn invite_code_status_uses_inclusive_start_and_exclusive_expire_boundary() { assert_eq!( resolve_runtime_profile_invite_code_status(Some(20), None, 19), RuntimeProfileInviteCodeStatus::Pending ); assert_eq!( resolve_runtime_profile_invite_code_status(Some(20), Some(30), 20), RuntimeProfileInviteCodeStatus::Active ); assert_eq!( resolve_runtime_profile_invite_code_status(Some(20), Some(30), 29), RuntimeProfileInviteCodeStatus::Active ); assert_eq!( resolve_runtime_profile_invite_code_status(Some(20), Some(30), 30), RuntimeProfileInviteCodeStatus::Expired ); } #[test] fn invite_code_record_formats_window_and_status() { let record = build_runtime_profile_invite_code_record(RuntimeProfileInviteCodeSnapshot { user_id: "user-1".to_string(), invite_code: "SY00000001".to_string(), metadata_json: "{}".to_string(), granted_user_tags: Vec::new(), starts_at_micros: Some(0), expires_at_micros: Some(1_000_000), created_at_micros: 0, updated_at_micros: 1_000_000, }); assert_eq!(record.starts_at.as_deref(), Some("1970-01-01T00:00:00Z")); assert_eq!(record.expires_at.as_deref(), Some("1970-01-01T00:00:01Z")); assert_eq!(record.status, RuntimeProfileInviteCodeStatus::Expired); }