feat(boxing): update many-to-one packing flow
This commit is contained in:
@@ -142,6 +142,152 @@ void main() {
|
||||
expect(result.errorMessage, '网络异常,请检查网络连接');
|
||||
});
|
||||
});
|
||||
|
||||
group('ApiService boxing APIs', () {
|
||||
test('fetchBoxInfo parses current boxes and box item ids', () async {
|
||||
final mockClient = _MockClient((request) async {
|
||||
return http.Response(
|
||||
jsonEncode({
|
||||
'zongpai_no': '26BW0011',
|
||||
'paichan_no': 'W00009',
|
||||
'work_order_no': '6-1(7)',
|
||||
'quantity': 80,
|
||||
'current_zongpai_boxes': [
|
||||
{'box_item_id': 101, 'box_no': 3, 'quantity': 30},
|
||||
],
|
||||
'existing_boxes': [
|
||||
{
|
||||
'box_no': 3,
|
||||
'items': [
|
||||
{
|
||||
'box_item_id': 101,
|
||||
'zongpai_no': '26BW0011',
|
||||
'work_order_no': '6-1(7)',
|
||||
'quantity': 30,
|
||||
'total_quantity': 80,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'max_box_no': 3,
|
||||
'suggested_box_no': 4,
|
||||
}),
|
||||
200,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
});
|
||||
|
||||
final svc = ApiService(client: mockClient);
|
||||
final result = await svc.fetchBoxInfo(
|
||||
baseUrl: 'http://localhost',
|
||||
zongpaiNo: '26BW0011',
|
||||
);
|
||||
|
||||
expect(result.success, isTrue);
|
||||
expect(result.currentZongpaiBoxes.single.boxItemId, 101);
|
||||
expect(result.existingBoxes.single.items.single.boxItemId, 101);
|
||||
expect(result.existingBoxes.single.items.single.totalQuantity, 80);
|
||||
expect(result.suggestedBoxNo, 4);
|
||||
});
|
||||
|
||||
test('saveBoxRecord parses zongpai number from success response', () async {
|
||||
final mockClient = _MockClient((request) async {
|
||||
return http.Response(
|
||||
jsonEncode({
|
||||
'box_item_id': 102,
|
||||
'paichan_no': 'W00009',
|
||||
'box_no': 4,
|
||||
'zongpai_no': '26BW0012',
|
||||
'quantity': 34,
|
||||
'created_at': '2026-05-13T10:00:00',
|
||||
}),
|
||||
200,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
});
|
||||
|
||||
final svc = ApiService(client: mockClient);
|
||||
final result = await svc.saveBoxRecord(
|
||||
baseUrl: 'http://localhost',
|
||||
zongpaiNo: '26BW0012',
|
||||
boxNo: 4,
|
||||
quantity: 34,
|
||||
boxMode: 'many-to-one',
|
||||
);
|
||||
|
||||
expect(result.success, isTrue);
|
||||
expect(result.boxItemId, 102);
|
||||
expect(result.zongpaiNo, '26BW0012');
|
||||
});
|
||||
|
||||
test('updateBoxRecord sends many-to-one box mode', () async {
|
||||
late Map<String, dynamic> body;
|
||||
final mockClient = _MockClient((request) async {
|
||||
final req = request as http.Request;
|
||||
body = jsonDecode(req.body) as Map<String, dynamic>;
|
||||
return http.Response(
|
||||
jsonEncode({
|
||||
'box_item_id': 102,
|
||||
'paichan_no': 'W00009',
|
||||
'box_no': 4,
|
||||
'zongpai_no': '26BW0012',
|
||||
'quantity': 20,
|
||||
'updated_at': '2026-05-13T10:00:00',
|
||||
}),
|
||||
200,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
});
|
||||
|
||||
final svc = ApiService(client: mockClient);
|
||||
final result = await svc.updateBoxRecord(
|
||||
baseUrl: 'http://localhost',
|
||||
boxItemId: 102,
|
||||
boxNo: 4,
|
||||
quantity: 20,
|
||||
boxMode: 'many-to-one',
|
||||
);
|
||||
|
||||
expect(result.success, isTrue);
|
||||
expect(body['box_mode'], 'many-to-one');
|
||||
});
|
||||
|
||||
test('deleteBoxRecord handles success and not found', () async {
|
||||
var calls = 0;
|
||||
final mockClient = _MockClient((request) async {
|
||||
calls += 1;
|
||||
if (calls == 1) {
|
||||
return http.Response(
|
||||
jsonEncode({'box_item_id': 102, 'deleted': true}),
|
||||
200,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
}
|
||||
return http.Response(
|
||||
jsonEncode({
|
||||
'error_code': 'BOX_ITEM_NOT_FOUND',
|
||||
'message': '指定装箱明细不存在',
|
||||
}),
|
||||
404,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
});
|
||||
|
||||
final svc = ApiService(client: mockClient);
|
||||
final ok = await svc.deleteBoxRecord(
|
||||
baseUrl: 'http://localhost',
|
||||
boxItemId: 102,
|
||||
);
|
||||
final missing = await svc.deleteBoxRecord(
|
||||
baseUrl: 'http://localhost',
|
||||
boxItemId: 999,
|
||||
);
|
||||
|
||||
expect(ok.success, isTrue);
|
||||
expect(missing.success, isFalse);
|
||||
expect(missing.errorMessage, '指定装箱明细不存在');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _MockClient extends http.BaseClient {
|
||||
|
||||
Reference in New Issue
Block a user