(params: {
subscriptionId: string;
kiloUserId: string;
welcomePromoEligibilityReason?: KiloPassWelcomePromoEligibilityReason;
issueMonth?: string;
stripeInvoiceId?: string;
createdAt?: string;
})
| 412 | }, |
| 413 | async update(assessmentKey, patch) { |
| 414 | const existing = rows.get(assessmentKey); |
| 415 | if (!existing) throw new Error(`missing ${assessmentKey}`); |
| 416 | const next = { |
| 417 | ...existing, |
| 418 | ...patch, |
| 419 | metadata: { ...existing.metadata, ...(patch.metadata ?? {}) }, |
| 420 | }; |
| 421 | rows.set(assessmentKey, next); |
| 422 | return { ...next }; |
| 423 | }, |
| 424 | }; |
| 425 | return store; |
| 426 | } |
| 427 | |
| 428 | type PersonalKiloPassCheckoutTestDeps = ServiceFeeCheckoutDependencies & { |
| 429 | createSession?: (params: Stripe.Checkout.SessionCreateParams) => Promise<CheckoutSessionLike>; |
| 430 | }; |
| 431 | |
| 432 | function kiloPassCheckoutDeps( |
| 433 | store: ServiceFeeAssessmentStore, |
| 434 | overrides: Partial<PersonalKiloPassCheckoutTestDeps> = {} |
| 435 | ): PersonalKiloPassCheckoutTestDeps { |
| 436 | return { |
| 437 | store, |
| 438 | now: new Date(SERVICE_FEE_ACTIVATION_UNIX_SECONDS * 1000), |
| 439 | sendAlert: jest.fn(async () => undefined), |
| 440 | stripe: { |
| 441 | prices: { |
| 442 | retrieve: async () => ({ |
| 443 | id: 'price_test_kilo_pass', |
| 444 | currency: 'usd', |
| 445 | unit_amount: 4900, |
| 446 | tax_behavior: 'unspecified', |
| 447 | }), |
| 448 | }, |
| 449 | }, |
| 450 | ...overrides, |
| 451 | }; |
| 452 | } |
| 453 | |
| 454 | jest.mock('@/lib/kilo-pass/dayjs', () => { |
| 455 | const realDayjs = jest.requireActual<typeof dayjsType>('dayjs'); |
| 456 | const utc = jest.requireActual<typeof utcType>('dayjs/plugin/utc'); |
| 457 | |
| 458 | realDayjs.extend(utc); |
| 459 | |
| 460 | const controlledDayjs = ((...args: Parameters<typeof realDayjs>) => { |
| 461 | if (args.length === 0 && mockKiloPassNowIso) { |
| 462 | return realDayjs(mockKiloPassNowIso); |
| 463 | } |
| 464 | return realDayjs(...args); |
| 465 | }) as typeof realDayjs; |
| 466 | |
| 467 | Object.assign(controlledDayjs, realDayjs); |
| 468 | |
| 469 | return { dayjs: controlledDayjs }; |
| 470 | }); |
| 471 |
no test coverage detected