Skip to content

Commit

Permalink
Mock pocket client
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao committed May 21, 2024
1 parent 411d67e commit ae06427
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 44 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ name = "uniffi_lipalightninglib"

[dependencies]
parser = { path = "parser" }
pocketclient = { path = "pocketclient" }
pocketclient = { path = "pocketclient", optional = true }
pocketclient-mock = { path = "mock/pocketclient", optional = true }

chameleon = { git = "https://github.com/getlipa/wild", tag = "v1.23.0", optional = true }
chameleon-mock = { path = "mock/wild/chameleon", optional = true }
Expand Down Expand Up @@ -62,8 +63,8 @@ uniffi = "0.27.0"
uuid = { version = "1.8.0", features = ["v5"] }

[features]
default = ["dep:breez-sdk-core", "dep:chameleon", "dep:crow", "dep:honeybadger", "dep:parrot", "dep:pigeon", "dep:squirrel"]
mock-deps = ["dep:breez-sdk-mock", "dep:chameleon-mock", "dep:crow-mock", "dep:honeybadger-mock", "dep:parrot-mock", "dep:pigeon-mock", "dep:squirrel-mock"]
default = ["dep:breez-sdk-core", "dep:chameleon", "dep:crow", "dep:honeybadger", "dep:parrot", "dep:pigeon", "dep:squirrel", "dep:pocketclient"]
mock-deps = ["dep:breez-sdk-mock", "dep:chameleon-mock", "dep:crow-mock", "dep:honeybadger-mock", "dep:parrot-mock", "dep:pigeon-mock", "dep:squirrel-mock", "dep:pocketclient-mock"]

# Bundle sqlite for all targets except iOS.
[target.'cfg(not(target_os = "ios"))'.dependencies]
Expand Down
11 changes: 11 additions & 0 deletions mock/pocketclient/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "pocketclient-mock"
version = "0.1.0"
edition = "2021"

[lib]
name = "pocketclient"

[dependencies]
perro = { git = "https://github.com/getlipa/perro", tag = "v1.2.0" }
pocketclient = { path = "../../pocketclient" }
41 changes: 41 additions & 0 deletions mock/pocketclient/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pub use pocketclient::{FiatTopupInfo, Result};
use std::future::Future;

pub struct PocketClient {}

impl PocketClient {
pub fn new(_pocket_url: String) -> Result<Self> {
Ok(PocketClient {})
}

pub async fn register_pocket_fiat_topup<S, Fut>(
&self,
_user_iban: &str,
_user_currency: String,
_node_pubkey: String,
_sign_message: S,
) -> Result<FiatTopupInfo>
where
S: FnOnce(String) -> Fut,
Fut: Future<Output = Option<String>>,
{
Ok(FiatTopupInfo {
order_id: "Mock order_id".to_string(),
debitor_iban: "Mock debitor_iban".to_string(),
creditor_reference: "Mock creditor_reference".to_string(),
creditor_iban: "Mock creditor_iban".to_string(),
creditor_bank_name: "Mock creditor_bank_name".to_string(),
creditor_bank_street: "Mock creditor_bank_street".to_string(),
creditor_bank_postal_code: "Mock creditor_bank_postal_code".to_string(),
creditor_bank_town: "Mock creditor_bank_town".to_string(),
creditor_bank_country: "Mock creditor_bank_country".to_string(),
creditor_bank_bic: "Mock creditor_bank_bic".to_string(),
creditor_name: "Mock creditor_name".to_string(),
creditor_street: "Mock creditor_street".to_string(),
creditor_postal_code: "Mock creditor_postal_code".to_string(),
creditor_town: "Mock creditor_town".to_string(),
creditor_country: "Mock creditor_country".to_string(),
currency: "Mock currency".to_string(),
})
}
}
41 changes: 0 additions & 41 deletions pocketclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ impl PocketClient {
)
}

#[cfg(not(feature = "mock-deps"))]
async fn create_order<S, Fut>(
&self,
challenge_response: ChallengeResponse,
Expand Down Expand Up @@ -269,44 +268,4 @@ impl PocketClient {
"Failed to parse CreateOrderResponse",
)
}

#[cfg(feature = "mock-deps")]
// todo: Instead of mocking this method only, we should move the entire PocketClient to a separate crate and mock the entire crate.
fn create_order(
&self,
_challenge_response: ChallengeResponse,
_user_iban: &str,
_user_currency: String,
) -> Result<CreateOrderResponse> {
let now: DateTime<Utc> = Utc::now();
Ok(CreateOrderResponse {
id: format!("mock-order-id-{now}"),
active: true,
created_on: None,
affiliate_id: None,
fee_rate: 0.0,
payment_method: PaymentMethodResponse {
currency: "".to_string(),
debitor_iban: "".to_string(),
creditor_reference: "".to_string(),
creditor_iban: "".to_string(),
creditor_bank_name: "".to_string(),
creditor_bank_street: "".to_string(),
creditor_bank_postal_code: "".to_string(),
creditor_bank_town: "".to_string(),
creditor_bank_country: "".to_string(),
creditor_bank_bic: "".to_string(),
creditor_name: "".to_string(),
creditor_street: "".to_string(),
creditor_postal_code: "".to_string(),
creditor_town: "".to_string(),
creditor_country: "".to_string(),
},
payout_method: PayoutMethod {
node_pubkey: "".to_string(),
message: "".to_string(),
signature: "".to_string(),
},
})
}
}

0 comments on commit ae06427

Please sign in to comment.