Skip to content

Commit

Permalink
adding tests to the module
Browse files Browse the repository at this point in the history
  • Loading branch information
princefr committed Dec 26, 2023
1 parent 58f4d22 commit 9ad6fab
Show file tree
Hide file tree
Showing 26 changed files with 1,160 additions and 312 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Testing the application
run-name: MTNMomo Test
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install nitghly
run: |
rustup install nightly
rustup default nightly
- name: Install cargo-make
run: cargo test

release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tag=$(git describe --tags --abbrev=0)
gh release create $tag ./target/release/*
24 changes: 24 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish to crates.io

on:
release:
types:
- created

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Build and publish
run: |
rustup install nightly
cargo login ${{ secrets.BNATOKEN }}
cargo publish --token ${{ secrets.BNATOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/target
.env
Cargo.lock
node_modules
node_modules
collection_access_tokens.db
disbursement_access_tokens.db
remittance_access_tokens.db
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "momo"
name = "mtnmomo"
version = "0.1.0"
edition = "2021"
authors = ["ONDONDA Prince Merveil @princefr"]
Expand Down
24 changes: 24 additions & 0 deletions new_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

# Read the current version from Cargo.toml
current_version=$(jq -r '.package.version' Cargo.toml)

# Increment the version (assuming semantic versioning)
new_version=$(echo $current_version | awk -F. '{$NF = $NF + 1;} 1' OFS=.)

# Update Cargo.toml with the new version
jq --arg new_version "$new_version" '.package.version = $new_version' Cargo.toml > Cargo.toml.tmp
mv Cargo.toml.tmp Cargo.toml

# Commit the changes
git add Cargo.toml
git commit -m "Bump version to $new_version"

# Tag the commit
git tag $new_version

# Push changes and tags to the repository
git push origin main # Change 'main' to your branch name if it's different
git push origin $new_version
12 changes: 6 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
### Installation
```toml
[dependencies]
momo = "0.1.0"
mtnmomo = "0.1.0"
```

or you can use cargo add

```cli
cargo add momo
cargo add mtnmomo
```


### Usage
### Create a new instance of momo
To create an instance of momo you need to have an api_user, url and environment (sandbox or production).
```rust
use momo::Momo;
use mtnmomo::Momo;

fn main() -> () {
let url = "https://sandbox.momodeveloper.mtn.com"; // the url of the api you are using for sandbox please use https://sandbox.momodeveloper.mtn.com
Expand All @@ -34,7 +34,7 @@ To create an instance of momo you need to have an api_user, url and environment
To create an instance of collection you need to have a primary_key and secondary_key of the collection product.
You can get the primary_key and secondary_key from https://momodeveloper.mtn.com when you create a collection product.
```rust
use momo::Momo;
use mtnmomo::Momo;

fn main() -> () {
let url = "https://sandbox.momodeveloper.mtn.com"; // the url of the api you are using for sandbox please use https://sandbox.momodeveloper.mtn.com
Expand All @@ -51,7 +51,7 @@ You can get the primary_key and secondary_key from https://momodeveloper.mtn.com
To create an instance of disbursement you need to have a primary_key and secondary_key of the disbursement product.
You can get the primary_key and secondary_key from https://momodeveloper.mtn.com when you create a disbursement product.
```rust
use momo::Momo;
use mtnmomo::Momo;

fn main() -> () {
let url = "https://sandbox.momodeveloper.mtn.com"; // the url of the api you are using for sandbox please use https://sandbox.momodeveloper.mtn.com
Expand All @@ -67,7 +67,7 @@ You can get the primary_key and secondary_key from https://momodeveloper.mtn.com
To create an instance of disbursement you need to have a primary_key and secondary_key of the remittance product.
You can get the primary_key and secondary_key from https://momodeveloper.mtn.com when you create a remittance product.
```rust
use momo::Momo;
use mtnmomo::Momo;

fn main() -> () {
let url = "https://sandbox.momodeveloper.mtn.com"; // the url of the api you are using for sandbox please use https://sandbox.momodeveloper.mtn.com
Expand Down
20 changes: 20 additions & 0 deletions src/enums/access_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::fmt;

use serde::{Serialize, Deserialize};


#[derive(Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Debug)]
pub enum AccessType {
Online,
Offline,
}


impl fmt::Display for AccessType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
AccessType::Online => write!(f, "online"),
AccessType::Offline => write!(f, "offline"),
}
}
}
136 changes: 136 additions & 0 deletions src/enums/currency.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt;

use serde::{Serialize, Deserialize};


Expand Down Expand Up @@ -134,3 +136,137 @@ pub enum Currency {
SHP,
SSP,
}


impl fmt::Display for Currency {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Currency::USD => write!(f, "USD"),
Currency::EUR => write!(f, "EUR"),
Currency::GBP => write!(f, "GBP"),
Currency::JPY => write!(f, "JPY"),
Currency::AUD => write!(f, "AUD"),
Currency::CAD => write!(f, "CAD"),
Currency::CHF => write!(f, "CHF"),
Currency::CNY => write!(f, "CNY"),
Currency::SEK => write!(f, "SEK"),
Currency::NZD => write!(f, "NZD"),
Currency::MXN => write!(f, "MXN"),
Currency::SGD => write!(f, "SGD"),
Currency::HKD => write!(f, "HKD"),
Currency::NOK => write!(f, "NOK"),
Currency::KRW => write!(f, "KRW"),
Currency::TRY => write!(f, "TRY"),
Currency::RUB => write!(f, "RUB"),
Currency::INR => write!(f, "INR"),
Currency::BRL => write!(f, "BRL"),
Currency::ZAR => write!(f, "ZAR"),
Currency::DKK => write!(f, "DKK"),
Currency::PLN => write!(f, "PLN"),
Currency::TWD => write!(f, "TWD"),
Currency::THB => write!(f, "THB"),
Currency::IDR => write!(f, "IDR"),
Currency::HUF => write!(f, "HUF"),
Currency::CZK => write!(f, "CZK"),
Currency::ILS => write!(f, "ILS"),
Currency::CLP => write!(f, "CLP"),
Currency::PHP => write!(f, "PHP"),
Currency::AED => write!(f, "AED"),
Currency::COP => write!(f, "COP"),
Currency::SAR => write!(f, "SAR"),
Currency::MYR => write!(f, "MYR"),
Currency::RON => write!(f, "RON"),
Currency::PEN => write!(f, "PEN"),
Currency::VND => write!(f, "VND"),
Currency::NGN => write!(f, "NGN"),
Currency::UAH => write!(f, "UAH"),
Currency::PKR => write!(f, "PKR"),
Currency::IQD => write!(f, "IQD"),
Currency::QAR => write!(f, "QAR"),
Currency::KZT => write!(f, "KZT"),
Currency::BHD => write!(f, "BHD"),
Currency::OMR => write!(f, "OMR"),
Currency::KWD => write!(f, "KWD"),
Currency::DZD => write!(f, "DZD"),
Currency::LKR => write!(f, "LKR"),
Currency::BGN => write!(f, "BGN"),
Currency::BDT => write!(f, "BDT"),
Currency::MAD => write!(f, "MAD"),
Currency::VEF => write!(f, "VEF"),
Currency::XOF => write!(f, "XOF"),
Currency::LBP => write!(f, "LBP"),
Currency::UZS => write!(f, "UZS"),
Currency::AZN => write!(f, "AZN"),
Currency::TND => write!(f, "TND"),
Currency::GTQ => write!(f, "GTQ"),
Currency::BOB => write!(f, "BOB"),
Currency::PYG => write!(f, "PYG"),
Currency::PAB => write!(f, "PAB"),
Currency::SVC => write!(f, "SVC"),
Currency::NIO => write!(f, "NIO"),
Currency::HNL => write!(f, "HNL"),
Currency::CRC => write!(f, "CRC"),
Currency::DOP => write!(f, "DOP"),
Currency::BWP => write!(f, "BWP"),
Currency::ISK => write!(f, "ISK"),
Currency::XAF => write!(f, "XAF"),
Currency::TZS => write!(f, "TZS"),
Currency::GHS => write!(f, "GHS"),
Currency::UGX => write!(f, "UGX"),
Currency::MZN => write!(f, "MZN"),
Currency::RSD => write!(f, "RSD"),
Currency::MMK => write!(f, "MMK"),
Currency::LYD => write!(f, "LYD"),
Currency::GEL => write!(f, "GEL"),
Currency::XCD => write!(f, "XCD"),
Currency::BSD => write!(f, "BSD"),
Currency::FJD => write!(f, "FJD"),
Currency::MUR => write!(f, "MUR"),
Currency::KYD => write!(f, "KYD"),
Currency::JMD => write!(f, "JMD"),
Currency::GYD => write!(f, "GYD"),
Currency::MOP => write!(f, "MOP"),
Currency::TTD => write!(f, "TTD"),
Currency::BND => write!(f, "BND"),
Currency::XPF => write!(f, "XPF"),
Currency::NAD => write!(f, "NAD"),
Currency::PGK => write!(f, "PGK"),
Currency::LAK => write!(f, "LAK"),
Currency::BMD => write!(f, "BMD"),
Currency::KHR => write!(f, "KHR"),
Currency::MVR => write!(f, "MVR"),
Currency::GNF => write!(f, "GNF"),
Currency::ALL => write!(f, "ALL"),
Currency::MWK => write!(f, "MWK"),
Currency::ZMW => write!(f, "ZMW"),
Currency::MGA => write!(f, "MGA"),
Currency::ERN => write!(f, "ERN"),
Currency::SCR => write!(f, "SCR"),
Currency::CVE => write!(f, "CVE"),
Currency::SRD => write!(f, "SRD"),
Currency::STD => write!(f, "STD"),
Currency::CDF => write!(f, "CDF"),
Currency::RWF => write!(f, "RWF"),
Currency::ANG => write!(f, "ANG"),
Currency::SBD => write!(f, "SBD"),
Currency::SOS => write!(f, "SOS"),
Currency::HTG => write!(f, "HTG"),
Currency::GMD => write!(f, "GMD"),
Currency::KGS => write!(f, "KGS"),
Currency::TJS => write!(f, "TJS"),
Currency::KPW => write!(f, "KPW"),
Currency::MNT => write!(f, "MNT"),
Currency::CUP => write!(f, "CUP"),
Currency::SLL => write!(f, "SLL"),
Currency::TOP => write!(f, "TOP"),
Currency::MRO => write!(f, "MRO"),
Currency::LSL => write!(f, "LSL"),
Currency::SZL => write!(f, "SZL"),
Currency::BZD => write!(f, "BZD"),
Currency::GWP => write!(f, "GWP"),
Currency::FKP => write!(f, "FKP"),
Currency::SHP => write!(f, "SHP"),
Currency::SSP => write!(f, "SSP"),
}
}
}
3 changes: 2 additions & 1 deletion src/enums/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod currency;
pub mod environment;
pub mod environment;
pub mod access_type;
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ impl Momo {
let provisioning = Provisioning::new(url.clone());
let _create_sandbox = provisioning.create_sandox(&api_user).await?;
let api = provisioning.create_api_information(&api_user).await?;
// create sql lite databases files if they don't exist


Ok(
Momo{
url,
Expand Down
Loading

0 comments on commit 9ad6fab

Please sign in to comment.