Skip to content

Commit

Permalink
feat: Combined formatPaymentTerm and formatSuperPayTerm (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
lapapooh committed May 10, 2023
1 parent 8943636 commit f42e02d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 82 deletions.
20 changes: 19 additions & 1 deletion src/PaymentTerm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@ export const PAYMENT_TERMS = [

export type PaymentTerm = typeof PAYMENT_TERMS[number];

export const SUPERPAY_TERMS = [
'1_3_days',
'5_days',
'10_days',
'15_days',
'20_days',
] as const;

export type SuperPayTerm = typeof SUPERPAY_TERMS[number];

export function isValidPaymentTerm(input: unknown): input is PaymentTerm {
return PAYMENT_TERMS.includes(input as PaymentTerm);
}

export function isValidSuperPayTerm(input: unknown): input is SuperPayTerm {
return SUPERPAY_TERMS.includes(input as SuperPayTerm);
}

/** @deprecated – use `PAYMENT_TERMS` */
export function listPaymentTerms(): readonly PaymentTerm[] {
return PAYMENT_TERMS;
Expand All @@ -40,7 +54,9 @@ export function formatPaymentTerm(
input: unknown,
{ short = false, fallback = 'Unknown' }: FormatPaymentTermOptions = {},
): string {
if (!isValidPaymentTerm(input)) return fallback;
if (!isValidPaymentTerm(input) && !isValidSuperPayTerm(input)) {
return fallback;
}

switch (input) {
case 'ach':
Expand All @@ -59,6 +75,8 @@ export function formatPaymentTerm(
case 'check_on_pickup':
return short ? 'CKOP' : 'Check on Pickup';

case '1_3_days':
return '1-3 Business Days';
case '5_days':
return '5 Business Days';
case '7_days':
Expand Down
42 changes: 0 additions & 42 deletions src/SuperPayTerm.ts

This file was deleted.

36 changes: 35 additions & 1 deletion src/__tests__/PaymentTerm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { formatPaymentTerm, PAYMENT_TERMS } from '../PaymentTerm';
import {
formatPaymentTerm,
PAYMENT_TERMS,
SUPERPAY_TERMS,
} from '../PaymentTerm';

it('formats known', () => {
PAYMENT_TERMS.map((term) => [
Expand Down Expand Up @@ -110,3 +114,33 @@ it('formats unknown', () => {
formatPaymentTerm('BAR', { fallback: 'No info' }),
).toMatchInlineSnapshot(`"No info"`);
});

it('formats superpay', () => {
SUPERPAY_TERMS.map((term) => [term, formatPaymentTerm(term)]);

expect(SUPERPAY_TERMS.map((term) => [term, formatPaymentTerm(term)]))
.toMatchInlineSnapshot(`
Array [
Array [
"1_3_days",
"1-3 Business Days",
],
Array [
"5_days",
"5 Business Days",
],
Array [
"10_days",
"10 Business Days",
],
Array [
"15_days",
"15 Business Days",
],
Array [
"20_days",
"20 Business Days",
],
]
`);
});
38 changes: 0 additions & 38 deletions src/__tests__/SuperPayTerm.spec.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ it('exports public api', () => {
"45_days",
"60_days",
],
"SUPERPAY_TERMS": Array [
"1_3_days",
"5_days",
"10_days",
"15_days",
"20_days",
],
"VEHICLE_TYPES": Array [
"sedan",
"2_door_coupe",
Expand Down Expand Up @@ -111,6 +118,7 @@ it('exports public api', () => {
"isValidLoadPaymentTerm": [Function],
"isValidPaymentMethod": [Function],
"isValidPaymentTerm": [Function],
"isValidSuperPayTerm": [Function],
"isValidVehicleType": [Function],
"listCustomerTypes": [Function],
"listDateTypes": [Function],
Expand Down

0 comments on commit f42e02d

Please sign in to comment.