Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge pull request #1941 from zed-industries/Allow-overwriting-signup-data
Joseph T. Lyonsdcd4b8f7dbad
diff --cc crates/collab/src/db/tests.rsindex e1c9e04812e,e3819116a04..2d254c2e370--- a/crates/collab/src/db/tests.rs+++ b/crates/collab/src/db/tests.rs@@@ -731,79 -728,88 +734,159 @@@ async fn test_invite_codes().unwrap_err();let (_, invite_count) = db.get_invite_code_for_user(user1).await.unwrap().unwrap();assert_eq!(invite_count, 1);++ // A newer user can invite an existing one via a different email address+ // than the one they used to sign up.+ let user5 = db+ .create_user(+ "[email protected]",+ false,+ NewUserParams {+ github_login: "user5".into(),+ github_user_id: 5,+ invite_count: 0,+ },+ )+ .await+ .unwrap()+ .user_id;+ db.set_invite_count_for_user(user5, 5).await.unwrap();+ let (user5_invite_code, _) = db.get_invite_code_for_user(user5).await.unwrap().unwrap();+ let user5_invite_to_user1 = db+ .create_invite_from_code(&user5_invite_code, "[email protected]", None)+ .await+ .unwrap();+ let user1_2 = db+ .create_user_from_invite(+ &user5_invite_to_user1,+ NewUserParams {+ github_login: "user1".into(),+ github_user_id: 1,+ invite_count: 5,+ },+ )+ .await+ .unwrap()+ .unwrap()+ .user_id;+ assert_eq!(user1_2, user1);+ assert_eq!(+ db.get_contacts(user1).await.unwrap(),+ [+ Contact::Accepted {+ user_id: user2,+ should_notify: true,+ busy: false,+ },+ Contact::Accepted {+ user_id: user3,+ should_notify: true,+ busy: false,+ },+ Contact::Accepted {+ user_id: user4,+ should_notify: true,+ busy: false,+ },+ Contact::Accepted {+ user_id: user5,+ should_notify: false,+ busy: false,+ }+ ]+ );+ assert_eq!(+ db.get_contacts(user5).await.unwrap(),+ [Contact::Accepted {+ user_id: user1,+ should_notify: true,+ busy: false,+ }]+ );+ assert!(db.has_contact(user1, user5).await.unwrap());+ assert!(db.has_contact(user5, user1).await.unwrap());}+ #[gpui::test]+ async fn test_multiple_signup_overwrite() {+ let test_db = TestDb::postgres(build_background_executor());+ let db = test_db.db();++ let email_address = "[email protected]".to_string();++ let initial_signup_created_at_milliseconds = 0;++ let initial_signup = NewSignup {+ email_address: email_address.clone(),+ platform_mac: false,+ platform_linux: true,+ platform_windows: false,+ editor_features: vec!["speed".into()],+ 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();++ let initial_signup_from_db = db.get_signup(&email_address).await.unwrap();++ assert_eq!(+ initial_signup_from_db.clone(),+ signup::Model {+ email_address: initial_signup.email_address,+ platform_mac: initial_signup.platform_mac,+ platform_linux: initial_signup.platform_linux,+ platform_windows: initial_signup.platform_windows,+ editor_features: Some(initial_signup.editor_features),+ programming_languages: Some(initial_signup.programming_languages),+ added_to_mailing_list: initial_signup.added_to_mailing_list,+ ..initial_signup_from_db+ }+ );++ let subsequent_signup = NewSignup {+ email_address: email_address.clone(),+ platform_mac: true,+ platform_linux: false,+ platform_windows: true,+ editor_features: vec!["git integration".into(), "clean design".into()],+ 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();++ let subsequent_signup_from_db = db.get_signup(&email_address).await.unwrap();++ assert_eq!(+ subsequent_signup_from_db.clone(),+ signup::Model {+ platform_mac: subsequent_signup.platform_mac,+ platform_linux: subsequent_signup.platform_linux,+ platform_windows: subsequent_signup.platform_windows,+ editor_features: Some(subsequent_signup.editor_features),+ programming_languages: Some(subsequent_signup.programming_languages),+ device_id: subsequent_signup.device_id,+ added_to_mailing_list: subsequent_signup.added_to_mailing_list,+ // shouldn't overwrite their creation Datetime - user shouldn't lose their spot in line+ created_at: initial_signup_from_db.created_at,+ ..subsequent_signup_from_db+ }+ );+ }+#[gpui::test]async fn test_signups() {let test_db = TestDb::postgres(build_background_executor());