-
Notifications
You must be signed in to change notification settings - Fork 53
feat(kes): add M-Pesa channel foundations #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { | ||
| expandKesMpesaInstitutions, | ||
| getOfframpAccountIdentifierPlaceholder, | ||
| formatKesMpesaAccountDisplay, | ||
| getKesMpesaInstitutionLabel, | ||
| KES_MPESA_INSTITUTION_CODE, | ||
| } from "../app/utils"; | ||
| import type { InstitutionProps } from "../app/types"; | ||
|
|
||
| describe("KES M-Pesa virtual institution split", () => { | ||
| const baseInstitutions: InstitutionProps[] = [ | ||
| { name: "SAFARICOM", code: "SAFAKEPC", type: "mobile_money" }, | ||
| { name: "AIRTEL", code: "AIRTKEPC", type: "mobile_money" }, | ||
| { name: "Equity Bank", code: "EQTYKEPC", type: "bank" }, | ||
| ]; | ||
|
|
||
| it("expands SAFAKEPC into Send Money / Till / Paybill for KES", () => { | ||
| const expanded = expandKesMpesaInstitutions(baseInstitutions, "KES"); | ||
| expect(expanded).toHaveLength(5); | ||
| const mpesa = expanded.filter((i) => i.code === KES_MPESA_INSTITUTION_CODE); | ||
| expect(mpesa.map((i) => i.name)).toEqual([ | ||
| "M-PESA (Send Money)", | ||
| "M-PESA (Till)", | ||
| "M-PESA (Paybill)", | ||
| ]); | ||
| expect(mpesa.every((i) => i.code === "SAFAKEPC")).toBe(true); | ||
| expect(mpesa.map((i) => i.channel)).toEqual(["Mobile", "Till", "Paybill"]); | ||
| expect(expanded.find((i) => i.code === "AIRTKEPC")?.name).toBe("AIRTEL"); | ||
| }); | ||
|
|
||
| it("does not expand SAFAKEPC for non-KES currencies", () => { | ||
| const expanded = expandKesMpesaInstitutions(baseInstitutions, "NGN"); | ||
| expect(expanded).toHaveLength(3); | ||
| expect(expanded.find((i) => i.code === "SAFAKEPC")?.name).toBe("SAFARICOM"); | ||
| }); | ||
|
|
||
| it("returns channel-aware placeholders", () => { | ||
| expect( | ||
| getOfframpAccountIdentifierPlaceholder("KES", "mobile_money", "Mobile"), | ||
| ).toBe("07XXXXXXXX"); | ||
| expect( | ||
| getOfframpAccountIdentifierPlaceholder("KES", "mobile_money", "Till"), | ||
| ).toBe("Till number (5–7 digits)"); | ||
| expect( | ||
| getOfframpAccountIdentifierPlaceholder("KES", "mobile_money", "Paybill"), | ||
| ).toBe("Account / reference"); | ||
| }); | ||
|
|
||
| it("formats preview/history account lines", () => { | ||
| expect(formatKesMpesaAccountDisplay("0712345678", "Mobile")).toBe( | ||
| "0712345678 • M-PESA", | ||
| ); | ||
| expect(formatKesMpesaAccountDisplay("123456", "Till")).toBe( | ||
| "Till • 123456 • M-PESA", | ||
| ); | ||
| expect(formatKesMpesaAccountDisplay("INV-001", "Paybill", "400200")).toBe( | ||
| "Paybill • 400200 / INV-001 • M-PESA", | ||
| ); | ||
| expect(getKesMpesaInstitutionLabel("Till")).toBe("M-PESA (Till)"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Handle channel-less KES M-Pesa recipients explicitly.
When
supportedInstitutionscontainsexpandKesMpesaInstitutions(...)output, a legacy recipient without optionalchannelfalls through togetInstitutionNameByCodeand is labeled M-PESA (Send Money) because it is the firstSAFAKEPCmatch. Return the genericM-PESAlabel for KES/SAFAKEPCrecords with no channel, and add a regression test.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents