From a36794c5d3bce9477f7f6424ed714686db4ff1f1 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 1 Feb 2022 18:30:40 +0300 Subject: [PATCH 1/2] Make `WebhookInfo::allowed_updates` typed --- CHANGELOG.md | 4 +++- src/types/webhook_info.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc2bb592..3422d890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,7 +51,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - How forwarded messages are represented ([#151][pr151]) - `RequestError::InvalidJson` now has a `raw` field with raw json for easier debugability ([#150][pr150]) - `ChatPermissions` is now bitflags ([#157][pr157]) -- Type of `WebhookInfo::ip_address` from `String` to `std::net::IpAddr` ([#172][pr172]) +- Type of `WebhookInfo::ip_address` from `Option` to `Option` ([#172][pr172]) +- Type of `WebhookInfo::allowed_updates` from `Option>` to `Option>` ([#174][pr174]) [pr115]: https://github.com/teloxide/teloxide-core/pull/115 [pr125]: https://github.com/teloxide/teloxide-core/pull/125 @@ -60,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr157]: https://github.com/teloxide/teloxide-core/pull/157 [pr167]: https://github.com/teloxide/teloxide-core/pull/167 [pr172]: https://github.com/teloxide/teloxide-core/pull/172 +[pr174]: https://github.com/teloxide/teloxide-core/pull/174 ### Fixed diff --git a/src/types/webhook_info.rs b/src/types/webhook_info.rs index 7a3d2f91..687d9f21 100644 --- a/src/types/webhook_info.rs +++ b/src/types/webhook_info.rs @@ -3,6 +3,8 @@ use std::net::IpAddr; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; +use crate::types::AllowedUpdate; + /// Contains information about the current status of a webhook. /// /// [The official docs](https://core.telegram.org/bots/api#webhookinfo). @@ -38,5 +40,5 @@ pub struct WebhookInfo { /// A list of update types the bot is subscribed to. Defaults to all update /// types. - pub allowed_updates: Option>, + pub allowed_updates: Option>, } From 16630133db246224f5a40c7c1df2024e5cb78d05 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 1 Feb 2022 18:31:04 +0300 Subject: [PATCH 2/2] Add regression test for `WebhookInfo` with an empty url --- src/types/webhook_info.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/types/webhook_info.rs b/src/types/webhook_info.rs index 687d9f21..6c9d031f 100644 --- a/src/types/webhook_info.rs +++ b/src/types/webhook_info.rs @@ -42,3 +42,25 @@ pub struct WebhookInfo { /// types. pub allowed_updates: Option>, } + +// Regression test for +#[test] +fn empty_url() { + let json = r#"{"url":"","has_custom_certificate":false,"pending_update_count":0,"allowed_updates":["message"]}"#; + let actual: WebhookInfo = serde_json::from_str(json).unwrap(); + let expected = WebhookInfo { + url: None, + has_custom_certificate: false, + pending_update_count: 0, + ip_address: None, + last_error_date: None, + last_error_message: None, + max_connections: None, + allowed_updates: Some(vec![AllowedUpdate::Message]), + }; + + assert_eq!(actual, expected); + + let json = r#"{"ok":true,"result":{"url":"","has_custom_certificate":false,"pending_update_count":0,"allowed_updates":["message"]}}"#; + serde_json::from_str::>(json).unwrap(); +}