b34b0dd7d6
Validators (Pushes and Pull Requests) / UI & Storage Validation (pull_request) Failing after 12s
Validators (Pushes and Pull Requests) / Database & Schema Validation (pull_request) Successful in 13s
Validators (Pushes and Pull Requests) / Core Validators & Database Setup (pull_request) Failing after 28s
Validators (Pushes and Pull Requests) / WBS & Audit Validations (pull_request) Has been skipped
Validators (Pushes and Pull Requests) / .NET Contracts (pull_request) Has been skipped
Validators (Pushes and Pull Requests) / Calibration & Performance (pull_request) Has been skipped
Validators (Pushes and Pull Requests) / Operational Report & Decision Packet (pull_request) Has been skipped
Validators (Pushes and Pull Requests) / CI Workflow Lint (pull_request) Failing after 10s
Validators (Pushes and Pull Requests) / Security & Secrets (pull_request) Successful in 12s
Validators (Pushes and Pull Requests) / Notify PR Results (pull_request) Successful in 2s
Frontend CI Pipeline / ci-frontend-8-steps (pull_request) Failing after 2m50s
222 lines
6.0 KiB
TypeScript
222 lines
6.0 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest'
|
|
import { setActivePinia, createPinia } from 'pinia'
|
|
import { useOrderStore, useCustomerStore, useInventoryStore } from '@/stores'
|
|
import type { Order } from '@/stores'
|
|
|
|
describe('Order Workflow Integration Tests', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia())
|
|
})
|
|
|
|
describe('Complete Order Lifecycle', () => {
|
|
it('should create order → update → delete workflow', async () => {
|
|
const orderStore = useOrderStore()
|
|
const customerStore = useCustomerStore()
|
|
|
|
// Step 1: Fetch customers
|
|
await customerStore.fetchCustomers()
|
|
expect(customerStore.activeCustomers.length).toBeGreaterThanOrEqual(0)
|
|
|
|
// Step 2: Create order
|
|
const newOrder = await orderStore.createOrder({
|
|
customerId: 'cust-001',
|
|
customerName: 'Test Customer',
|
|
orderDate: '2026-08-01',
|
|
dueDate: '2026-08-15',
|
|
items: [
|
|
{
|
|
id: 'item-001',
|
|
lineNumber: 1,
|
|
productId: 'prod-001',
|
|
productSku: 'SKU-12345',
|
|
quantity: 100,
|
|
unitPrice: 50,
|
|
lineTotal: 5000
|
|
}
|
|
],
|
|
subtotal: 5000,
|
|
tax: 500,
|
|
total: 5500
|
|
})
|
|
|
|
expect(newOrder).toBeDefined()
|
|
expect(newOrder.status).toBe('DRAFT')
|
|
expect(orderStore.orderCount).toBeGreaterThan(0)
|
|
|
|
// Step 3: Update order
|
|
const updated = await orderStore.updateOrder(newOrder.id, {
|
|
status: 'CONFIRMED',
|
|
notes: 'Updated via workflow test'
|
|
})
|
|
|
|
expect(updated.status).toBe('CONFIRMED')
|
|
expect(updated.notes).toBe('Updated via workflow test')
|
|
|
|
// Step 4: Delete order
|
|
await orderStore.deleteOrder(newOrder.id)
|
|
expect(orderStore.orders.find((o) => o.id === newOrder.id)).toBeUndefined()
|
|
})
|
|
|
|
it('should filter orders by status', async () => {
|
|
const orderStore = useOrderStore()
|
|
|
|
await orderStore.fetchOrders()
|
|
|
|
// Set filter
|
|
orderStore.setFilter({ status: 'CONFIRMED' })
|
|
expect(orderStore.filter.status).toBe('CONFIRMED')
|
|
|
|
// Filter computed
|
|
const filtered = orderStore.filteredOrders
|
|
expect(filtered.every((o) => o.status === 'CONFIRMED')).toBe(true)
|
|
|
|
// Clear filter
|
|
orderStore.clearFilter()
|
|
expect(orderStore.filter.status).toBe('ALL')
|
|
})
|
|
|
|
it('should calculate order totals correctly', async () => {
|
|
const orderStore = useOrderStore()
|
|
|
|
const order = await orderStore.createOrder({
|
|
customerId: 'cust-001',
|
|
customerName: 'Test',
|
|
orderDate: '2026-08-01',
|
|
dueDate: '2026-08-15',
|
|
items: [
|
|
{
|
|
id: '1',
|
|
lineNumber: 1,
|
|
productId: 'p1',
|
|
productSku: 'SKU-001',
|
|
quantity: 100,
|
|
unitPrice: 50,
|
|
lineTotal: 5000
|
|
},
|
|
{
|
|
id: '2',
|
|
lineNumber: 2,
|
|
productId: 'p2',
|
|
productSku: 'SKU-002',
|
|
quantity: 50,
|
|
unitPrice: 30,
|
|
lineTotal: 1500
|
|
}
|
|
],
|
|
subtotal: 6500,
|
|
tax: 650,
|
|
total: 7150
|
|
})
|
|
|
|
expect(order.subtotal).toBe(6500)
|
|
expect(order.tax).toBe(650)
|
|
expect(order.total).toBe(7150)
|
|
})
|
|
|
|
it('should track recent orders', async () => {
|
|
const orderStore = useOrderStore()
|
|
|
|
// Create multiple orders
|
|
for (let i = 0; i < 3; i++) {
|
|
await orderStore.createOrder({
|
|
customerId: `cust-${i}`,
|
|
customerName: `Customer ${i}`,
|
|
orderDate: '2026-08-01',
|
|
dueDate: '2026-08-15',
|
|
items: [],
|
|
subtotal: 1000,
|
|
tax: 100,
|
|
total: 1100
|
|
})
|
|
}
|
|
|
|
const recent = orderStore.recentOrders
|
|
expect(recent.length).toBeLessThanOrEqual(5)
|
|
})
|
|
})
|
|
|
|
describe('Order Status Transitions', () => {
|
|
it('should transition through valid statuses', async () => {
|
|
const orderStore = useOrderStore()
|
|
|
|
const order = await orderStore.createOrder({
|
|
customerId: 'cust-001',
|
|
customerName: 'Test',
|
|
orderDate: '2026-08-01',
|
|
dueDate: '2026-08-15',
|
|
items: [],
|
|
subtotal: 0,
|
|
tax: 0,
|
|
total: 0
|
|
})
|
|
|
|
const statuses = ['DRAFT', 'PENDING', 'CONFIRMED', 'SHIPPED', 'DELIVERED']
|
|
let current = order
|
|
|
|
for (const status of statuses) {
|
|
current = await orderStore.updateOrder(current.id, { status: status as any })
|
|
expect(current.status).toBe(status)
|
|
}
|
|
})
|
|
|
|
it('should count orders by status', async () => {
|
|
const orderStore = useOrderStore()
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
await orderStore.createOrder({
|
|
customerId: 'cust-001',
|
|
customerName: 'Test',
|
|
orderDate: '2026-08-01',
|
|
dueDate: '2026-08-15',
|
|
items: [],
|
|
subtotal: 0,
|
|
tax: 0,
|
|
total: 0,
|
|
status: i === 0 ? 'CONFIRMED' : 'PENDING'
|
|
} as any)
|
|
}
|
|
|
|
const byStatus = orderStore.ordersByStatus
|
|
expect(byStatus['CONFIRMED']).toBeGreaterThan(0)
|
|
expect(byStatus['PENDING']).toBeGreaterThan(0)
|
|
})
|
|
})
|
|
|
|
describe('Order Validation', () => {
|
|
it('should require customer for order', async () => {
|
|
const orderStore = useOrderStore()
|
|
|
|
const order = await orderStore.createOrder({
|
|
customerId: '',
|
|
customerName: '',
|
|
orderDate: '2026-08-01',
|
|
dueDate: '2026-08-15',
|
|
items: [],
|
|
subtotal: 0,
|
|
tax: 0,
|
|
total: 0
|
|
})
|
|
|
|
expect(order.customerId).toBe('')
|
|
// Validation would be enforced at form level
|
|
})
|
|
|
|
it('should handle empty order items', async () => {
|
|
const orderStore = useOrderStore()
|
|
|
|
const order = await orderStore.createOrder({
|
|
customerId: 'cust-001',
|
|
customerName: 'Test',
|
|
orderDate: '2026-08-01',
|
|
dueDate: '2026-08-15',
|
|
items: [],
|
|
subtotal: 0,
|
|
tax: 0,
|
|
total: 0
|
|
})
|
|
|
|
expect(order.items.length).toBe(0)
|
|
})
|
|
})
|
|
})
|