AI Prompt: Forma3D.Connect — Phase 5w: Test Fixtures Centralization¶
Purpose: This prompt instructs an AI to centralize duplicated test fixtures
Estimated Effort: 3-4 hours
Prerequisites: Phase 5v completed (OpenAPI Examples)
Output: Centralized test fixtures with factory functions
Status: 🟡 PENDING
🎯 Mission¶
You are implementing Phase 5w: Test Fixtures Centralization — addressing TD-021 (Test Data Fixtures Duplication) from the technical debt register.
Why This Matters:
Duplicated test fixtures cause:
- Maintenance Burden: Same data defined in many places
- Inconsistency: Fixtures drift apart over time
- Verbose Tests: Each test file recreates mock data
- Schema Changes: Updates required in many files
📋 Context: Technical Debt Item¶
TD-021: Test Data Fixtures Duplication¶
| Attribute | Value |
|---|---|
| Type | Test Debt |
| Priority | Low |
| Interest Rate | Low |
| Principal (Effort) | 3-4 hours |
🛠️ Implementation¶
Phase 1: Create Test Fixtures Library (1.5 hours)¶
Create libs/testing/src/fixtures/:
// order.fixtures.ts
import { Order, OrderStatus } from '@forma3d/domain';
export const createMockOrder = (overrides: Partial<Order> = {}): Order => ({
id: 'order-123',
shopifyOrderId: '5123456789',
shopifyOrderNumber: 1001,
status: OrderStatus.PENDING,
customerName: 'John Doe',
customerEmail: 'john@example.com',
totalPrice: 99.99,
currency: 'EUR',
shippingAddress: {
address1: '123 Main St',
city: 'Amsterdam',
country: 'NL',
zip: '1011AB',
},
lineItems: [],
metadata: null,
createdAt: new Date('2026-01-15T10:00:00Z'),
updatedAt: new Date('2026-01-15T10:00:00Z'),
...overrides,
});
export const createMockOrders = (count: number): Order[] =>
Array.from({ length: count }, (_, i) =>
createMockOrder({ id: `order-${i + 1}` })
);
// line-item.fixtures.ts
export const createMockLineItem = (overrides = {}) => ({
id: 'line-item-123',
orderId: 'order-123',
productId: 'product-456',
variantId: 'variant-789',
quantity: 1,
...overrides,
});
// print-job.fixtures.ts
export const createMockPrintJob = (overrides = {}) => ({
id: 'print-job-123',
lineItemId: 'line-item-123',
status: 'PENDING',
...overrides,
});
Phase 2: Create Factory Builders (1 hour)¶
// builders/order.builder.ts
export class OrderBuilder {
private order = createMockOrder();
withStatus(status: OrderStatus): this {
this.order.status = status;
return this;
}
withLineItems(items: LineItem[]): this {
this.order.lineItems = items;
return this;
}
build(): Order {
return { ...this.order };
}
}
// Usage:
const order = new OrderBuilder()
.withStatus(OrderStatus.PROCESSING)
.withLineItems([createMockLineItem()])
.build();
Phase 3: Update Existing Tests (1.5 hours)¶
Replace inline fixtures with imports:
// Before
const mockOrder = {
id: 'order-123',
// ... 20 more lines
};
// After
import { createMockOrder } from '@forma3d/testing';
const mockOrder = createMockOrder({ status: OrderStatus.SHIPPED });
📁 Files to Create¶
libs/testing/src/fixtures/order.fixtures.ts
libs/testing/src/fixtures/line-item.fixtures.ts
libs/testing/src/fixtures/print-job.fixtures.ts
libs/testing/src/fixtures/shipment.fixtures.ts
libs/testing/src/fixtures/index.ts
libs/testing/src/builders/order.builder.ts
libs/testing/src/index.ts
✅ Validation Checklist¶
- Fixtures library created
- Factory functions for all entities
- Builder pattern for complex objects
- Existing tests updated to use fixtures
-
pnpm nx testpasses - No duplicate fixture definitions
END OF PROMPT
This prompt resolves TD-021 from the technical debt register.