feat: add invite code validity controls
- Add invite code starts/expires fields across contracts, API, Spacetime bindings, and admin UI - Enforce pending/expired invite code redemption behavior and expose admin status - Add admin write-operation confirmation guard and documentation - Add invite code contract/runtime tests
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
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(),
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user