fix(helcim): read dateBilling on subscription CREATE to populate next-billing cache
Helcim returns next-charge as `dateBilling` on POST /subscriptions, but the two CREATE sites were reading `subscription.nextBillingDate`, leaving `member.nextBillingDate` empty after every signup and free→paid upgrade. The lazy refresh in subscription.get.js (which already accepts both shapes) masked it on next account-page load, so renders eventually populated — but the success response we returned to the client also had `nextBillingDate: undefined`. Mirror the GET-side resolution at both CREATE sites: prefer `dateBilling`, fall back to `nextBillingDate`. Existing Number.isNaN guard unchanged; defensively rejects malformed strings from either field.
This commit is contained in:
parent
3c38333dd1
commit
cf59931814
5 changed files with 65 additions and 9 deletions
|
|
@ -261,6 +261,30 @@ describe('update-contribution endpoint — Case 1 (free→paid)', () => {
|
|||
expect(result.message).toBe('Successfully upgraded to paid tier')
|
||||
})
|
||||
|
||||
it('reads dateBilling from Helcim CREATE response and threads it to $set + response', async () => {
|
||||
setMember(freeMember)
|
||||
getHelcimPlanId.mockReturnValue('111')
|
||||
getHelcimCustomer.mockResolvedValue({ customerCode: 'code-1' })
|
||||
listHelcimCustomerCards.mockResolvedValue([{ id: 'card-1' }])
|
||||
createHelcimSubscription.mockResolvedValue({ data: [{ id: 'sub-new', status: 'active', dateBilling: '2026-05-18' }] })
|
||||
Member.findByIdAndUpdate.mockResolvedValue({})
|
||||
|
||||
const event = createMockEvent({
|
||||
method: 'POST',
|
||||
path: '/api/members/update-contribution',
|
||||
body: { contributionAmount: 15, cadence: 'monthly' },
|
||||
})
|
||||
|
||||
const result = await handler(event)
|
||||
|
||||
expect(Member.findByIdAndUpdate).toHaveBeenCalledWith(
|
||||
'member-c1',
|
||||
{ $set: expect.objectContaining({ nextBillingDate: new Date('2026-05-18') }) },
|
||||
{ runValidators: false }
|
||||
)
|
||||
expect(result.subscription.nextBillingDate).toBe('2026-05-18')
|
||||
})
|
||||
|
||||
it('annual: calls createHelcimSubscription with annual plan id and recurringAmount 180, persists billingCadence annual', async () => {
|
||||
setMember(freeMember)
|
||||
getHelcimPlanId.mockReturnValue('222')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue