1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use module_runtime::{
|
||||
RuntimeProfileFieldError, RuntimeProfileInviteCodeSnapshot, RuntimeProfileInviteCodeStatus,
|
||||
build_runtime_profile_invite_code_record, resolve_runtime_profile_invite_code_status,
|
||||
build_runtime_profile_invite_code_record, normalize_invite_code_metadata_json,
|
||||
resolve_runtime_profile_invite_code_status,
|
||||
validate_runtime_profile_invite_code_validity_window,
|
||||
};
|
||||
|
||||
@@ -15,11 +16,14 @@ fn invite_code_validity_window_rejects_start_after_expire() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invite_code_validity_window_allows_open_ended_or_equal_boundary() {
|
||||
fn invite_code_validity_window_allows_open_ended_and_rejects_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());
|
||||
assert_eq!(
|
||||
validate_runtime_profile_invite_code_validity_window(Some(10), Some(10)),
|
||||
Err(RuntimeProfileFieldError::InvalidInviteCodeValidityWindow)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -48,7 +52,6 @@ fn invite_code_record_formats_window_and_status() {
|
||||
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,
|
||||
@@ -59,3 +62,33 @@ fn invite_code_record_formats_window_and_status() {
|
||||
assert_eq!(record.expires_at.as_deref(), Some("1970-01-01T00:00:01Z"));
|
||||
assert_eq!(record.status, RuntimeProfileInviteCodeStatus::Expired);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invite_code_metadata_normalizes_user_tags() {
|
||||
let normalized = normalize_invite_code_metadata_json(
|
||||
r#"{"source":"admin","user_tags":[" 北科 ","北科",""]}"#.to_string(),
|
||||
)
|
||||
.expect("metadata should normalize");
|
||||
|
||||
assert_eq!(normalized, r#"{"source":"admin","userTags":["北科"]}"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invite_code_metadata_removes_empty_user_tags() {
|
||||
let normalized = normalize_invite_code_metadata_json(r#"{"userTags":[]}"#.to_string())
|
||||
.expect("empty tags should be valid");
|
||||
|
||||
assert_eq!(normalized, "{}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invite_code_metadata_rejects_invalid_user_tags_shape() {
|
||||
assert_eq!(
|
||||
normalize_invite_code_metadata_json(r#"{"userTags":"北科"}"#.to_string()),
|
||||
Err(RuntimeProfileFieldError::InvalidUserTag)
|
||||
);
|
||||
assert_eq!(
|
||||
normalize_invite_code_metadata_json(r#"{"userTags":["北科",1]}"#.to_string()),
|
||||
Err(RuntimeProfileFieldError::InvalidUserTag)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user