Some checks are pending
Flutter CI / build (push) Waiting to run
Co-authored-by: aider (ollama_chat/7b) <aider@aider.chat>
42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:sqflite/sqflite.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'db_helper.dart';
|
|
import 'invoice.dart';
|
|
|
|
void main() {
|
|
group('Invoice Tests', () {
|
|
late Database db;
|
|
|
|
setUp(() async {
|
|
final io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
|
|
String path = '${documentsDirectory.path}/test.db';
|
|
db = await openDatabase(path, version: 1, onCreate: DbHelper()._onCreate);
|
|
});
|
|
|
|
tearDown(() async {
|
|
await db.close();
|
|
final io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
|
|
String path = '${documentsDirectory.path}/test.db';
|
|
await io.File(path).delete();
|
|
});
|
|
|
|
test('Add and fetch invoice', () async {
|
|
final invoice = Invoice(
|
|
customerId: 1,
|
|
date: DateTime.now().toIso8601String(),
|
|
total: 90.0,
|
|
tax: 9.0,
|
|
discountTotal: 10.0,
|
|
);
|
|
|
|
await db.insert('invoices', invoice.toMap());
|
|
|
|
final List<Map<String, dynamic>> maps = await db.query('invoices');
|
|
expect(maps.length, 1);
|
|
|
|
final fetchedInvoice = Invoice.fromMap(maps.first);
|
|
expect(fetchedInvoice.customerId, 1);
|
|
});
|
|
});
|
|
}
|