Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Jan 5, 2024
1 parent fc7753b commit 9344ca5
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4223,6 +4223,7 @@ async fn works_with_staging_keys_server(notify_server: &NotifyServerContext) {

async fn setup_subscription(
notify_server_url: Url,
notification_types: HashSet<Uuid>,
) -> (
Arc<Client>,
UnboundedReceiver<RelayClientEvent>,
Expand Down Expand Up @@ -4292,7 +4293,7 @@ async fn setup_subscription(
key_agreement,
&app_client_id,
app_domain.clone(),
HashSet::from([Uuid::new_v4()]),
notification_types,
)
.await;
let subs = accept_watch_subscriptions_changed(
Expand Down Expand Up @@ -4337,7 +4338,7 @@ async fn integration_get_notifications_has_none(notify_server: &NotifyServerCont
app_domain,
app_client_id,
notify_key,
) = setup_subscription(notify_server.url.clone()).await;
) = setup_subscription(notify_server.url.clone(), HashSet::from([Uuid::new_v4()])).await;

let result = get_notifications(
&relay_ws_client,
Expand Down Expand Up @@ -4379,6 +4380,7 @@ async fn integration_get_notifications_has_none(notify_server: &NotifyServerCont
#[test_context(NotifyServerContext)]
#[tokio::test]
async fn integration_get_notifications_has_one(notify_server: &NotifyServerContext) {
let notification_type = Uuid::new_v4();
let (
relay_ws_client,
mut rx,
Expand All @@ -4388,10 +4390,14 @@ async fn integration_get_notifications_has_one(notify_server: &NotifyServerConte
app_domain,
app_client_id,
notify_key,
) = setup_subscription(notify_server.url.clone()).await;
) = setup_subscription(
notify_server.url.clone(),
HashSet::from([notification_type]),
)
.await;

let notification = Notification {
r#type: Uuid::new_v4(),
r#type: notification_type,
title: "title".to_owned(),
body: "body".to_owned(),
icon: None,
Expand Down Expand Up @@ -4845,8 +4851,8 @@ async fn get_notifications_6() {

let limit = 5;

let mut gotten_ids = HashSet::with_capacity(7);
let mut gotten_titles = HashSet::with_capacity(7);
let mut gotten_ids = HashSet::with_capacity(6);
let mut gotten_titles = HashSet::with_capacity(6);

let first_page = get_notifications_for_subscriber(
subscriber,
Expand Down Expand Up @@ -4892,7 +4898,7 @@ async fn get_notifications_6() {
.map(|s| s.to_owned())
.collect::<HashSet<_>>()
);
assert_eq!(gotten_ids.len(), 5);
assert_eq!(gotten_ids.len(), 6);
}

#[tokio::test]
Expand Down Expand Up @@ -4948,7 +4954,7 @@ async fn get_notifications_7() {
};

let notification_with_id = upsert_notification(
"test_notification".to_owned(),
Uuid::new_v4().to_string(),
project.id,
notification.clone(),
&postgres,
Expand All @@ -4957,7 +4963,6 @@ async fn get_notifications_7() {
.await
.unwrap();

// Insert notify for delivery
upsert_subscriber_notifications(notification_with_id.id, &[subscriber], &postgres, None)
.await
.unwrap();
Expand Down Expand Up @@ -4999,8 +5004,8 @@ async fn get_notifications_7() {
assert_eq!(second_page.notifications.len(), 2);
assert!(!second_page.has_more);

assert_eq!(&second_page.notifications[0].title, notification_titles[6]);
assert_eq!(&second_page.notifications[1].title, notification_titles[7]);
assert_eq!(&second_page.notifications[0].title, notification_titles[5]);
assert_eq!(&second_page.notifications[1].title, notification_titles[6]);

// TODO apply HashMap approach for all of these?
}
Expand Down Expand Up @@ -5110,8 +5115,8 @@ async fn different_created_at() {
assert_eq!(second_page.notifications.len(), 2);
assert!(!second_page.has_more);

assert_eq!(&second_page.notifications[0].title, notification_titles[6]);
assert_eq!(&second_page.notifications[1].title, notification_titles[7]);
assert_eq!(&second_page.notifications[0].title, notification_titles[5]);
assert_eq!(&second_page.notifications[1].title, notification_titles[6]);
}

#[tokio::test]
Expand Down Expand Up @@ -5179,7 +5184,8 @@ async fn duplicate_created_at() {
.unwrap();

let query = "
INSERT INTO subscriber_notification (notification, subscriber, status, created_at)
INSERT INTO subscriber_notification (notification, subscriber, status)
SELECT $1 AS notification, subscriber, $3::subscriber_notification_status FROM UNNEST($2) AS subscriber
";
sqlx::query(query)
.bind(notification_with_id.id)
Expand Down

0 comments on commit 9344ca5

Please sign in to comment.