Skip to content
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

ON-43523 # Added formatDate to getDisplayDetailsFromFormSubmissionPay… #95

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/paymentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,32 @@ type PaymentDisplayDetail = {
*
* ```js
* const detailItems =
* paymentService.getDisplayDetailsFromFormSubmissionPayment({
* paymentService.getDisplayDetailsFromFormSubmissionPayment(
* formSubmissionPayment,
* formatCurrency,
* })
* {
* formatCurrency,
* formatDateTime,
* formatDate,
* },
* )
* ```
*
* @param formSubmissionPayment
* @param options
* @returns
*/
export const getDisplayDetailsFromFormSubmissionPayment = ({
formSubmissionPayment,
formatCurrency,
formatDateTime,
}: {
export const getDisplayDetailsFromFormSubmissionPayment = (
/** The form submission payment to get the details from */
formSubmissionPayment: SubmissionTypes.FormSubmissionPayment
/** A function to format any curreny values */
formatCurrency: ReplaceInjectablesFormatters['formatCurrency']
/**
* A function to format any dates. If this is not passed, datetimes will be
* returned as iso strings.
*/
formatDateTime: ReplaceInjectablesFormatters['formatDateTime']
}): PaymentDisplayDetail[] => {
formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,
{
formatCurrency,
formatDateTime,
formatDate,
}: Pick<
ReplaceInjectablesFormatters,
'formatCurrency' | 'formatDate' | 'formatDateTime'
>,
): PaymentDisplayDetail[] => {
switch (formSubmissionPayment.type) {
case 'NSW_GOV_PAY': {
const { paymentTransaction } = formSubmissionPayment
Expand Down Expand Up @@ -417,7 +419,7 @@ export const getDisplayDetailsFromFormSubmissionPayment = ({
{
key: 'settlementDate',
label: 'Settlement Date',
value: formatDateTime(paymentTransaction.settlementDate),
value: formatDate(paymentTransaction.settlementDate),
},
]
}
Expand Down
5 changes: 5 additions & 0 deletions src/replaceCustomValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ import {
import { findFormElement, flattenFormElements } from './formElementsService'

export type ReplaceInjectablesFormatters = {
/** A function to format any date/times. */
formatDateTime: (value: string) => string
/** A function to format any dates. */
formatDate: (value: string) => string
/** A function to format any times. */
formatTime: (value: string) => string
/** A function to format any numbers. */
formatNumber: (value: number) => string
/** A function to format any numbers as currency. */
formatCurrency: (value: number) => string
}

Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/paymentService.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ exports[`getDisplayDetailsFromFormSubmissionPayment Westpac gets the correct det
{
"key": "settlementDate",
"label": "Settlement Date",
"value": "11/09/2024 12:00:00 PM",
"value": "11/09/2024",
},
]
`;
63 changes: 24 additions & 39 deletions tests/paymentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { SubmissionTypes } from '@oneblink/types'
import { paymentService } from '../src'

describe('getDisplayDetailsFromFormSubmissionPayment', () => {
const formatCurrency = (amount: number) => `$${amount.toFixed(2)}`
const formatDateTime = () => '11/09/2024 12:00:00 PM'
const formatters = {
formatCurrency: (amount: number) => `$${amount.toFixed(2)}`,
formatDateTime: () => '11/09/2024 12:00:00 PM',
formatDate: () => '11/09/2024',
}

describe('NSW Gov Pay', () => {
const formSubmissionPayment: SubmissionTypes.FormSubmissionPayment = {
Expand Down Expand Up @@ -43,33 +46,27 @@ describe('getDisplayDetailsFromFormSubmissionPayment', () => {

it('gets the correct details', () => {
const details = paymentService.getDisplayDetailsFromFormSubmissionPayment(
{
formSubmissionPayment,
formatCurrency,
formatDateTime,
},
formSubmissionPayment,
formatters,
)
expect(details).toMatchSnapshot()
})

it('using BPAY', () => {
const details = paymentService.getDisplayDetailsFromFormSubmissionPayment(
{
formSubmissionPayment: {
...formSubmissionPayment,
paymentTransaction: {
...formSubmissionPayment.paymentTransaction,
// @ts-expect-error Wrong
agencyCompletionPayment: {
...formSubmissionPayment.paymentTransaction
.agencyCompletionPayment,
paymentMethod: 'BPAY',
},
...formSubmissionPayment,
paymentTransaction: {
...formSubmissionPayment.paymentTransaction,
// @ts-expect-error Wrong
agencyCompletionPayment: {
...formSubmissionPayment.paymentTransaction
.agencyCompletionPayment,
paymentMethod: 'BPAY',
},
},
formatCurrency,
formatDateTime,
},
formatters,
)

expect(details.find((d) => d.key === 'billerCode')?.value).toBe(
Expand Down Expand Up @@ -105,11 +102,8 @@ describe('getDisplayDetailsFromFormSubmissionPayment', () => {
}
it('gets the correct details', () => {
const details = paymentService.getDisplayDetailsFromFormSubmissionPayment(
{
formSubmissionPayment,
formatCurrency,
formatDateTime,
},
formSubmissionPayment,
formatters,
)
expect(details).toMatchSnapshot()
})
Expand Down Expand Up @@ -158,22 +152,16 @@ describe('getDisplayDetailsFromFormSubmissionPayment', () => {

it('gets the correct details - v1', () => {
const details = paymentService.getDisplayDetailsFromFormSubmissionPayment(
{
formSubmissionPayment: formSubmissionPaymentv1,
formatCurrency,
formatDateTime,
},
formSubmissionPaymentv1,
formatters,
)
expect(details).toMatchSnapshot()
})

it('gets the correct details - v2', () => {
const details = paymentService.getDisplayDetailsFromFormSubmissionPayment(
{
formSubmissionPayment: formSubmissionPaymentv2,
formatCurrency,
formatDateTime,
},
formSubmissionPaymentv2,
formatters,
)
expect(details).toMatchSnapshot()
})
Expand Down Expand Up @@ -209,11 +197,8 @@ describe('getDisplayDetailsFromFormSubmissionPayment', () => {

it('gets the correct details', () => {
const details = paymentService.getDisplayDetailsFromFormSubmissionPayment(
{
formSubmissionPayment,
formatCurrency,
formatDateTime,
},
formSubmissionPayment,
formatters,
)
expect(details).toMatchSnapshot()
})
Expand Down