Session 7i: Stripe test coverage gaps filled, dual-provider cutover documented (1042 tests)
This commit is contained in:
@@ -127,6 +127,31 @@ describe('stripeService', () => {
|
||||
expect(profilesUpdate.patch.subscription_status).toBe('grace_period');
|
||||
});
|
||||
|
||||
test('customer.subscription.updated active → flips tier to the new plan + clears grace', async () => {
|
||||
// Plan-change flow (portal-driven upgrade/downgrade). Stripe sends
|
||||
// the new price on items.data[0].price.id; the service must map it
|
||||
// back to a tier via PRICE_MAP and reflect that on the user.
|
||||
const fake = makeFake();
|
||||
mockSupabaseClient.current = fake;
|
||||
const newPriceId = process.env.STRIPE_PRICE_DESK || 'price_desk_monthly';
|
||||
await handleWebhookEvent({
|
||||
type: 'customer.subscription.updated',
|
||||
data: {
|
||||
object: {
|
||||
customer: 'cus_active',
|
||||
status: 'active',
|
||||
items: { data: [{ price: { id: newPriceId } }] },
|
||||
},
|
||||
},
|
||||
});
|
||||
const usersUpdate = fake.updates.find((u) => u.table === 'users');
|
||||
const profilesUpdate = fake.updates.find((u) => u.table === 'user_profiles');
|
||||
expect(usersUpdate.patch.tier).toBe('desk');
|
||||
expect(usersUpdate.patch.grace_period_until).toBeNull();
|
||||
expect(profilesUpdate.patch.tier).toBe('desk');
|
||||
expect(profilesUpdate.patch.subscription_status).toBe('active');
|
||||
});
|
||||
|
||||
test('customer.subscription.deleted sets grace, does not flip tier immediately', async () => {
|
||||
const fake = makeFake();
|
||||
mockSupabaseClient.current = fake;
|
||||
|
||||
Reference in New Issue
Block a user