Skip to content

Commit

Permalink
chore: add common module
Browse files Browse the repository at this point in the history
  • Loading branch information
itsyaasir committed Aug 20, 2023
1 parent 7182252 commit 53f70aa
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use pesapal::{Environment, PesaPal};
use serde_json::json;
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};

pub(crate) async fn pesapal_client() -> (PesaPal, MockServer) {
dotenvy::dotenv().ok();
let server = MockServer::start().await;

let client = PesaPal::new(
dotenvy::var("CONSUMER_KEY").expect("consumer_key not present"),
dotenvy::var("CONSUMER_SECRET").expect("consumer_secret not present"),
Environment::Custom(server.uri()),
);

let auth_response = json!({
"token": "token",
"expiry_date": "2021-08-26T12:29:30.5177702Z",
"error": null,
"status": "200",
"message": "Request processed successfully"
});

Mock::given(method("POST"))
.and(path("/api/Auth/RequestToken"))
.respond_with(ResponseTemplate::new(200).set_body_json(auth_response))
.expect(1)
.mount(&server)
.await;

(client, server)
}

0 comments on commit 53f70aa

Please sign in to comment.