Skip to content

Commit

Permalink
added more tests to cover the new adjustments to the mpesa b2c paymen…
Browse files Browse the repository at this point in the history
…t document.
  • Loading branch information
GichanaMayaka committed Nov 16, 2023
1 parent 8dc590b commit 1b8e489
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
IncorrectStatusError,
InsufficientPaymentAmountError,
InvalidReceiverMobileNumberError,
InformationMismatchError,
)
from ..mpesa_b2c_payment.mpesa_b2c_payment import extract_transaction_values

Expand Down Expand Up @@ -63,12 +64,15 @@ def create_mpesa_b2c_payment() -> None:
frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Not Initiated",
"partyb": "254708993268",
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

Expand All @@ -90,48 +94,60 @@ def test_invalid_receiver_number(self) -> None:
frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Not Initiated",
"partyb": "2547089932680",
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Not Initiated",
"partyb": "25470899326",
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Not Initiated",
"partyb": 254103456789,
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Not Initiated",
"partyb": 254113456789,
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

Expand Down Expand Up @@ -166,28 +182,34 @@ def test_insufficient_amount(self) -> None:
frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Not Initiated",
"partyb": "254708993268",
"amount": 9.9999999,
"amount": 9.99,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

def test_incredibly_large_amount(self) -> None:
def test_arbitrarily_large_amount(self) -> None:
"""Tests when an incredibly large number has been supplied"""
large_number = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
with self.assertRaises(pymysql.err.DataError):
frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Not Initiated",
"partyb": "254708993268",
"amount": large_number,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

Expand All @@ -196,12 +218,15 @@ def test_valid_originator_conversation_id_length(self) -> None:
new_mpesa_b2c_payment = frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Not Initiated",
"partyb": "254708993268",
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

Expand All @@ -213,12 +238,15 @@ def test_invalid_errored_status_no_code_or_error_description(self) -> None:
frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"status": "Errored",
"partyb": "254708993268",
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

Expand All @@ -230,16 +258,49 @@ def test_status_set_to_not_initiated_when_not_supplied(self) -> None:
new_doc = frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"partyb": "254708993268",
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

self.assertEqual(new_doc.status, "Not Initiated")

def test_mismatch_in_command_id_and_party_type(self) -> None:
"""Tests for mismatch between the party type and command id fields"""
with self.assertRaises(InformationMismatchError):
frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "SalaryPayment",
"remarks": "test remarks",
"partyb": "254708993268",
"amount": 10,
"occassion": "Testing",
"party_type": "Supplier",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()
frappe.get_doc(
{
"doctype": "MPesa B2C Payment",
"commandid": "BusinessPayment",
"remarks": "test remarks",
"partyb": "254708993268",
"amount": 10,
"occassion": "Testing",
"party_type": "Employee",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

def test_extract_transaction_values(self) -> None:
"""Tests extract_transaction_values() from the mpesa_b2c_payment module"""
transaction_values = extract_transaction_values(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def create_b2c_payment_transaction() -> None:
"partyb": "254712345678",
"amount": 10,
"occassion": "Testing",
"party_type": "Employee",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

Expand All @@ -44,6 +47,9 @@ def create_b2c_payment_transaction() -> None:
"partyb": "254712345678",
"amount": 10,
"occassion": "Testing",
"party_type": "Employee",
"account_paid_from": "Cash - NVR",
"account_paid_to": "Debtors - NVR",
}
).insert()

Expand Down

0 comments on commit 1b8e489

Please sign in to comment.