Merge pull request #174 from teloxide/typed_webhookinfo_allowed_updates

Make `WebhookInfo::allowed_updates` typed
This commit is contained in:
Waffle Maybe 2022-02-01 18:35:40 +03:00 committed by GitHub
commit b1f10c91cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View file

@ -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<String>` to `Option<std::net::IpAddr>` ([#172][pr172])
- Type of `WebhookInfo::allowed_updates` from `Option<Vec<String>>` to `Option<Vec<AllowedUpdate>>` ([#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

View file

@ -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,27 @@ pub struct WebhookInfo {
/// A list of update types the bot is subscribed to. Defaults to all update
/// types.
pub allowed_updates: Option<Vec<String>>,
pub allowed_updates: Option<Vec<AllowedUpdate>>,
}
// Regression test for <https://github.com/teloxide/teloxide-core/pull/166>
#[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::<crate::net::TelegramResponse<WebhookInfo>>(json).unwrap();
}