Skip to content

Commit

Permalink
fix mixin detections
Browse files Browse the repository at this point in the history
  • Loading branch information
codekeyz committed Nov 5, 2024
1 parent 42afd20 commit f2eeda7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
3 changes: 2 additions & 1 deletion packages/yaroorm_cli/lib/src/builder/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class Item {

final migrationClasses =
classElements.where((element) => typeChecker(orm.Migration).isExactlyType(element.supertype!));
final entityClasses = classElements.where((element) => typeChecker(orm.Entity).isExactlyType(element.supertype!));
final entityClasses =
classElements.where((element) => element.mixins.any((mixin) => typeChecker(orm.Entity).isExactlyType(mixin)));

return (
migrations: migrationClasses.isEmpty ? null : Item(migrationClasses, identifier),
Expand Down
48 changes: 18 additions & 30 deletions packages/yaroorm_test/test/yaroorm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ void main() {
setUpAll(() => driver = DB.driver('foo_sqlite'));

test('should return SQLite Driver', () {
expect(
driver,
isA<SqliteDriver>().having(
(p0) => p0.type, 'has driver type', DatabaseDriverType.sqlite));
expect(driver, isA<SqliteDriver>().having((p0) => p0.type, 'has driver type', DatabaseDriverType.sqlite));
});

test('should have table blueprint', () {
Expand All @@ -41,10 +38,7 @@ void main() {
setUpAll(() => driver = DB.driver('moo_mysql'));

test('should return MySql Driver', () {
expect(
driver,
isA<MySqlDriver>().having(
(p0) => p0.type, 'has driver type', DatabaseDriverType.mysql));
expect(driver, isA<MySqlDriver>().having((p0) => p0.type, 'has driver type', DatabaseDriverType.mysql));
});

test('should have table blueprint', () {
Expand All @@ -62,10 +56,7 @@ void main() {
setUpAll(() => driver = DB.driver('bar_mariadb'));

test('should return MySql Driver', () {
expect(
driver,
isA<MySqlDriver>().having((p0) => p0.type, 'has driver type',
DatabaseDriverType.mariadb));
expect(driver, isA<MySqlDriver>().having((p0) => p0.type, 'has driver type', DatabaseDriverType.mariadb));
});

test('should have table blueprint', () {
Expand All @@ -83,10 +74,7 @@ void main() {
setUpAll(() => driver = DB.driver('foo_pgsql'));

test('should return Postgres Driver', () {
expect(
driver,
isA<PostgreSqlDriver>().having(
(p0) => p0.type, 'has driver type', DatabaseDriverType.pgsql));
expect(driver, isA<PostgreSqlDriver>().having((p0) => p0.type, 'has driver type', DatabaseDriverType.pgsql));
});

test('should have table blueprint', () {
Expand All @@ -99,18 +87,18 @@ void main() {
});
});

// test('should err when Query without driver', () async {
// late Object error;
// try {
// await Query.table<User>().findMany();
// } catch (e) {
// error = e;
// }

// expect(
// error,
// isA<StateError>()
// .having((p0) => p0.message, '', 'Driver not set for query. Make sure you supply a driver using .driver()'),
// );
// });
test('should err when Query without driver', () async {
late Object error;
try {
await Query.table<User>().findMany();
} catch (e) {
error = e;
}

expect(
error,
isA<StateError>()
.having((p0) => p0.message, '', 'Driver not set for query. Make sure you supply a driver using .driver()'),
);
});
}

0 comments on commit f2eeda7

Please sign in to comment.