Исправление тестов.

FCMClient теперь не инициализируется, если отсутствует требуемая переменная окружения.
This commit is contained in:
2025-04-16 16:38:37 +04:00
parent e71ab0526d
commit 28f59389ed
3 changed files with 12 additions and 2 deletions

View File

@@ -56,7 +56,7 @@ pub struct AppState {
pub schedule: Mutex<Option<Schedule>>, pub schedule: Mutex<Option<Schedule>>,
pub database: Mutex<PgConnection>, pub database: Mutex<PgConnection>,
pub vk_id: VkId, pub vk_id: VkId,
pub fcm_client: Mutex<FCMClient>, pub fcm_client: Option<Mutex<FCMClient>>, // в рантайме не меняется, так что опционален мьютекс, а не данные в нём.
} }
impl AppState { impl AppState {
@@ -71,7 +71,13 @@ impl AppState {
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url)), .unwrap_or_else(|_| panic!("Error connecting to {}", database_url)),
), ),
vk_id: VkId::new(), vk_id: VkId::new(),
fcm_client: Mutex::new(FCMClient::new().await.expect("FCM client must be created")), fcm_client: if env::var("GOOGLE_APPLICATION_CREDENTIALS").is_ok() {
Some(Mutex::new(
FCMClient::new().await.expect("FCM client must be created"),
))
} else {
None
},
} }
} }
} }

View File

@@ -567,6 +567,8 @@ fn convert_groups_to_teachers(
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use schedule_parser_rusted::parser::parse_xls;
///
/// let result = parse_xls(&include_bytes!("../../schedule.xls").to_vec()); /// let result = parse_xls(&include_bytes!("../../schedule.xls").to_vec());
/// ///
/// assert!(result.is_ok()); /// assert!(result.is_ok());

View File

@@ -78,6 +78,8 @@ pub async fn set_token(
// Subscribe to default topics. // Subscribe to default topics.
if let Some(e) = app_state if let Some(e) = app_state
.fcm_client .fcm_client
.as_ref()
.unwrap()
.async_scope( .async_scope(
async |client: &mut FCMClient| -> Result<(), TopicManagementError> { async |client: &mut FCMClient| -> Result<(), TopicManagementError> {
let mut tokens: Vec<String> = Vec::new(); let mut tokens: Vec<String> = Vec::new();