fix: code review fixes + unit/API tests for repair-POS integration
Code review fixes: - Wrap createFromRepairTicket() in DB transaction for atomicity - Wrap complete() inventory + status updates in DB transaction - Repair ticket status update now atomic with transaction completion - Add Zod validation on from-repair route body - Fix requiresDiscountOverride: threshold and manual_discount are independent checks - Order discount distributes proportionally across line items (not first-only) - Extract shared receipt calculations into useReceiptData/useBarcode hooks - Add error handling for barcode generation Tests: - Unit: consumable tax category mapping, exempt rate short-circuit - API: ready-for-pickup listing + search, from-repair transaction creation, consumable exclusion from line items, tax rate verification (labor=service, part=goods), duplicate prevention, ticket auto-pickup on payment completion, isConsumable product filter Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
packages/backend/__tests__/services/tax-consumable.test.ts
Normal file
37
packages/backend/__tests__/services/tax-consumable.test.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { describe, it, expect } from 'bun:test'
|
||||
import { TaxService } from '../../src/services/tax.service.js'
|
||||
|
||||
describe('TaxService.repairItemTypeToTaxCategory — consumable', () => {
|
||||
it('maps consumable to exempt', () => {
|
||||
expect(TaxService.repairItemTypeToTaxCategory('consumable')).toBe('exempt')
|
||||
})
|
||||
|
||||
it('maps labor to service', () => {
|
||||
expect(TaxService.repairItemTypeToTaxCategory('labor')).toBe('service')
|
||||
})
|
||||
|
||||
it('maps part to goods', () => {
|
||||
expect(TaxService.repairItemTypeToTaxCategory('part')).toBe('goods')
|
||||
})
|
||||
|
||||
it('maps flat_rate to goods', () => {
|
||||
expect(TaxService.repairItemTypeToTaxCategory('flat_rate')).toBe('goods')
|
||||
})
|
||||
|
||||
it('maps misc to goods', () => {
|
||||
expect(TaxService.repairItemTypeToTaxCategory('misc')).toBe('goods')
|
||||
})
|
||||
|
||||
it('maps unknown type to goods (default)', () => {
|
||||
expect(TaxService.repairItemTypeToTaxCategory('anything_else')).toBe('goods')
|
||||
})
|
||||
})
|
||||
|
||||
describe('TaxService.getRateForLocation — exempt category', () => {
|
||||
it('returns 0 for exempt tax category without DB call', async () => {
|
||||
// Passing a fake DB and fake locationId — should short-circuit and return 0
|
||||
const fakeDb = {} as any
|
||||
const rate = await TaxService.getRateForLocation(fakeDb, 'fake-id', 'exempt')
|
||||
expect(rate).toBe(0)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user