feat: add ScanRecord model with toJson
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
21
lib/models/scan_record.dart
Normal file
21
lib/models/scan_record.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
enum SendStatus { pending, success, failed }
|
||||
|
||||
class ScanRecord {
|
||||
final String barcode;
|
||||
final String codeType;
|
||||
final DateTime timestamp;
|
||||
SendStatus status;
|
||||
|
||||
ScanRecord({
|
||||
required this.barcode,
|
||||
required this.codeType,
|
||||
required this.timestamp,
|
||||
this.status = SendStatus.pending,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'barcode': barcode,
|
||||
'code_type': codeType,
|
||||
'timestamp': timestamp.toUtc().toIso8601String(),
|
||||
};
|
||||
}
|
||||
29
test/models/scan_record_test.dart
Normal file
29
test/models/scan_record_test.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pad_scanner/models/scan_record.dart';
|
||||
|
||||
void main() {
|
||||
group('ScanRecord', () {
|
||||
test('creates with correct defaults', () {
|
||||
final record = ScanRecord(
|
||||
barcode: '1234567890',
|
||||
codeType: 'CODE128',
|
||||
timestamp: DateTime.parse('2026-05-07T10:30:00Z'),
|
||||
);
|
||||
expect(record.barcode, '1234567890');
|
||||
expect(record.codeType, 'CODE128');
|
||||
expect(record.status, SendStatus.pending);
|
||||
});
|
||||
|
||||
test('toJson produces correct map', () {
|
||||
final record = ScanRecord(
|
||||
barcode: 'ABC123',
|
||||
codeType: 'QR',
|
||||
timestamp: DateTime.parse('2026-05-07T10:30:00Z'),
|
||||
);
|
||||
final json = record.toJson();
|
||||
expect(json['barcode'], 'ABC123');
|
||||
expect(json['code_type'], 'QR');
|
||||
expect(json['timestamp'], '2026-05-07T10:30:00.000Z');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user