diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-08 11:20:35 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-08 11:23:28 +0000 |
| commit | 5d02ad6b893f9059044914c115d77cf9d8e589c3 (patch) | |
| tree | b727f9c44d2f2d4e203dc2344e4c9bd5144a77dd /tests/common/purgatory_helpers.rs | |
| parent | 075307804bf66bba10f5bc55cb40e2e6a98a65ee (diff) | |
refactor: replace hardcoded Kind constants with rust-nostr variants
- Replace KIND_REPOSITORY_ANNOUNCEMENT with Kind::GitRepoAnnouncement
- Replace KIND_REPOSITORY_STATE with Kind::RepoState
- Replace KIND_PR with Kind::GitPullRequest
- Replace KIND_PR_UPDATE with Kind::GitPullRequestUpdate
- Replace KIND_USER_GRASP_LIST with Kind::GitUserGraspList
- Replace KIND_PATCH with Kind::GitPatch
- Replace KIND_ISSUE with Kind::GitIssue
- Replace KIND_COMMENT with Kind::Comment
- Replace all Kind::Custom(30617|30618|1617|1618|1619|1621|1111|10317) patterns
- Remove all hardcoded KIND_* constants from events.rs
- Update all match statements to use Kind enum directly
- Update all filter builders to use Kind variants
- Update all test helpers and assertions
Benefits:
- Type safety: compiler prevents wrong kind numbers
- Readability: Kind::GitRepoAnnouncement is self-documenting
- Maintainability: single source of truth (rust-nostr)
- IDE support: full autocompletion and refactoring
- Standards: aligns with rust-nostr best practices
Files modified: 21
Constants removed: 9
Patterns replaced: 100+
Tests passing: 222/222
Diffstat (limited to 'tests/common/purgatory_helpers.rs')
| -rw-r--r-- | tests/common/purgatory_helpers.rs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/tests/common/purgatory_helpers.rs b/tests/common/purgatory_helpers.rs index b39982e..1d06f22 100644 --- a/tests/common/purgatory_helpers.rs +++ b/tests/common/purgatory_helpers.rs | |||
| @@ -16,11 +16,9 @@ use std::path::Path; | |||
| 16 | use std::process::Command; | 16 | use std::process::Command; |
| 17 | use std::time::Duration; | 17 | use std::time::Duration; |
| 18 | 18 | ||
| 19 | /// NIP-34 Repository State (kind 30618) | 19 | // NOTE: Using rust-nostr Kind variants: |
| 20 | pub const KIND_STATE: u16 = 30618; | 20 | // - Kind::RepoState.as_u16() -> Kind::RepoState (30618) |
| 21 | 21 | // - Kind::GitPullRequest.as_u16() -> Kind::GitPullRequest (1618) | |
| 22 | /// NIP-34 Pull Request (kind 1618) | ||
| 23 | pub const KIND_PR: u16 = 1618; | ||
| 24 | 22 | ||
| 25 | /// Commit variants for deterministic test commits | 23 | /// Commit variants for deterministic test commits |
| 26 | #[derive(Debug, Clone, Copy)] | 24 | #[derive(Debug, Clone, Copy)] |
| @@ -236,7 +234,7 @@ pub fn create_state_event( | |||
| 236 | )); | 234 | )); |
| 237 | } | 235 | } |
| 238 | 236 | ||
| 239 | EventBuilder::new(Kind::Custom(KIND_STATE), "") | 237 | EventBuilder::new(Kind::RepoState, "") |
| 240 | .tags(event_tags) | 238 | .tags(event_tags) |
| 241 | .sign_with_keys(keys) | 239 | .sign_with_keys(keys) |
| 242 | .map_err(|e| format!("Failed to sign state event: {}", e)) | 240 | .map_err(|e| format!("Failed to sign state event: {}", e)) |
| @@ -269,7 +267,7 @@ pub fn create_pr_event( | |||
| 269 | Tag::custom(TagKind::custom("c"), vec![commit_hash.to_string()]), | 267 | Tag::custom(TagKind::custom("c"), vec![commit_hash.to_string()]), |
| 270 | ]; | 268 | ]; |
| 271 | 269 | ||
| 272 | EventBuilder::new(Kind::Custom(KIND_PR), title) | 270 | EventBuilder::new(Kind::GitPullRequest, title) |
| 273 | .tags(tags) | 271 | .tags(tags) |
| 274 | .sign_with_keys(keys) | 272 | .sign_with_keys(keys) |
| 275 | .map_err(|e| format!("Failed to sign PR event: {}", e)) | 273 | .map_err(|e| format!("Failed to sign PR event: {}", e)) |
| @@ -323,7 +321,7 @@ pub fn create_pr_event_with_clone( | |||
| 323 | tags.push(Tag::custom(TagKind::Clone, urls)); | 321 | tags.push(Tag::custom(TagKind::Clone, urls)); |
| 324 | } | 322 | } |
| 325 | 323 | ||
| 326 | EventBuilder::new(Kind::Custom(KIND_PR), title) | 324 | EventBuilder::new(Kind::GitPullRequest, title) |
| 327 | .tags(tags) | 325 | .tags(tags) |
| 328 | .sign_with_keys(keys) | 326 | .sign_with_keys(keys) |
| 329 | .map_err(|e| format!("Failed to sign PR event: {}", e)) | 327 | .map_err(|e| format!("Failed to sign PR event: {}", e)) |
| @@ -705,7 +703,7 @@ mod tests { | |||
| 705 | ) | 703 | ) |
| 706 | .expect("Failed to create state event"); | 704 | .expect("Failed to create state event"); |
| 707 | 705 | ||
| 708 | assert_eq!(event.kind.as_u16(), KIND_STATE); | 706 | assert_eq!(event.kind.as_u16(), Kind::RepoState.as_u16()); |
| 709 | 707 | ||
| 710 | // Check d-tag | 708 | // Check d-tag |
| 711 | let has_d_tag = event.tags.iter().any(|tag| { | 709 | let has_d_tag = event.tags.iter().any(|tag| { |
| @@ -747,7 +745,7 @@ mod tests { | |||
| 747 | let event = create_pr_event(&keys, &repo_coord, "def456abc123", "Test PR") | 745 | let event = create_pr_event(&keys, &repo_coord, "def456abc123", "Test PR") |
| 748 | .expect("Failed to create PR event"); | 746 | .expect("Failed to create PR event"); |
| 749 | 747 | ||
| 750 | assert_eq!(event.kind.as_u16(), KIND_PR); | 748 | assert_eq!(event.kind.as_u16(), Kind::GitPullRequest.as_u16()); |
| 751 | 749 | ||
| 752 | // Check a-tag | 750 | // Check a-tag |
| 753 | let has_a_tag = event.tags.iter().any(|tag| { | 751 | let has_a_tag = event.tags.iter().any(|tag| { |
| @@ -815,7 +813,7 @@ mod tests { | |||
| 815 | ) | 813 | ) |
| 816 | .expect("Failed to create PR event with clone"); | 814 | .expect("Failed to create PR event with clone"); |
| 817 | 815 | ||
| 818 | assert_eq!(event.kind.as_u16(), KIND_PR); | 816 | assert_eq!(event.kind.as_u16(), Kind::GitPullRequest.as_u16()); |
| 819 | 817 | ||
| 820 | // Check a-tag | 818 | // Check a-tag |
| 821 | let has_a_tag = event.tags.iter().any(|tag| { | 819 | let has_a_tag = event.tags.iter().any(|tag| { |