Skip to content

Commit c021435

Browse files
committed
fix payment tests
1 parent 0221aed commit c021435

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

apps/backend/src/lib/payments.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
162162
subscription: {
163163
findMany: async () => [{
164164
productId: 'off1',
165+
product: tenancy.config.payments.products['off1'],
165166
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
166167
currentPeriodEnd: new Date('2025-02-28T23:59:59.000Z'),
167168
quantity: 2,
@@ -200,6 +201,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
200201
subscription: {
201202
findMany: async () => [{
202203
productId: 'offW',
204+
product: tenancy.config.payments.products['offW'],
203205
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
204206
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
205207
quantity: 1,
@@ -239,6 +241,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
239241
subscription: {
240242
findMany: async () => [{
241243
productId: 'offW',
244+
product: tenancy.config.payments.products['offW'],
242245
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
243246
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
244247
quantity: 1,
@@ -278,6 +281,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
278281
subscription: {
279282
findMany: async () => [{
280283
productId: 'offR',
284+
product: tenancy.config.payments.products['offR'],
281285
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
282286
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
283287
quantity: 1,
@@ -317,6 +321,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
317321
subscription: {
318322
findMany: async () => [{
319323
productId: 'offN',
324+
product: tenancy.config.payments.products['offN'],
320325
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
321326
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
322327
quantity: 3,
@@ -352,6 +357,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
352357
subscription: {
353358
findMany: async () => [{
354359
productId: 'offRC',
360+
product: tenancy.config.payments.products['offRC'],
355361
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
356362
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
357363
quantity: 1,
@@ -400,6 +406,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
400406
const end = inFirstPeriod ? new Date('2025-03-01T00:00:00.000Z') : new Date('2025-04-01T00:00:00.000Z');
401407
return [{
402408
productId: 'offRR',
409+
product: tenancy.config.payments.products['offRR'],
403410
currentPeriodStart: start,
404411
currentPeriodEnd: end,
405412
quantity: 1,
@@ -444,6 +451,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
444451
subscription: {
445452
findMany: async () => [{
446453
productId: 'offMD',
454+
product: tenancy.config.payments.products['offMD'],
447455
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
448456
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
449457
quantity: 1,
@@ -492,6 +500,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
492500
subscription: {
493501
findMany: async () => [{
494502
productId: 'offBF',
503+
product: tenancy.config.payments.products['offBF'],
495504
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
496505
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
497506
quantity: 1,
@@ -547,13 +556,15 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
547556
findMany: async () => [
548557
{
549558
productId: 'off1',
559+
product: tenancy.config.payments.products['off1'],
550560
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
551561
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
552562
quantity: 3,
553563
status: 'active',
554564
},
555565
{
556566
productId: 'off2',
567+
product: tenancy.config.payments.products['off2'],
557568
currentPeriodStart: new Date('2025-01-15T00:00:00.000Z'),
558569
currentPeriodEnd: new Date('2025-03-15T00:00:00.000Z'),
559570
quantity: 5,
@@ -594,6 +605,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
594605
subscription: {
595606
findMany: async () => [{
596607
productId: 'offBundle',
608+
product: tenancy.config.payments.products['offBundle'],
597609
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
598610
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
599611
quantity: 2,
@@ -631,6 +643,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
631643
subscription: {
632644
findMany: async () => [{
633645
productId: 'offT',
646+
product: tenancy.config.payments.products['offT'],
634647
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
635648
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
636649
quantity: 3,
@@ -666,6 +679,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
666679
subscription: {
667680
findMany: async () => [{
668681
productId: 'offC',
682+
product: tenancy.config.payments.products['offC'],
669683
currentPeriodStart: new Date('2024-12-01T00:00:00.000Z'),
670684
currentPeriodEnd: new Date('2025-01-01T00:00:00.000Z'),
671685
quantity: 1,
@@ -706,6 +720,7 @@ describe('getItemQuantityForCustomer - subscriptions', () => {
706720
subscription: {
707721
findMany: async () => [{
708722
productId: 'offU',
723+
product: tenancy.config.payments.products['offU'],
709724
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
710725
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
711726
quantity: 2,
@@ -975,6 +990,7 @@ describe('validatePurchaseSession - one-time purchase rules', () => {
975990
subscription: {
976991
findMany: async () => [{
977992
productId: 'product-sub',
993+
product: tenancy.config.payments.products['product-sub'],
978994
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
979995
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
980996
quantity: 1,
@@ -1030,6 +1046,7 @@ describe('validatePurchaseSession - one-time purchase rules', () => {
10301046
subscription: {
10311047
findMany: async () => [{
10321048
productId: 'product-sub-stackable',
1049+
product: tenancy.config.payments.products['product-sub-stackable'],
10331050
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
10341051
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
10351052
quantity: 1,
@@ -1102,6 +1119,7 @@ describe('combined sources - one-time purchases + manual changes + subscriptions
11021119
subscription: {
11031120
findMany: async () => [{
11041121
productId: 'offSub',
1122+
product: tenancy.config.payments.products['offSub'],
11051123
currentPeriodStart: new Date('2025-02-01T00:00:00.000Z'),
11061124
currentPeriodEnd: new Date('2025-03-01T00:00:00.000Z'),
11071125
quantity: 2,

apps/backend/src/lib/payments.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,7 @@ export async function getSubscriptions(options: {
331331

332332
const productLinesWithDbSubscriptions = new Set<string>();
333333
for (const s of dbSubscriptions) {
334-
let product = s.product as yup.InferType<typeof productSchema> | undefined;
335-
if (!product) {
336-
product = s.productId ? getOrUndefined(products, s.productId) : undefined;
337-
}
338-
if (!product) continue;
334+
const product = s.product as yup.InferType<typeof productSchema>;
339335
subscriptions.push({
340336
id: s.id,
341337
productId: s.productId,

0 commit comments

Comments
 (0)