-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1241 from guardian/ahe/cancellation-save-refactor
Refactor: move membership saves into own directory
- Loading branch information
Showing
13 changed files
with
227 additions
and
159 deletions.
There are no files selected for viewing
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
78 changes: 78 additions & 0 deletions
78
client/components/mma/cancel/cancellationSaves/CancellationLanding.stories.tsx
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,78 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { rest } from 'msw'; | ||
import { ReactRouterDecorator } from '@/.storybook/ReactRouterDecorator'; | ||
import { toMembersDataApiResponse } from '@/client/fixtures/mdapiResponse'; | ||
import { | ||
digitalPackPaidByDirectDebit, | ||
membershipSupporterCurrencyUSD, | ||
} from '@/client/fixtures/productBuilder/testProducts'; | ||
import { PRODUCT_TYPES } from '@/shared/productTypes'; | ||
import { CancellationContainer } from '../CancellationContainer'; | ||
import { CancellationLanding } from './CancellationLanding'; | ||
|
||
export default { | ||
title: 'Pages/CancellationLanding', | ||
component: CancellationContainer, | ||
decorators: [ReactRouterDecorator], | ||
parameters: { | ||
layout: 'fullscreen', | ||
}, | ||
} as Meta<typeof CancellationContainer>; | ||
|
||
export const Membership: StoryObj<typeof CancellationLanding> = { | ||
render: () => { | ||
return <CancellationLanding />; | ||
}, | ||
|
||
parameters: { | ||
reactRouter: { | ||
state: { | ||
productDetail: membershipSupporterCurrencyUSD(), | ||
user: { email: '[email protected]' }, | ||
}, | ||
container: ( | ||
<CancellationContainer productType={PRODUCT_TYPES.membership} /> | ||
), | ||
}, | ||
msw: [ | ||
rest.get('/api/me/mma', (_req, res, ctx) => { | ||
return res( | ||
ctx.json( | ||
toMembersDataApiResponse( | ||
membershipSupporterCurrencyUSD(), | ||
), | ||
), | ||
); | ||
}), | ||
], | ||
}, | ||
}; | ||
|
||
export const DigiPack: StoryObj<typeof CancellationLanding> = { | ||
render: () => { | ||
return <CancellationLanding />; | ||
}, | ||
|
||
parameters: { | ||
reactRouter: { | ||
state: { | ||
productDetail: digitalPackPaidByDirectDebit(), | ||
user: { email: '[email protected]' }, | ||
}, | ||
container: ( | ||
<CancellationContainer productType={PRODUCT_TYPES.digipack} /> | ||
), | ||
}, | ||
msw: [ | ||
rest.get('/api/me/mma', (_req, res, ctx) => { | ||
return res( | ||
ctx.json( | ||
toMembersDataApiResponse( | ||
digitalPackPaidByDirectDebit(), | ||
), | ||
), | ||
); | ||
}), | ||
], | ||
}, | ||
}; |
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
44 changes: 44 additions & 0 deletions
44
client/components/mma/cancel/cancellationSaves/eligibilityCheck.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,44 @@ | ||
import { getNewMembershipPrice } from '@/client/utilities/membershipPriceRise'; | ||
import type { | ||
PaidSubscriptionPlan, | ||
ProductDetail, | ||
} from '@/shared/productResponse'; | ||
import { getMainPlan } from '@/shared/productResponse'; | ||
|
||
export function ineligibleForSave( | ||
products: ProductDetail[], | ||
productToCancel: ProductDetail, | ||
) { | ||
if (productToCancel.mmaCategory === 'membership') { | ||
return isMembershipIneligible(products, productToCancel); | ||
} | ||
} | ||
|
||
function isMembershipIneligible( | ||
products: ProductDetail[], | ||
productToCancel: ProductDetail, | ||
) { | ||
const inPaymentFailure = products.find((product) => product.alertText); | ||
|
||
const hasOtherProduct = products.find( | ||
(product) => | ||
product.mmaCategory != 'membership' && | ||
!product.subscription.cancelledAt, | ||
); | ||
|
||
const membershipTierIsNotSupporter = productToCancel.tier !== 'Supporter'; | ||
|
||
const mainPlan = getMainPlan( | ||
productToCancel.subscription, | ||
) as PaidSubscriptionPlan; | ||
|
||
const hasBeenPriceRisen = | ||
getNewMembershipPrice(mainPlan) === mainPlan.price / 100; | ||
|
||
return ( | ||
inPaymentFailure || | ||
hasOtherProduct || | ||
membershipTierIsNotSupporter || | ||
hasBeenPriceRisen | ||
); | ||
} |
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
Oops, something went wrong.