Refactor infra tests, clean E2E step suites, and fix TS in tests
This commit is contained in:
@@ -10,30 +10,37 @@ import { CheckoutPrice } from '../../../../packages/domain/value-objects/Checkou
|
||||
describe('CheckoutPrice Value Object', () => {
|
||||
describe('Construction', () => {
|
||||
it('should create with valid price $0.50', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
expect(() => new CheckoutPrice(0.50)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should create with valid price $10.00', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
expect(() => new CheckoutPrice(10.00)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should create with valid price $100.00', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
expect(() => new CheckoutPrice(100.00)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should reject negative prices', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
expect(() => new CheckoutPrice(-0.50)).toThrow(/negative/i);
|
||||
});
|
||||
|
||||
it('should reject excessive prices over $10,000', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
expect(() => new CheckoutPrice(10000.01)).toThrow(/excessive|maximum/i);
|
||||
});
|
||||
|
||||
it('should accept exactly $10,000', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
expect(() => new CheckoutPrice(10000.00)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should accept $0.00 (zero price)', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
expect(() => new CheckoutPrice(0.00)).not.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -83,26 +90,31 @@ describe('CheckoutPrice Value Object', () => {
|
||||
|
||||
describe('Display formatting', () => {
|
||||
it('should format $0.50 as "$0.50"', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(0.50);
|
||||
expect(price.toDisplayString()).toBe('$0.50');
|
||||
});
|
||||
|
||||
it('should format $10.00 as "$10.00"', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(10.00);
|
||||
expect(price.toDisplayString()).toBe('$10.00');
|
||||
});
|
||||
|
||||
it('should format $100.00 as "$100.00"', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(100.00);
|
||||
expect(price.toDisplayString()).toBe('$100.00');
|
||||
});
|
||||
|
||||
it('should always show two decimal places', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(5);
|
||||
expect(price.toDisplayString()).toBe('$5.00');
|
||||
});
|
||||
|
||||
it('should round to two decimal places', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(5.129);
|
||||
expect(price.toDisplayString()).toBe('$5.13');
|
||||
});
|
||||
@@ -110,16 +122,19 @@ describe('CheckoutPrice Value Object', () => {
|
||||
|
||||
describe('Zero check', () => {
|
||||
it('should detect $0.00 correctly', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(0.00);
|
||||
expect(price.isZero()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for non-zero prices', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(0.50);
|
||||
expect(price.isZero()).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle floating point precision for zero', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(0.0000001);
|
||||
expect(price.isZero()).toBe(true);
|
||||
});
|
||||
@@ -127,16 +142,19 @@ describe('CheckoutPrice Value Object', () => {
|
||||
|
||||
describe('Edge Cases', () => {
|
||||
it('should handle very small prices $0.01', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(0.01);
|
||||
expect(price.toDisplayString()).toBe('$0.01');
|
||||
});
|
||||
|
||||
it('should handle large prices $9,999.99', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(9999.99);
|
||||
expect(price.toDisplayString()).toBe('$9999.99');
|
||||
});
|
||||
|
||||
it('should be immutable after creation', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(5.00);
|
||||
const amount = price.getAmount();
|
||||
expect(amount).toBe(5.00);
|
||||
@@ -152,11 +170,13 @@ describe('CheckoutPrice Value Object', () => {
|
||||
});
|
||||
|
||||
it('Given amount 10.00, When formatting, Then display is "$10.00"', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
const price = new CheckoutPrice(10.00);
|
||||
expect(price.toDisplayString()).toBe('$10.00');
|
||||
});
|
||||
|
||||
it('Given negative amount, When constructing, Then error is thrown', () => {
|
||||
// @ts-expect-error Testing private constructor invariants
|
||||
expect(() => new CheckoutPrice(-5.00)).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user