Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
#8. Fixing test
Browse files Browse the repository at this point in the history
  • Loading branch information
matei-tm committed Mar 22, 2019
1 parent 48782e3 commit 012dc92
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/lib/generator/entity_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import 'package:sqflite/sqflite.dart';
import 'dart:async';
/*import 'package:todo_currentProjectPackage_path/abstract_database_helper.dart';*/
import '${emittedEntity.packageIdentifier}';
""";
}

Expand All @@ -48,7 +47,6 @@ import '${emittedEntity.packageIdentifier}';
StringBuffer getCommonStart() {
StringBuffer sb = StringBuffer();
sb.writeln(_getGeneralImports());
sb.writeln();
sb.writeln(_getMixinHead());
sb.writeln(_getMixinBodyCommonFields());

Expand Down
98 changes: 94 additions & 4 deletions src/test/flutter_sqlite_m8_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,100 @@ void main() async {

test('Test raw output', () async {
final output = await generator.generate(_library, null);
final expected = r'''/*
Instance of 'EntityWriter'
Entity:my_account_related_table Model:HealthEntryAccountRelated
{_id: Instance of 'EntityAttribute', _description: Instance of 'EntityAttribute', _account_id: Instance of 'EntityAttribute'}*/''';
final expected = r'''import 'package:sqflite/sqflite.dart';
import 'dart:async';
/*import 'package:todo_currentProjectPackage_path/abstract_database_helper.dart';*/
import 'package:__test__/account_related.dart';
mixin HealthEntryAccountRelatedDatabaseHelper /*implements AbstractDatabaseHelper*/ {
Future<Database> db;
final theHealthEntryAccountRelatedColumns = ["my_id_column", "my_description_column", "my_account_id_column"];
final String _theHealthEntryAccountRelatedTableHandler = 'my_account_related_table';
final String primaryKeyHandler = 'id';
Future createHealthEntryAccountRelatedTable(Database db) async {
await db.execute(
'CREATE TABLE $_theHealthEntryAccountRelatedTableHandler ($primaryKeyHandler INTEGER PRIMARY KEY, account_id INTEGER, record_date INTEGER, is_deleted INTEGER )');
}
Future<int> saveHealthEntryAccountRelated(HealthEntryAccountRelated instanceHealthEntryAccountRelated) async {
var dbClient = await db;
var result = await dbClient.insert(_theHealthEntryAccountRelatedTableHandler, instanceHealthEntryAccountRelated.toMap());
return result;
}
Future<List> getHealthEntryAccountRelatedsAll() async {
var dbClient = await db;
var result =
await dbClient.query(_theHealthEntryAccountRelatedTableHandler, columns: theHealthEntryAccountRelatedColumns, where: 'is_deleted != 1');
return result.toList();
}
Future<List> getHealthEntryAccountRelatedsByAccountId(int accountId) async {
var dbClient = await db;
var result = await dbClient.query(_theHealthEntryAccountRelatedTableHandler,
columns: theHealthEntryAccountRelatedColumns,
where: 'account_id = ? AND is_deleted != 1',
whereArgs: [accountId]);
return result.toList();
}
Future<int> getHealthEntryAccountRelatedsCount() async {
var dbClient = await db;
return Sqflite.firstIntValue(
await dbClient.rawQuery('SELECT COUNT(*) FROM $_theHealthEntryAccountRelatedTableHandler WHERE is_deleted != 1'));
}
Future<HealthEntryAccountRelated> getHealthEntryAccountRelated(int id) async {
var dbClient = await db;
List<Map> result = await dbClient.query(_theHealthEntryAccountRelatedTableHandler,
columns: theHealthEntryAccountRelatedColumns, where: '$primaryKeyHandler = ? AND is_deleted != 1', whereArgs: [id]);
/*
if (result.length > 0) {
return HealthEntryAccountRelated.fromMap(result.first);
}
*/
return null;
}
Future<int> deleteHealthEntryAccountRelated(int id) async {
var dbClient = await db;
return await dbClient
.delete(_theHealthEntryAccountRelatedTableHandler, where: '$primaryKeyHandler = ?', whereArgs: [id]);
}
Future<bool> deleteHealthEntryAccountRelatedsAll() async {
var dbClient = await db;
await dbClient.delete(_theHealthEntryAccountRelatedTableHandler);
return true;
}
Future<int> updateHealthEntryAccountRelated(HealthEntryAccountRelated instanceHealthEntryAccountRelated) async {
var dbClient = await db;
return await dbClient.update(_theHealthEntryAccountRelatedTableHandler, instanceHealthEntryAccountRelated.toMap(),
where: "$primaryKeyHandler = ?", whereArgs: [instanceHealthEntryAccountRelated.id]);
}
Future<int> softdeleteHealthEntryAccountRelated(int id) async {
var dbClient = await db;
var map = Map<String, dynamic>();
map['is_deleted'] = 1;
return await dbClient
.update(_theHealthEntryAccountRelatedTableHandler, map, where: "$primaryKeyHandler = ?", whereArgs: [id]);
}
}
// Entity:my_account_related_table Model:HealthEntryAccountRelated
//{_id: Instance of 'EntityAttribute', _description: Instance of 'EntityAttribute', _accountId: Instance of 'EntityAttribute'}''';
expect(output, expected);
});

Expand Down

0 comments on commit 012dc92

Please sign in to comment.