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/sync/metrics.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/sync/metrics.rs')
| -rw-r--r-- | tests/sync/metrics.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index 987b83a..e8c75c7 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs | |||
| @@ -17,7 +17,7 @@ use nostr_sdk::prelude::*; | |||
| 17 | use crate::common::{ | 17 | use crate::common::{ |
| 18 | sync_helpers::{ | 18 | sync_helpers::{ |
| 19 | create_repo_announcement, fetch_metrics, wait_for_sync_connection, MetricsTestHarness, | 19 | create_repo_announcement, fetch_metrics, wait_for_sync_connection, MetricsTestHarness, |
| 20 | ParsedMetrics, TestClient, KIND_REPOSITORY_STATE, | 20 | ParsedMetrics, TestClient, |
| 21 | }, | 21 | }, |
| 22 | TestRelay, | 22 | TestRelay, |
| 23 | }; | 23 | }; |
| @@ -175,8 +175,8 @@ async fn test_metric_values_are_numeric() { | |||
| 175 | // Phase 2: Real Metrics Tests (Using MetricsTestHarness) | 175 | // Phase 2: Real Metrics Tests (Using MetricsTestHarness) |
| 176 | // ============================================================================ | 176 | // ============================================================================ |
| 177 | 177 | ||
| 178 | /// Kind 1617 - Patch event (NIP-34) | 178 | // NOTE: Using rust-nostr Kind variant: |
| 179 | const KIND_PATCH: u16 = 1617; | 179 | // - Kind::GitPatch.as_u16() -> Kind::GitPatch (1617) |
| 180 | 180 | ||
| 181 | /// Create an event referencing a repository coordinate via 'a' tag. | 181 | /// Create an event referencing a repository coordinate via 'a' tag. |
| 182 | /// | 182 | /// |
| @@ -187,7 +187,7 @@ fn create_event_referencing_repo(keys: &Keys, repo_coord: &str, kind: u16, conte | |||
| 187 | vec![repo_coord.to_string()], | 187 | vec![repo_coord.to_string()], |
| 188 | )]; | 188 | )]; |
| 189 | 189 | ||
| 190 | EventBuilder::new(Kind::Custom(kind), content) | 190 | EventBuilder::new(Kind::from_u16(kind), content) |
| 191 | .tags(tags) | 191 | .tags(tags) |
| 192 | .sign_with_keys(keys) | 192 | .sign_with_keys(keys) |
| 193 | .expect("Failed to sign event") | 193 | .expect("Failed to sign event") |
| @@ -239,7 +239,7 @@ async fn test_startup_sync_event_count() { | |||
| 239 | // 5. Build the repo coordinate for the 'a' tag in the patches | 239 | // 5. Build the repo coordinate for the 'a' tag in the patches |
| 240 | let repo_coord = format!( | 240 | let repo_coord = format!( |
| 241 | "{}:{}:{}", | 241 | "{}:{}:{}", |
| 242 | KIND_REPOSITORY_STATE, | 242 | Kind::GitRepoAnnouncement.as_u16(), |
| 243 | keys.public_key().to_hex(), | 243 | keys.public_key().to_hex(), |
| 244 | "test-repo-metrics" | 244 | "test-repo-metrics" |
| 245 | ); | 245 | ); |
| @@ -250,7 +250,7 @@ async fn test_startup_sync_event_count() { | |||
| 250 | create_event_referencing_repo( | 250 | create_event_referencing_repo( |
| 251 | &keys, | 251 | &keys, |
| 252 | &repo_coord, | 252 | &repo_coord, |
| 253 | KIND_PATCH, | 253 | Kind::GitPatch.as_u16(), |
| 254 | &format!("Test patch {}", i), | 254 | &format!("Test patch {}", i), |
| 255 | ) | 255 | ) |
| 256 | }) | 256 | }) |
| @@ -320,7 +320,7 @@ async fn test_startup_sync_event_count() { | |||
| 320 | 320 | ||
| 321 | // 12. Verify patches actually synced (functional check) | 321 | // 12. Verify patches actually synced (functional check) |
| 322 | let filter = Filter::new() | 322 | let filter = Filter::new() |
| 323 | .kind(Kind::Custom(KIND_PATCH)) | 323 | .kind(Kind::Custom(Kind::GitPatch.as_u16())) |
| 324 | .author(keys.public_key()); | 324 | .author(keys.public_key()); |
| 325 | 325 | ||
| 326 | let patches_synced = crate::common::sync_helpers::wait_for_event_on_relay( | 326 | let patches_synced = crate::common::sync_helpers::wait_for_event_on_relay( |