forked from houdiniproject/houdini
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move post-success into DonationSubmitter
- Loading branch information
Showing
7 changed files
with
164 additions
and
35 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
client/js/nonprofits/donate/DonationSubmitter/__mocks__/plausibleWrapper.ts
This file contains 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,3 @@ | ||
|
||
// License: LGPL-3.0-or-later | ||
export const paymentSucceededPlausible = jest.fn(); |
This file contains 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 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
61 changes: 61 additions & 0 deletions
61
client/js/nonprofits/donate/DonationSubmitter/plausibleWrapper.spec.ts
This file contains 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 @@ | ||
// License: LGPL-3.0-or-later | ||
import {paymentSucceededPlausible} from './plausibleWrapper'; | ||
|
||
|
||
describe('plausibleWrapper', () => { | ||
describe('paymentSucceededPlausible', () => { | ||
it('completes if getPlausible is undefined', () => { | ||
expect(() => paymentSucceededPlausible({})).not.toThrow(); | ||
}) | ||
|
||
it('completes if getPlausible is returns undefined', () => { | ||
expect(() => paymentSucceededPlausible({getPlausible: () => undefined})).not.toThrow(); | ||
}) | ||
|
||
describe('completes if getPlausible is defined but result is', () => { | ||
it('undefined', () => { | ||
const realPlausibleFunc = jest.fn(); | ||
expect(() => paymentSucceededPlausible({getPlausible: () => realPlausibleFunc})).not.toThrow(); | ||
|
||
expect(realPlausibleFunc).toHaveBeenCalledWith('payment_succeeded', { | ||
props: { | ||
amount: undefined, | ||
}}); | ||
|
||
}) | ||
|
||
it('exists but doesnt have a charge', () => { | ||
const realPlausibleFunc = jest.fn(); | ||
expect(() => paymentSucceededPlausible({getPlausible: () => realPlausibleFunc, result:{}})).not.toThrow(); | ||
|
||
expect(realPlausibleFunc).toHaveBeenCalledWith('payment_succeeded', { | ||
props: { | ||
amount: undefined, | ||
}}); | ||
|
||
}); | ||
|
||
it('exists but doesnt have an amount', () => { | ||
const realPlausibleFunc = jest.fn(); | ||
expect(() => paymentSucceededPlausible({getPlausible: () => realPlausibleFunc, result:{charge:{}}})).not.toThrow(); | ||
|
||
expect(realPlausibleFunc).toHaveBeenCalledWith('payment_succeeded', { | ||
props: { | ||
amount: undefined, | ||
}}); | ||
|
||
}); | ||
|
||
it('exists and has an amount', () => { | ||
const realPlausibleFunc = jest.fn(); | ||
expect(() => paymentSucceededPlausible({getPlausible: () => realPlausibleFunc, result:{charge:{amount: 1000}}})).not.toThrow(); | ||
|
||
expect(realPlausibleFunc).toHaveBeenCalledWith('payment_succeeded', { | ||
props: { | ||
amount: 10, | ||
}}); | ||
|
||
}) | ||
}) | ||
}) | ||
}); |
25 changes: 25 additions & 0 deletions
25
client/js/nonprofits/donate/DonationSubmitter/plausibleWrapper.ts
This file contains 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,25 @@ | ||
// License: LGPL-3.0-or-later | ||
export interface PlausibleFunction { | ||
(eventType: string, val: any): void | ||
} | ||
|
||
export interface GetPlausible { | ||
|
||
(): PlausibleFunction | undefined | ||
} | ||
|
||
/** | ||
* Notifies plausible that the payment has been created | ||
*/ | ||
export function paymentSucceededPlausible({ getPlausible, result }: { getPlausible?: GetPlausible, result?: { charge?: { amount?: number } } }) { | ||
|
||
const plausibleFunction = getPlausible && getPlausible(); | ||
|
||
if (plausibleFunction) { | ||
plausibleFunction('payment_succeeded', { | ||
props: { | ||
amount: result?.charge?.amount && (result.charge.amount / 100) | ||
} | ||
}); | ||
} | ||
} |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.