Skip to content

Commit

Permalink
Added Test Delays
Browse files Browse the repository at this point in the history
Supabase sets rate limits, so a one-minute delay has been added when
tests send emails to ensure we don't hit them.

Added Additional Delay
  • Loading branch information
Proziam committed Oct 12, 2024
1 parent 43fbe3a commit 4050022
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions tests/client_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::HashMap, env};
use core::time;
use std::{collections::HashMap, env, thread};

use supabase_auth::models::{
AuthClient, DesktopResendParams, LogoutScope, ResendParams, SignInWithOAuthOptions,
Expand Down Expand Up @@ -59,6 +60,10 @@ async fn sign_up_with_email_test_valid() {
.await
.unwrap();

// Wait to prevent running into Supabase rate limits when running cargo test
let one_minute = time::Duration::from_secs(60);
thread::sleep(one_minute);

assert!(session.user.email == demo_email)
}

Expand Down Expand Up @@ -95,40 +100,37 @@ async fn send_login_email_with_magic_link() {

let demo_email = env::var("DEMO_EMAIL").unwrap();

let _response = auth_client
let response = auth_client
.send_login_email_with_magic_link(demo_email)
.await;

assert!(_response.is_ok())
}

#[tokio::test]
async fn send_email_with_otp() {
let auth_client = create_test_client();

let demo_email = env::var("DEMO_EMAIL").unwrap();

let response = auth_client.send_email_with_otp(demo_email, None).await;

if response.is_err() {
eprintln!("{:?}", response.as_ref().unwrap_err())
}

// Wait to prevent running into Supabase rate limits when running cargo test
let one_minute = time::Duration::from_secs(60);
thread::sleep(one_minute);

assert!(response.is_ok())
}

#[tokio::test]
async fn send_sms_with_otp() {
async fn send_email_with_otp() {
let auth_client = create_test_client();

let demo_phone = env::var("DEMO_PHONE").unwrap();
let demo_email = env::var("DEMO_EMAIL").unwrap();

let response = auth_client.send_sms_with_otp(demo_phone).await;
let response = auth_client.send_email_with_otp(demo_email, None).await;

if response.is_err() {
eprintln!("{:?}", response.as_ref().unwrap_err())
}

// Wait to prevent running into Supabase rate limits when running cargo test
let one_minute = time::Duration::from_secs(60);
thread::sleep(one_minute);

assert!(response.is_ok())
}

Expand Down Expand Up @@ -316,6 +318,10 @@ async fn reset_password_for_email_test() {

let response = auth_client.reset_password_for_email(demo_email).await;

// Wait to prevent running into Supabase rate limits when running cargo test
let one_minute = time::Duration::from_secs(60);
thread::sleep(one_minute);

assert!(response.is_ok())
}

Expand All @@ -342,6 +348,10 @@ async fn resend_email_test() {
options: None,
};

// Wait to prevent running into Supabase rate limits when running cargo test
let one_minute = time::Duration::from_secs(60);
thread::sleep(one_minute);

let response = auth_client.resend(ResendParams::Desktop(credentials)).await;

assert!(response.is_ok() && session.unwrap().user.email == demo_email)
Expand Down

0 comments on commit 4050022

Please sign in to comment.