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
|
|
@ -166,6 +166,41 @@ describe('helcim subscription endpoint', () => {
|
|||
expect(Member.findById).toHaveBeenCalledWith('member-2')
|
||||
})
|
||||
|
||||
it('reads dateBilling from Helcim CREATE response and threads it to $set + response', async () => {
|
||||
requireAuth.mockResolvedValue(undefined)
|
||||
requiresPayment.mockReturnValue(true)
|
||||
getHelcimPlanId.mockReturnValue('99999')
|
||||
|
||||
const mockMember = {
|
||||
_id: 'member-db',
|
||||
email: 'datebilling@example.com',
|
||||
name: 'DateBilling User',
|
||||
circle: 'founder',
|
||||
contributionAmount: 15,
|
||||
status: 'active',
|
||||
}
|
||||
Member.findOneAndUpdate.mockResolvedValue({ _id: 'member-db', status: 'pending_payment' })
|
||||
Member.findById.mockResolvedValue(mockMember)
|
||||
createHelcimSubscription.mockResolvedValue({
|
||||
data: [{ id: 'sub-x', status: 'active', dateBilling: '2026-06-01' }]
|
||||
})
|
||||
|
||||
const event = createMockEvent({
|
||||
method: 'POST',
|
||||
path: '/api/helcim/subscription',
|
||||
body: { customerId: 'cust-1', contributionAmount: 15, customerCode: 'code-1', cardToken: 'tok-123', cadence: 'monthly' }
|
||||
})
|
||||
|
||||
const result = await subscriptionHandler(event)
|
||||
|
||||
expect(Member.findOneAndUpdate).toHaveBeenCalledWith(
|
||||
{ helcimCustomerId: 'cust-1' },
|
||||
{ $set: expect.objectContaining({ nextBillingDate: new Date('2026-06-01') }) },
|
||||
{ new: false, runValidators: false, projection: { status: 1 } }
|
||||
)
|
||||
expect(result.subscription.nextBillingDate).toBe('2026-06-01')
|
||||
})
|
||||
|
||||
it('annual $15 tier creates subscription with correct paymentPlanId and recurringAmount', async () => {
|
||||
requireAuth.mockResolvedValue(undefined)
|
||||
requiresPayment.mockReturnValue(true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue