Skip to content

Commit

Permalink
Add mock Twilio when not used that rejects all
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Oct 12, 2023
1 parent 9fd9045 commit 03f1884
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions unmnemonic_devices_vrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub type AppEngine = Engine<Handlebars<'static>>;

pub struct InjectableServices {
pub db: PgPool,
// FIXME maybe not optional?
pub twilio_address: Option<String>,
}

Expand Down
26 changes: 22 additions & 4 deletions unmnemonic_devices_vrs/tests/api/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use axum::Server;
use sqlx::PgPool;
use std::net::TcpListener;
use unmnemonic_devices_vrs::{app, InjectableServices};
use wiremock::matchers::any;
use wiremock::{Mock, MockServer, ResponseTemplate};

pub struct TestApp {
pub address: String,
Expand All @@ -25,11 +27,19 @@ pub async fn get(
path: &str,
skip_redirects: bool,
) -> Result<reqwest::Response, reqwest::Error> {
let mock_twilio = MockServer::start().await;

Mock::given(any())
.respond_with(ResponseTemplate::new(500))
.expect(0)
.named("Mock Twilio API")
.mount(&mock_twilio)
.await;

get_with_twilio(
InjectableServices {
db,
// FIXME should this be a mock server that rejects everything
twilio_address: Some("https://api.twilio.com".to_string()),
twilio_address: Some(mock_twilio.uri()),
},
path,
skip_redirects,
Expand Down Expand Up @@ -62,10 +72,18 @@ pub async fn post(
body: &str,
skip_redirects: bool,
) -> Result<reqwest::Response, reqwest::Error> {
let mock_twilio = MockServer::start().await;

Mock::given(any())
.respond_with(ResponseTemplate::new(500))
.expect(0)
.named("Mock Twilio API")
.mount(&mock_twilio)
.await;

let app_address = spawn_app(InjectableServices {
db,
// FIXME same as above
twilio_address: Some("https://api.twilio.com".to_string()),
twilio_address: Some(mock_twilio.uri()),
})
.await
.address;
Expand Down

0 comments on commit 03f1884

Please sign in to comment.