refactor: split validation handler responsibilities

This commit is contained in:
Misaka
2026-03-21 08:54:35 +08:00
parent 68e6c9483f
commit b979b73ba1
7 changed files with 678 additions and 724 deletions

View File

@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest'
import { identifyInputType } from '../../src/main/services/validation/production-input-service'
describe('production-input-service', () => {
it('identifies order numbers', () => {
expect(identifyInputType('SC12345678901234')).toBe('order_number')
})
it('identifies production ids', () => {
expect(identifyInputType('26A1234')).toBe('production_id')
})
it('returns unknown for unsupported formats', () => {
expect(identifyInputType('invalid-value')).toBe('unknown')
})
})

View File

@@ -0,0 +1,31 @@
import { describe, expect, it } from 'vitest'
import { SharedProductionIdsStore } from '../../src/main/services/validation/shared-production-ids-store'
describe('SharedProductionIdsStore', () => {
it('stores unique ids per sender', () => {
const store = new SharedProductionIdsStore()
store.set(1, ['A', 'B', 'A'])
expect(store.get(1)).toEqual(['A', 'B'])
})
it('keeps sender scopes isolated', () => {
const store = new SharedProductionIdsStore()
store.set(1, ['A'])
store.set(2, ['B'])
expect(store.get(1)).toEqual(['A'])
expect(store.get(2)).toEqual(['B'])
})
it('clears sender data', () => {
const store = new SharedProductionIdsStore()
store.set(1, ['A'])
store.clear(1)
expect(store.get(1)).toEqual([])
})
})