Skip to content

Commit

Permalink
Add tests to app_database
Browse files Browse the repository at this point in the history
  • Loading branch information
Syutkin committed Dec 27, 2024
1 parent f2058ae commit 393c48c
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 54 deletions.
16 changes: 8 additions & 8 deletions lib/src/constants/pubspec.yaml.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ sealed class Pubspec {
static const PubspecVersion version = (
/// Non-canonical string representation of the version as provided
/// in the pubspec.yaml file.
representation: r'0.5.0-beta.1+391',
representation: r'0.5.0-beta.1+392',

/// Returns a 'canonicalized' representation
/// of the application version.
/// This represents the version string in accordance with
/// Semantic Versioning (SemVer) standards.
canonical: r'0.5.0-beta.1+391',
canonical: r'0.5.0-beta.1+392',

/// MAJOR version when you make incompatible API changes.
/// The major version number: 1 in "1.2.3".
Expand All @@ -118,19 +118,19 @@ sealed class Pubspec {
preRelease: <String>[r'beta', r'1'],

/// The build identifier: "foo" in "1.2.3+foo".
build: <String>[r'391'],
build: <String>[r'392'],
);

/// Build date and time (UTC)
static final DateTime timestamp = DateTime.utc(
2024,
12,
27,
10,
57,
54,
23,
139,
19,
8,
40,
77,
216,
);

/// Name
Expand Down
61 changes: 17 additions & 44 deletions lib/src/feature/database/drift/app_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class AppDatabase extends _$AppDatabase {
.getSingleOrNull();
}

/// Список "неудалённых" гонщиков
/// Список "неудалённых" гонщиков, отсортированных по именам
Selectable<Rider> get getRiders {
return _getRiders(isDeleted: false);
}
Expand Down Expand Up @@ -446,21 +446,21 @@ class AppDatabase extends _$AppDatabase {
}

/// Добавляет участника соревнований
Future<int> addParticipant({
required int raceId,
required int riderId,
required int number,
String? category,
String? rfid,
}) {
return _addParticipant(
raceId: raceId,
riderId: riderId,
number: number,
category: category,
rfid: rfid,
);
}
// Future<int> _addParticipant({
// required int raceId,
// required int riderId,
// required int number,
// String? category,
// String? rfid,
// }) {
// return _addParticipant(
// raceId: raceId,
// riderId: riderId,
// number: number,
// category: category,
// rfid: rfid,
// );
// }

/// Обновляет участника соревнований
Future<int> updateParticipant({
Expand Down Expand Up @@ -1123,7 +1123,7 @@ class AppDatabase extends _$AppDatabase {
team: item.team,
birthday: item.age,
);
final participantId = await addParticipant(
final participantId = await _addParticipant(
raceId: raceId,
riderId: riderId,
number: item.number,
Expand All @@ -1138,33 +1138,6 @@ class AppDatabase extends _$AppDatabase {
}
}
});
// await transaction(() async {
// for (final stageName in race.stageNames) {
// stages[stageName] = await addStage(raceId: raceId, name: stageName);
// }
// for (final item in race.startItems) {
// final riderId = await addRider(
// name: item.name,
// nickname: item.nickname,
// city: item.city,
// team: item.team,
// birthday: item.age,
// );
// final participantId = await addParticipant(
// raceId: raceId,
// riderId: riderId,
// number: item.number,
// category: item.category,
// );
// for (final stageName in stages.keys) {
// await _addStartInfo(
// stageId: stages[stageName]!,
// participantId: participantId,
// startTime: item.startTimes![stageName]!,
// );
// }
// }
// });
return raceId;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/feature/ntp/logic/ntp_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract interface class INtpProvider {

class NtpProvider implements INtpProvider {
@override
// TODO: implement offset stream
// ToDo: implement offset stream
Stream<int> get offset => throw UnimplementedError();

@override
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository: https://github.com/Syutkin/entime-mobile
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.5.0-beta.1+391
version: 0.5.0-beta.1+392

environment:
sdk: ^3.5.0
Expand Down
180 changes: 180 additions & 0 deletions test/src/feature/database/drift/app_database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ void main() {
expect(trail.distance, distance);
expect(trail.elevation, elevation);
});

test('Get trail', () async {
const trailName = 'trailName';

final id = await db.addTrail(name: trailName);
final trail = await db.getTrail(id);
expect(trail, isNotNull);
expect(trail?.name, trailName);
});
});

group('Tracks tests', () {
Expand Down Expand Up @@ -443,6 +452,177 @@ void main() {
});
});

group('Riders tests', () {
test('Get riders', () async {
final riders = await db.getRiders.get();
expect(riders.length, 79);
});

test('Add and get rider', () async {
const name = 'name';
const nickname = 'nickname';
const birthday = '10-10-2000';
const city = 'city';
const comment = 'comment';
const email = 'email@mail.mail';
const phone = '+79990009999';
const team = 'team';

final id = await db.addRider(
name: name,
nickname: nickname,
birthday: birthday,
city: city,
comment: comment,
email: email,
phone: phone,
team: team,
);

final riders = await db.getRiders.get();
expect(id, 80);
expect(riders.length, 80);
expect(riders.first.name, name);
expect(riders.first.nickname, nickname);
expect(riders.first.birthday, birthday);
expect(riders.first.city, city);
expect(riders.first.comment, comment);
expect(riders.first.email, email);
expect(riders.first.phone, phone);
expect(riders.first.team, team);
});

test('Update rider', () async {
const id = 50;
const name = 'name';
const nickname = 'nickname';
const birthday = '10-10-2000';
const city = 'city';
const comment = 'comment';
const email = 'email@mail.mail';
const phone = '+79990009999';
const team = 'team';

final count = await db.updateRider(
id: id,
name: name,
nickname: nickname,
birthday: birthday,
city: city,
comment: comment,
email: email,
phone: phone,
team: team,
);

final riders = await db.getRiders.get();
// Гонщик будет первым из-за сортировки по именам
expect(count, 1);
expect(riders.first.id, id);
expect(riders.first.name, name);
expect(riders.first.nickname, nickname);
expect(riders.first.birthday, birthday);
expect(riders.first.city, city);
expect(riders.first.comment, comment);
expect(riders.first.email, email);
expect(riders.first.phone, phone);
expect(riders.first.team, team);
});

test('Trying to update non existed rider', () async {
const id = 99;
const name = 'name';

final count = await db.updateRider(
id: id,
name: name,
);

final riders = await db.getRiders.get();
// Гонщик будет первым из-за сортировки по именам
expect(count, 0);
expect(riders.length, 79);
});

test('"Delete" rider', () async {
const id = 5;

final count = await db.updateRider(
id: id,
isDeleted: true,
);

final riders = await db.getRiders.get();
expect(count, 1);
expect(riders.length, 78);
});
});

group('Participants tests', () {
test('Update participant', () async {
const raceId = 2;
const riderId = 5;
const stageId = 1;
const number = 55;
const newNumber = 100;
const statusId = 1;
const category = 'category';
const rfid = 'rfid';
// const isDeleted = false;

final existed = await db
.getNumberAtStarts(stageId: stageId, number: number)
.getSingle();

final id = existed.participantId;
expect(id, 21);
expect(existed.raceId, 1);
expect(existed.riderId, 21);

final count = await db.updateParticipant(
id: id,
raceId: raceId,
riderId: riderId,
number: newNumber,
statusId: statusId,
category: category,
rfid: rfid,
);

expect(count, 1);

final updated = await db
.getNumberAtStarts(stageId: stageId, number: newNumber)
.getSingle();

expect(updated.participantId, id);
expect(updated.raceId, raceId);
expect(updated.riderId, riderId);
expect(updated.category, category);
expect(updated.rfid, rfid);
});
});

group('Categories tests', () {
test('Get categories', () async {
const id = 1;
const raceId = 1;
const category = 'category';

var categories = await db.getCategories(raceId);
expect(categories.length, 5);

await db.updateParticipant(
id: id,
category: category,
);
categories = await db.getCategories(raceId);

expect(categories.length, 6);
expect(categories.contains(category), true);
});
});

group('Test setStartingInfo', () {
test('All field filled for starting info', () async {
final stage = (await db.getStages(raceId: 1).get()).first;
Expand Down

0 comments on commit 393c48c

Please sign in to comment.