feat: handle off-shelf registration results
This commit is contained in:
@@ -8,7 +8,11 @@ void main() {
|
||||
test('returns ok on 200', () async {
|
||||
final mockClient = _MockClient((request) async {
|
||||
return http.Response(
|
||||
jsonEncode({'zongpai_no': '26B1', 'location_code': 'A01-02-03', 'created_at': '2026-05-11T10:00:00'}),
|
||||
jsonEncode({
|
||||
'zongpai_no': '26B1',
|
||||
'location_code': 'A01-02-03',
|
||||
'created_at': '2026-05-11T10:00:00',
|
||||
}),
|
||||
200,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
@@ -21,16 +25,69 @@ void main() {
|
||||
);
|
||||
expect(result.success, isTrue);
|
||||
expect(result.isDuplicate, isFalse);
|
||||
expect(result.isOffShelfSuccess, isFalse);
|
||||
});
|
||||
|
||||
test('returns duplicate on 409 with location_code and registered_at', () async {
|
||||
test('returns off-shelf success on 200 with previous_location', () async {
|
||||
final mockClient = _MockClient((request) async {
|
||||
return http.Response(
|
||||
jsonEncode({
|
||||
'error_code': 'DUPLICATE_LOCATION',
|
||||
'message': '该总排号已存在货位记录',
|
||||
'location_code': 'A01-02-03',
|
||||
'registered_at': '2026-05-11T10:00:00',
|
||||
'zongpai_no': '26B1',
|
||||
'location_code': 'TRANS-01',
|
||||
'previous_location': 'A01-02-03',
|
||||
'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.registerLocation(
|
||||
baseUrl: 'http://localhost',
|
||||
zongpaiNo: '26B1',
|
||||
locationCode: 'TRANS-01',
|
||||
);
|
||||
expect(result.success, isTrue);
|
||||
expect(result.isOffShelfSuccess, isTrue);
|
||||
expect(result.isDuplicate, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'returns duplicate on 409 with location_code and registered_at',
|
||||
() async {
|
||||
final mockClient = _MockClient((request) async {
|
||||
return http.Response(
|
||||
jsonEncode({
|
||||
'error_code': 'DUPLICATE_LOCATION',
|
||||
'message': '该总排号已存在货位记录',
|
||||
'location_code': 'A01-02-03',
|
||||
'registered_at': '2026-05-11T10:00:00',
|
||||
}),
|
||||
409,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
});
|
||||
final svc = ApiService(client: mockClient);
|
||||
final result = await svc.registerLocation(
|
||||
baseUrl: 'http://localhost',
|
||||
zongpaiNo: '26B1',
|
||||
locationCode: 'A02-01-01',
|
||||
);
|
||||
expect(result.success, isFalse);
|
||||
expect(result.isDuplicate, isTrue);
|
||||
expect(result.duplicateInfo?['location_code'], 'A01-02-03');
|
||||
expect(result.duplicateInfo?['registered_at'], '2026-05-11T10:00:00');
|
||||
},
|
||||
);
|
||||
|
||||
test('returns already off shelf on 409 ALREADY_OFF_SHELF', () async {
|
||||
final mockClient = _MockClient((request) async {
|
||||
return http.Response(
|
||||
jsonEncode({
|
||||
'error_code': 'ALREADY_OFF_SHELF',
|
||||
'message': '该总排号已下架至转运区域,不可重新上架',
|
||||
'location_code': 'TRANS-01',
|
||||
'registered_at': '2026-05-13T10:00:00',
|
||||
}),
|
||||
409,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
@@ -43,15 +100,19 @@ void main() {
|
||||
locationCode: 'A02-01-01',
|
||||
);
|
||||
expect(result.success, isFalse);
|
||||
expect(result.isDuplicate, isTrue);
|
||||
expect(result.duplicateInfo?['location_code'], 'A01-02-03');
|
||||
expect(result.duplicateInfo?['registered_at'], '2026-05-11T10:00:00');
|
||||
expect(result.isDuplicate, isFalse);
|
||||
expect(result.isAlreadyOffShelf, isTrue);
|
||||
expect(result.errorMessage, '该总排号已下架至转运区域,不可重新上架');
|
||||
expect(result.conflictInfo?['location_code'], 'TRANS-01');
|
||||
});
|
||||
|
||||
test('returns error on 400 with message', () async {
|
||||
final mockClient = _MockClient((request) async {
|
||||
return http.Response(
|
||||
jsonEncode({'error_code': 'INVALID_ZONGPAI', 'message': 'INVALID_ZONGPAI'}),
|
||||
jsonEncode({
|
||||
'error_code': 'INVALID_ZONGPAI',
|
||||
'message': 'INVALID_ZONGPAI',
|
||||
}),
|
||||
400,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user