mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
added docs and tests
This commit is contained in:
parent
d380f2696f
commit
0913857787
3 changed files with 51 additions and 4 deletions
|
@ -1,5 +1,29 @@
|
|||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||
/// This object represents a portion of the price for goods or services.
|
||||
pub struct LabeledPrice {
|
||||
/// Portion label
|
||||
pub label: String,
|
||||
/// Price of the product in the smallest units of the
|
||||
/// [currency](https://core.telegram.org/bots/payments#supported-currencies)
|
||||
/// (integer, not float/double). For example, for a price of US$ 1.45 pass
|
||||
/// amount = 145. See the exp parameter in [`currencies.json`](https://core.telegram.org/bots/payments/currencies.json),
|
||||
/// it shows the number of digits past the decimal point for each currency
|
||||
/// (2 for the majority of currencies).
|
||||
pub amount: i64,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let labeled_price = LabeledPrice {
|
||||
label: "Label".to_string(),
|
||||
amount: 60
|
||||
};
|
||||
let expected = r#"{"label":"Label","amount":60}"#;
|
||||
let actual = serde_json::to_string(&labeled_price).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
|
||||
pub struct SendInvoice {
|
||||
pub chat_id: i64,
|
||||
pub title: String,
|
||||
|
|
|
@ -1,8 +1,31 @@
|
|||
use crate::core::types::LabeledPrice;
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Serialize)]
|
||||
/// This object represents one shipping option.
|
||||
pub struct ShippingOption {
|
||||
pub id: i64,
|
||||
/// Shipping option identifier
|
||||
pub id: String,
|
||||
/// Option title
|
||||
pub title: String,
|
||||
/// List of price portions
|
||||
pub prices: Vec<LabeledPrice>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serialize() {
|
||||
let shipping_option = ShippingOption {
|
||||
id: "0".to_string(),
|
||||
title: "Option".to_string(),
|
||||
prices: vec![
|
||||
LabeledPrice { label: "Label".to_string(), amount: 60 }
|
||||
]
|
||||
};
|
||||
let expected = r#"{"id":"0","title":"Option","prices":[{"label":"Label","amount":60}]}"#;
|
||||
let actual = serde_json::to_string(&shipping_option).unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue