Skip to content

Commit

Permalink
fix withdrawRequest tag
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Nov 10, 2019
1 parent c0d74a9 commit fc14e5f
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub enum Tag {
#[serde(rename = "withdrawalRequest")]
WithdrawalRequest,
#[serde(rename = "withdrawRequest")]
WithdrawRequest,
}

/// Withdrawal is a withdrawal resource.
Expand All @@ -28,16 +28,38 @@ pub struct Withdrawal {
pub tag: Tag,
}

#[derive(Debug, Serialize, Deserialize)]
pub enum ResponseStatus {
ERROR,
OK,
}

/// Response is the response format returned by Service.
/// Example: `{\"status\":\"ERROR\",\"reason\":\"error detail...\"}"`
#[derive(Debug, Serialize, Deserialize)]
pub struct Response {
pub status: ResponseStatus,
pub reason: Option<String>,
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "status")]
pub enum Response {
#[serde(rename = "ERROR")]
Error { reason: String },
#[serde(rename = "OK")]
Ok,
}

#[cfg(test)]
mod tests {
use crate::lnurl::Response;

#[test]
fn response_from_str() {
let json = r#"{"status":"ERROR","reason":"error detail..."}"#;
let resp: Response = serde_json::from_str(json).unwrap();
assert_eq!(
resp,
Response::Error {
reason: "error detail...".to_string()
}
);
}
#[test]
fn response_to_str() {
let resp = Response::Error {
reason: "error detail...".to_string(),
};
let json = serde_json::to_string(&resp).unwrap();
assert_eq!(json, r#"{"status":"ERROR","reason":"error detail..."}"#);
}
}

0 comments on commit fc14e5f

Please sign in to comment.