From 03f18844be43a7ab2c024200a5ad4a17f4e17907 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Wed, 11 Oct 2023 21:35:32 -0500 Subject: [PATCH] Add mock Twilio when not used that rejects all --- unmnemonic_devices_vrs/src/lib.rs | 1 + unmnemonic_devices_vrs/tests/api/helpers.rs | 26 +++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/unmnemonic_devices_vrs/src/lib.rs b/unmnemonic_devices_vrs/src/lib.rs index 00e9c4e2..0c333e48 100644 --- a/unmnemonic_devices_vrs/src/lib.rs +++ b/unmnemonic_devices_vrs/src/lib.rs @@ -19,6 +19,7 @@ pub type AppEngine = Engine>; pub struct InjectableServices { pub db: PgPool, + // FIXME maybe not optional? pub twilio_address: Option, } diff --git a/unmnemonic_devices_vrs/tests/api/helpers.rs b/unmnemonic_devices_vrs/tests/api/helpers.rs index 9e1068fc..12e678cd 100644 --- a/unmnemonic_devices_vrs/tests/api/helpers.rs +++ b/unmnemonic_devices_vrs/tests/api/helpers.rs @@ -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, @@ -25,11 +27,19 @@ pub async fn get( path: &str, skip_redirects: bool, ) -> Result { + 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, @@ -62,10 +72,18 @@ pub async fn post( body: &str, skip_redirects: bool, ) -> Result { + 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;