Skip to content

Commit

Permalink
tiny improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
codekeyz committed May 4, 2024
1 parent c283b98 commit 0564850
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 199 deletions.
236 changes: 197 additions & 39 deletions _tests_/lib/test_data.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,204 @@
typedef UserData = ({String firstname, String lastname, int age, String homeAddress});
import 'package:yaroorm_tests/src/models.dart';

final usersList = <UserData>[
typedef UserData = ({
String firstname,
String lastname,
int age,
String homeAddress
});

final usersList = <NewUser>[
/// Ghana Users - [6]
(firstname: 'Kofi', lastname: 'Duke', age: 22, homeAddress: "Accra, Ghana"),
(firstname: 'Foo', lastname: 'Bar', age: 23, homeAddress: "Kumasi, Ghana"),
(firstname: 'Bar', lastname: 'Moo', age: 24, homeAddress: "Cape Coast, Ghana"),
(firstname: 'Kee', lastname: 'Koo', age: 25, homeAddress: "Accra, Ghana"),
(firstname: 'Poo', lastname: 'Paa', age: 26, homeAddress: "Accra, Ghana"),
(firstname: 'Merh', lastname: 'Moor', age: 27, homeAddress: "Accra, Ghana"),
NewUser(
firstname: 'Kofi',
lastname: 'Duke',
age: 22,
homeAddress: "Accra, Ghana",
),
NewUser(
firstname: 'Foo',
lastname: 'Bar',
age: 23,
homeAddress: "Kumasi, Ghana",
),
NewUser(
firstname: 'Bar',
lastname: 'Moo',
age: 24,
homeAddress: "Cape Coast, Ghana",
),
NewUser(
firstname: 'Kee',
lastname: 'Koo',
age: 25,
homeAddress: "Accra, Ghana",
),
NewUser(
firstname: 'Poo',
lastname: 'Paa',
age: 26,
homeAddress: "Accra, Ghana",
),
NewUser(
firstname: 'Merh',
lastname: 'Moor',
age: 27,
homeAddress: "Accra, Ghana",
),

/// Nigerian Users - [22]
(firstname: 'Abdul', lastname: 'Ibrahim', age: 28, homeAddress: "Owerri, Nigeria"),
(firstname: 'Amina', lastname: 'Sule', age: 29, homeAddress: "Owerri, Nigeria"),
(firstname: 'Chukwudi', lastname: 'Okafor', age: 30, homeAddress: "Lagos, Nigeria"),
(firstname: 'Chioma', lastname: 'Nwosu', age: 31, homeAddress: "Lagos, Nigeria"),
(firstname: 'Yusuf', lastname: 'Aliyu', age: 32, homeAddress: "Owerri, Nigeria"),
(firstname: 'Blessing', lastname: 'Okonkwo', age: 33, homeAddress: "Owerri, Nigeria"),
(firstname: 'Tunde', lastname: 'Williams', age: 34, homeAddress: "Abuja, Nigeria"),
(firstname: 'Rukayat', lastname: 'Sanni', age: 35, homeAddress: "Abuja, Nigeria"),
(firstname: 'Segun', lastname: 'Adeleke', age: 36, homeAddress: "Lagos, Nigeria"),
(firstname: 'Abdullahi', lastname: 'Mohammed', age: 46, homeAddress: "Lagos, Nigeria"),
(firstname: 'Chidinma', lastname: 'Onyeka', age: 47, homeAddress: "Owerri, Nigeria"),
(firstname: 'Bola', lastname: 'Akinwumi', age: 48, homeAddress: "Owerri, Nigeria"),
(firstname: 'Haruna', lastname: 'Bello', age: 49, homeAddress: "Lagos, Nigeria"),
(firstname: 'Habiba', lastname: 'Yusuf', age: 50, homeAddress: "Owerri, Nigeria"),
(firstname: 'Tochukwu', lastname: 'Eze', age: 50, homeAddress: "Lagos, Nigeria"),
(firstname: 'Ade', lastname: 'Ogunbanjo', age: 50, homeAddress: "Owerri, Nigeria"),
(firstname: 'Zainab', lastname: 'Abubakar', age: 50, homeAddress: "Lagos, Nigeria"),
(firstname: 'Chijioke', lastname: 'Nwachukwu', age: 54, homeAddress: "Owerri, Nigeria"),
(firstname: 'Folake', lastname: 'Adewale', age: 55, homeAddress: "Owerri, Nigeria"),
(firstname: 'Mustafa', lastname: 'Olawale', age: 56, homeAddress: "Lagos, Nigeria"),
(firstname: 'Halima', lastname: 'Idris', age: 57, homeAddress: "Lagos, Nigeria"),
(firstname: 'Chukwuemeka', lastname: 'Okonkwo', age: 58, homeAddress: "Abuja, Nigeria"),
NewUser(
firstname: 'Abdul',
lastname: 'Ibrahim',
age: 28,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Amina',
lastname: 'Sule',
age: 29,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Chukwudi',
lastname: 'Okafor',
age: 30,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Chioma',
lastname: 'Nwosu',
age: 31,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Yusuf',
lastname: 'Aliyu',
age: 32,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Blessing',
lastname: 'Okonkwo',
age: 33,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Tunde',
lastname: 'Williams',
age: 34,
homeAddress: "Abuja, Nigeria"),
NewUser(
firstname: 'Rukayat',
lastname: 'Sanni',
age: 35,
homeAddress: "Abuja, Nigeria"),
NewUser(
firstname: 'Segun',
lastname: 'Adeleke',
age: 36,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Abdullahi',
lastname: 'Mohammed',
age: 46,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Chidinma',
lastname: 'Onyeka',
age: 47,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Bola',
lastname: 'Akinwumi',
age: 48,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Haruna',
lastname: 'Bello',
age: 49,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Habiba',
lastname: 'Yusuf',
age: 50,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Tochukwu',
lastname: 'Eze',
age: 50,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Ade',
lastname: 'Ogunbanjo',
age: 50,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Zainab',
lastname: 'Abubakar',
age: 50,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Chijioke',
lastname: 'Nwachukwu',
age: 54,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Folake',
lastname: 'Adewale',
age: 55,
homeAddress: "Owerri, Nigeria"),
NewUser(
firstname: 'Mustafa',
lastname: 'Olawale',
age: 56,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Halima',
lastname: 'Idris',
age: 57,
homeAddress: "Lagos, Nigeria"),
NewUser(
firstname: 'Chukwuemeka',
lastname: 'Okonkwo',
age: 58,
homeAddress: "Abuja, Nigeria"),

/// Kenyan Users - [9]
(firstname: 'Kevin', lastname: 'Luke', age: 37, homeAddress: "Nairobi, Kenya"),
(firstname: 'Foop', lastname: 'Farr', age: 38, homeAddress: "CBD, Kenya"),
(firstname: 'Koin', lastname: 'Karl', age: 39, homeAddress: "Mumbasa, Kenya"),
(firstname: 'Moo', lastname: 'Maa', age: 40, homeAddress: "Westlands, Kenya"),
(firstname: 'Merh', lastname: 'Merh', age: 41, homeAddress: "Nairobi, Kenya"),
(firstname: 'Ibrahim', lastname: 'Bakare', age: 42, homeAddress: "Nairobi, Kenya"),
(firstname: 'Grace', lastname: 'Adegoke', age: 43, homeAddress: "Nairobi, Kenya"),
(firstname: 'Ahmed', lastname: 'Umar', age: 44, homeAddress: "Nairobi, Kenya"),
(firstname: 'Nneka', lastname: 'Okoli', age: 45, homeAddress: "Nairobi, Kenya"),
NewUser(
firstname: 'Kevin',
lastname: 'Luke',
age: 37,
homeAddress: "Nairobi, Kenya"),
NewUser(
firstname: 'Foop', lastname: 'Farr', age: 38, homeAddress: "CBD, Kenya"),
NewUser(
firstname: 'Koin',
lastname: 'Karl',
age: 39,
homeAddress: "Mumbasa, Kenya"),
NewUser(
firstname: 'Moo',
lastname: 'Maa',
age: 40,
homeAddress: "Westlands, Kenya"),
NewUser(
firstname: 'Merh',
lastname: 'Merh',
age: 41,
homeAddress: "Nairobi, Kenya"),
NewUser(
firstname: 'Ibrahim',
lastname: 'Bakare',
age: 42,
homeAddress: "Nairobi, Kenya"),
NewUser(
firstname: 'Grace',
lastname: 'Adegoke',
age: 43,
homeAddress: "Nairobi, Kenya"),
NewUser(
firstname: 'Ahmed',
lastname: 'Umar',
age: 44,
homeAddress: "Nairobi, Kenya"),
NewUser(
firstname: 'Nneka',
lastname: 'Okoli',
age: 45,
homeAddress: "Nairobi, Kenya"),
];
45 changes: 25 additions & 20 deletions _tests_/test/integration/e2e_basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ void runBasicE2ETest(String connectionName) {
expect(driver.isOpen, isTrue);
});

test('should have no tables', () async => expect(await driver.hasTable('users'), isFalse));
test('should have no tables',
() async => expect(await driver.hasTable('users'), isFalse));

test('should execute migration', () async {
await runMigrator(connectionName, 'migrate');
Expand All @@ -27,12 +28,13 @@ void runBasicE2ETest(String connectionName) {
test('should insert single user', () async {
final firstData = usersList.first;
final query = UserQuery.driver(driver);
final result = await query.create(

final result = await query.insert(NewUser(
firstname: firstData.firstname,
lastname: firstData.lastname,
age: firstData.age,
homeAddress: firstData.homeAddress,
);
));

final exists = await query.where((user) => user.id(result.id)).exists();
expect(exists, isTrue);
Expand All @@ -41,20 +43,14 @@ void runBasicE2ETest(String connectionName) {
test('should insert many users', () async {
final query = UserQuery.driver(driver);

for (final user in usersList.skip(1)) {
await query.create(
firstname: user.firstname,
lastname: user.lastname,
age: user.age,
homeAddress: user.homeAddress,
);
}
await query.insertMany(usersList.skip(1).toList());

expect(await query.count(), usersList.length);
});

group('Aggregate Functions', () {
final query = UserQuery.driver(driver).where((user) => user.$isLike('home_address', '%%, Ghana'));
final query = UserQuery.driver(driver)
.where((user) => user.$isLike('home_address', '%%, Ghana'));
List<User> usersInGhana = [];

setUpAll(() async {
Expand Down Expand Up @@ -88,7 +84,8 @@ void runBasicE2ETest(String connectionName) {

test('concat', () async {
Matcher matcher(String separator) {
if ([DatabaseDriverType.sqlite, DatabaseDriverType.pgsql].contains(driver.type)) {
if ([DatabaseDriverType.sqlite, DatabaseDriverType.pgsql]
.contains(driver.type)) {
return equals(usersInGhana.map((e) => e.age).join(separator));
}

Expand All @@ -107,7 +104,10 @@ void runBasicE2ETest(String connectionName) {
final user = await query.findOne();
expect(user!.id, 1);

await query.update(firstname: value('Red Oil'), age: value(100));
await query.update(UpdateUser(
firstname: value('Red Oil'),
age: value(100),
));

final userFromDB = await query.findOne();
expect(user, isNotNull);
Expand All @@ -123,16 +123,20 @@ void runBasicE2ETest(String connectionName) {
expect(usersWithAge50.length, 4);
expect(usersWithAge50.every((e) => e.age == 50), isTrue);

await age50Users.update(homeAddress: value('Keta, Ghana'));
await age50Users.update(
UpdateUser(homeAddress: value('Keta, Ghana')),
);

final updatedResult = await age50Users.findMany();
expect(updatedResult.length, 4);
expect(updatedResult.every((e) => e.age == 50), isTrue);
expect(updatedResult.every((e) => e.homeAddress == 'Keta, Ghana'), isTrue);
expect(
updatedResult.every((e) => e.homeAddress == 'Keta, Ghana'), isTrue);
});

test('should fetch only users in Ghana', () async {
final userQuery = UserQuery.driver(driver).where((user) => user.$isLike('home_address', '%, Ghana'));
final userQuery = UserQuery.driver(driver)
.where((user) => user.$isLike('home_address', '%, Ghana'));

final usersInGhana = await userQuery.findMany();
expect(usersInGhana.length, 10);
Expand All @@ -147,7 +151,7 @@ void runBasicE2ETest(String connectionName) {
test('should get all users between age 35 and 50', () async {
final age50Users = await UserQuery.driver(driver)
.where((user) => user.$isBetween('age', [35, 50]))
.findMany(orderBy: [OrderUserBy.age(OrderDirection.desc)]);
.findMany(orderBy: [OrderUserBy.age(order: OrderDirection.desc)]);

expect(age50Users.length, 19);
expect(age50Users.first.age, 50);
Expand All @@ -157,7 +161,7 @@ void runBasicE2ETest(String connectionName) {
test('should get all users in somewhere in Nigeria', () async {
final users = await UserQuery.driver(driver)
.where((user) => user.$isLike('home_address', '%, Nigeria'))
.findMany(orderBy: [OrderUserBy.homeAddress(OrderDirection.asc)]);
.findMany(orderBy: [OrderUserBy.homeAddress()]);

expect(users.length, 18);
expect(users.first.homeAddress, 'Abuja, Nigeria');
Expand Down Expand Up @@ -188,7 +192,8 @@ void runBasicE2ETest(String connectionName) {
});

test('should delete many users', () async {
final query = UserQuery.driver(driver).where((user) => user.$isLike('home_address', '%, Nigeria'));
final query = UserQuery.driver(driver)
.where((user) => user.$isLike('home_address', '%, Nigeria'));
expect(await query.findMany(), isNotEmpty);

await query.delete();
Expand Down
Loading

0 comments on commit 0564850

Please sign in to comment.