From d71d543337abb108bd3ea4b1f5b24729d78ac5e7 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Wed, 7 Dec 2022 08:15:01 -0500 Subject: [PATCH] Ensure that subsequent signup happens after initial We can't rely on the fact that the test won't run fast enough such that both `created_at`s are the same time. This ensures the subsequent signup happens after the initial one and that the database doesn't overwrite the initial one. --- crates/collab/src/db/signup.rs | 1 + crates/collab/src/db/tests.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/crates/collab/src/db/signup.rs b/crates/collab/src/db/signup.rs index 5d5a9a1b6113e60cb0c3b3c44f60b5df802dc94a..6368482de936b53b92bc27cd45ef0be0603e1f8c 100644 --- a/crates/collab/src/db/signup.rs +++ b/crates/collab/src/db/signup.rs @@ -44,6 +44,7 @@ pub struct NewSignup { pub programming_languages: Vec, pub device_id: Option, pub added_to_mailing_list: bool, + pub created_at: Option, } #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, FromQueryResult)] diff --git a/crates/collab/src/db/tests.rs b/crates/collab/src/db/tests.rs index 84cf4229762576b14c39105af41e38c2c142b8f4..e3819116a0404a16934ebce01c7c4f8c28636d60 100644 --- a/crates/collab/src/db/tests.rs +++ b/crates/collab/src/db/tests.rs @@ -737,6 +737,8 @@ async fn test_multiple_signup_overwrite() { let email_address = "user_1@example.com".to_string(); + let initial_signup_created_at_milliseconds = 0; + let initial_signup = NewSignup { email_address: email_address.clone(), platform_mac: false, @@ -746,6 +748,9 @@ async fn test_multiple_signup_overwrite() { programming_languages: vec!["rust".into(), "c".into()], device_id: Some(format!("device_id")), added_to_mailing_list: false, + created_at: Some( + DateTime::from_timestamp_millis(initial_signup_created_at_milliseconds).unwrap(), + ), }; db.create_signup(&initial_signup).await.unwrap(); @@ -775,6 +780,13 @@ async fn test_multiple_signup_overwrite() { programming_languages: vec!["d".into(), "elm".into()], device_id: Some(format!("different_device_id")), added_to_mailing_list: true, + // subsequent signup happens next day + created_at: Some( + DateTime::from_timestamp_millis( + initial_signup_created_at_milliseconds + (1000 * 60 * 60 * 24), + ) + .unwrap(), + ), }; db.create_signup(&subsequent_signup).await.unwrap(); @@ -817,6 +829,7 @@ async fn test_signups() { programming_languages: vec!["rust".into(), "c".into()], device_id: Some(format!("device_id_{i}")), added_to_mailing_list: i != 0, // One user failed to subscribe + created_at: Some(DateTime::from_timestamp_millis(i as i64).unwrap()), // Signups are consecutive }) .collect::>();