Files
webshop/shop/lib/checkout-split.test.ts

43 lines
1.4 KiB
TypeScript

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);
});
});