Skip to content

Commit

Permalink
Clippy + Cypher fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Sep 18, 2024
1 parent 1c26a43 commit 9c56157
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
35 changes: 23 additions & 12 deletions src/account_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,11 @@ mod tests {
let public_key =
PublicKey::from_hex("89ef92b9ebe6dc1e4ea398f6477f227e95429627b0a33dc89b640e137b256be5")
.unwrap();
let mut metadata = Metadata::default();
metadata.display_name = Some("Alice".to_string());

let metadata = Metadata {
display_name: Some("Alice".to_string()),
..Default::default()
};

let friendly_id =
verified_friendly_id(Some(metadata), &public_key, PanicNip05Verifier).await;
Expand All @@ -275,8 +278,11 @@ mod tests {
let public_key =
PublicKey::from_hex("89ef92b9ebe6dc1e4ea398f6477f227e95429627b0a33dc89b640e137b256be5")
.unwrap();
let mut metadata = Metadata::default();
metadata.name = Some("Alice".to_string());

let metadata = Metadata {
display_name: Some("Alice".to_string()),
..Default::default()
};

let friendly_id =
verified_friendly_id(Some(metadata), &public_key, PanicNip05Verifier).await;
Expand All @@ -289,10 +295,13 @@ mod tests {
let public_key =
PublicKey::from_hex("89ef92b9ebe6dc1e4ea398f6477f227e95429627b0a33dc89b640e137b256be5")
.unwrap();
let mut metadata = Metadata::default();
metadata.display_name = Some("Alice".to_string());
metadata.name = Some("Alice".to_string());
metadata.nip05 = Some("alice@nos.social".to_string());

let metadata = Metadata {
display_name: Some("Alice".to_string()),
name: Some("Alice".to_string()),
nip05: Some("alice@nos.social".to_string()),
..Default::default()
};

let friendly_id =
verified_friendly_id(Some(metadata), &public_key, TrueNip05Verifier).await;
Expand All @@ -308,10 +317,12 @@ mod tests {
let public_key =
PublicKey::from_hex("89ef92b9ebe6dc1e4ea398f6477f227e95429627b0a33dc89b640e137b256be5")
.unwrap();
let mut metadata = Metadata::default();
metadata.display_name = Some("AliceDisplayName".to_string());
metadata.name = Some("AliceName".to_string());
metadata.nip05 = Some("alice@nos.social".to_string());
let metadata = Metadata {
display_name: Some("AliceDisplayName".to_string()),
name: Some("AliceName".to_string()),
nip05: Some("alice@nos.social".to_string()),
..Default::default()
};

let friendly_id =
verified_friendly_id(Some(metadata), &public_key, FalseNip05Verifier).await;
Expand Down
10 changes: 6 additions & 4 deletions src/domain/follows_differ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,8 @@ mod tests {
use tokio::sync::Mutex;
use tokio::time::sleep;

static NOW: LazyLock<DateTime<Utc>> = LazyLock::new(|| {
DateTime::<Utc>::from_timestamp(Utc::now().timestamp() as i64, 0).unwrap()
});
static NOW: LazyLock<DateTime<Utc>> =
LazyLock::new(|| DateTime::<Utc>::from_timestamp(Utc::now().timestamp(), 0).unwrap());

#[derive(Default)]

Expand All @@ -424,8 +423,11 @@ mod tests {
Ok(vec![])
}
}

type TestHashMap =
Arc<Mutex<HashMap<PublicKey, (Vec<ContactListFollow>, Option<DateTime<Utc>>)>>>;
struct MockRepo {
follows: Arc<Mutex<HashMap<PublicKey, (Vec<ContactListFollow>, Option<DateTime<Utc>>)>>>,
follows: TestHashMap,
}

impl Default for MockRepo {
Expand Down
23 changes: 10 additions & 13 deletions src/domain/notification_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ mod tests {
use std::time::Duration;
use tokio::time::advance;

static NOW: LazyLock<DateTime<Utc>> = LazyLock::new(|| {
DateTime::<Utc>::from_timestamp(Utc::now().timestamp() as i64, 0).unwrap()
});
static NOW: LazyLock<DateTime<Utc>> =
LazyLock::new(|| DateTime::<Utc>::from_timestamp(Utc::now().timestamp(), 0).unwrap());

#[test]
fn test_insert_follow_change() {
Expand Down Expand Up @@ -203,15 +202,14 @@ mod tests {
notification_factory.insert(change1.clone().into());
notification_factory.insert(change2.clone().into());

let mut messages = notification_factory.flush();
let messages = notification_factory.flush();
// Both changes should be kept since they have different followees
assert_eq!(
messages.sort(),
assert_bag_eq!(
messages,
[
NotificationMessage::from(Box::new(change1)),
NotificationMessage::from(Box::new(change2))
NotificationMessage::from(Box::new(change1.clone())),
NotificationMessage::from(Box::new(change2.clone()))
]
.sort()
);
}

Expand Down Expand Up @@ -415,7 +413,7 @@ mod tests {

let followee = Keys::generate().public_key();

insert_new_follower(&mut notification_factory, followee.clone());
insert_new_follower(&mut notification_factory, followee);

advance(Duration::from_secs(
min_seconds_between_messages.get() as u64 * 60 + 1,
Expand Down Expand Up @@ -470,7 +468,7 @@ mod tests {
insert_follower(notification_factory, followee, follower)
}

fn insert_new_unfollower<'a>(
fn insert_new_unfollower(
notification_factory: &mut NotificationFactory,
followee: PublicKey,
) -> FollowChange {
Expand Down Expand Up @@ -503,8 +501,7 @@ mod tests {
let mut expected_batches = Vec::new();

for (_, changes) in expected {
let batch: NotificationMessage =
(*changes).to_vec().into_iter().map(|fc| fc.into()).into();
let batch: NotificationMessage = (*changes).iter().cloned().map(|fc| fc.into()).into();
expected_batches.push(batch);
}

Expand Down
4 changes: 2 additions & 2 deletions src/domain/notification_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ mod tests {
let follower2_follow = FollowChange::new_followed(Utc::now(), follower2, followee1);
let follower2_follow2 = FollowChange::new_followed(Utc::now(), follower2, followee1);
let follower3_follow = FollowChange::new_followed(Utc::now(), follower3, followee1);
let wrong_followee_change = FollowChange::new_followed(Utc::now(), follower4, followee2);
let _wrong_followee_change = FollowChange::new_followed(Utc::now(), follower4, followee2);

let mut message = NotificationMessage::new(followee1);

Expand All @@ -214,7 +214,7 @@ mod tests {
#[cfg(not(feature = "ci"))]
{
let result = std::panic::catch_unwind(|| {
NotificationMessage::new(followee1).add(wrong_followee_change.into())
NotificationMessage::new(followee1).add(_wrong_followee_change.into())
});
assert!(result.is_err());
}
Expand Down
4 changes: 2 additions & 2 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl RepoTrait for Repo {
WITH graphName
OPTIONAL MATCH (n:User)-[r:FOLLOWS]->(m:User)
WHERE n.followee_count > 1 AND n.follower_count > 0
WHERE m.followee_count > 1 AND m.follower_count > 0
AND m.followee_count > 1 AND m.follower_count > 0
WITH gds.graph.project(
graphName,
n,
Expand All @@ -334,7 +334,7 @@ impl RepoTrait for Repo {
"#;

// Combined Cypher query to drop, create, run PageRank, and drop again
let query = query(&statements).param("graph_name", graph_name);
let query = query(statements).param("graph_name", graph_name);

self.graph
.run(query)
Expand Down

0 comments on commit 9c56157

Please sign in to comment.