test: add unit tests for frontend top-down auto-reset and backend split logic
This commit is contained in:
42
shop/lib/checkout-split.test.ts
Normal file
42
shop/lib/checkout-split.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { splitCart, CartItem } from './checkout-split';
|
||||
|
||||
describe('Checkout Split Logic', () => {
|
||||
it('should place purchase items only into purchase group', () => {
|
||||
const cart: CartItem[] = [
|
||||
{ billingInterval: 'one_time', selections: {} },
|
||||
{ billingType: 'purchase', selections: {} }
|
||||
];
|
||||
|
||||
const { purchaseItems, subscriptionItems } = splitCart(cart);
|
||||
|
||||
expect(purchaseItems.length).toBe(2);
|
||||
expect(subscriptionItems.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should place subscription items only into subscription group', () => {
|
||||
const cart: CartItem[] = [
|
||||
{ billingInterval: 'monthly', selections: {} },
|
||||
{ billingType: 'subscription', selections: {} }
|
||||
];
|
||||
|
||||
const { purchaseItems, subscriptionItems } = splitCart(cart);
|
||||
|
||||
expect(purchaseItems.length).toBe(0);
|
||||
expect(subscriptionItems.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should split mixed cart into separate purchase and subscription groups', () => {
|
||||
const cart: CartItem[] = [
|
||||
{ billingInterval: 'one_time', selections: {} },
|
||||
{ billingInterval: 'monthly', selections: {} },
|
||||
{ billingType: 'purchase', selections: {} },
|
||||
{ billingType: 'subscription', selections: {} }
|
||||
];
|
||||
|
||||
const { purchaseItems, subscriptionItems } = splitCart(cart);
|
||||
|
||||
expect(purchaseItems.length).toBe(2);
|
||||
expect(subscriptionItems.length).toBe(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user