Some checks are pending
Flutter CI / build (push) Waiting to run
Co-authored-by: aider (ollama_chat/7b) <aider@aider.chat>
41 lines
1.2 KiB
Dart
41 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 'customer.dart';
|
|
|
|
void main() {
|
|
group('Customer 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 customer', () async {
|
|
final customer = Customer(
|
|
name: 'Test Customer',
|
|
phone: '1234567890',
|
|
address: 'Test Address',
|
|
email: 'test@example.com',
|
|
);
|
|
|
|
await db.insert('customers', customer.toMap());
|
|
|
|
final List<Map<String, dynamic>> maps = await db.query('customers');
|
|
expect(maps.length, 1);
|
|
|
|
final fetchedCustomer = Customer.fromMap(maps.first);
|
|
expect(fetchedCustomer.name, 'Test Customer');
|
|
});
|
|
});
|
|
}
|