44 lines
2.8 KiB
JavaScript
44 lines
2.8 KiB
JavaScript
import test from 'node:test'
|
|||
|
|
import assert from 'node:assert/strict'
|
||
|
|
import { listReturnCountTasks, scanReturnCountCarton, scanReturnCountTasks, getCurrentReturnCountTask, beginReturnCountTask, confirmReturnCount } from '../src/api/return-counting.js'
|
||
|
|
import { session } from '../src/stores/session.js'
|
||
|
|
|
||
|
|
test('counting preserves box contents and retry key without accepting client warehouse scope', async () => {
|
||
|
|
session.apiBase = '/api'; session.token = 'counting-test'
|
||
|
|
const calls = []
|
||
|
|
globalThis.uni = { request(options) { calls.push(options); options.success({ statusCode: 200, data: { code: '200', data: { status: 'PENDING' } }, header: {} }) } }
|
||
|
|
await listReturnCountTasks({ page: 2, keyword: ' RC#2-1 ' })
|
||
|
|
await scanReturnCountCarton('RC#2-1')
|
||
|
|
const request = { idempotencyKey: 'count-retry', boxes: [{ cartonMark: 'RC#2-1', items: [{ skuCode: 'SKU-1', quantity: 3 }] }, { cartonMark: 'RC#2-2', items: [{ skuCode: 'SKU-1', quantity: 7 }] }] }
|
||
|
|
await confirmReturnCount('RR/1', request)
|
||
|
|
assert.deepEqual(calls.map(row => [row.method, row.url]), [
|
||
|
|
['GET', '/api/pda/v1/last-leg/return-inventory/counting/tasks?page=2&size=10&keyword=RC%232-1'],
|
||
|
|
['GET', '/api/pda/v1/last-leg/return-inventory/counting/cartons/RC%232-1'],
|
||
|
|
['POST', '/api/pda/v1/last-leg/return-inventory/counting/receipts/RR%2F1']
|
||
|
|
])
|
||
|
|
assert.deepEqual(calls[2].data, request)
|
||
|
|
assert.ok(calls.every(row => row.header.Authorization === 'Bearer counting-test'))
|
||
|
|
})
|
||
|
|
|
||
|
|
test('unified scan supports box and pallet codes and preserves the no-count empty result', async () => {
|
||
|
|
session.apiBase = '/api'; session.token = 'counting-test'
|
||
|
|
const urls = []
|
||
|
|
globalThis.uni = { request(options) { urls.push(options.url); options.success({ statusCode: 200, data: { code: '200', data: [] }, header: {} }) } }
|
||
|
|
assert.deepEqual(await scanReturnCountTasks(' RC#2-1 '), [])
|
||
|
|
assert.deepEqual(await scanReturnCountTasks('PLT/1'), [])
|
||
|
|
assert.deepEqual(urls, ['/api/pda/v1/last-leg/return-inventory/counting/scan/RC%232-1', '/api/pda/v1/last-leg/return-inventory/counting/scan/PLT%2F1'])
|
||
|
|
})
|
||
|
|
|
||
|
|
test('current task preserves null and begin uses the operator-scoped claim route', async () => {
|
||
|
|
session.apiBase = '/api'; session.token = 'counting-test'
|
||
|
|
const calls = []
|
||
|
|
globalThis.uni = { request(options) { calls.push(options); options.success({ statusCode: 200, data: { code: '200', data: options.method === 'GET' ? null : { receiptNo: 'RR/1', status: 'COUNTING' } }, header: {} }) } }
|
||
|
|
assert.equal(await getCurrentReturnCountTask(), null)
|
||
|
|
assert.equal((await beginReturnCountTask('RR/1')).status, 'COUNTING')
|
||
|
|
assert.deepEqual(calls.map(row => [row.method, row.url]), [
|
||
|
|
['GET', '/api/pda/v1/last-leg/return-inventory/counting/current'],
|
||
|
|
['POST', '/api/pda/v1/last-leg/return-inventory/counting/receipts/RR%2F1/begin']
|
||
|
|
])
|
||
|
|
assert.equal(calls[1].data, undefined)
|
||
|
|
})
|