Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add integration test for transaction rollback #346

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions floor/test/integration/database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ void main() {
expect(actual, equals(newPersons));
});

test('transaction rollback on failure', () async {
final persons = [Person(1, 'Simon'), Person(2, 'Frank')];
await personDao.insertPersons(persons);

final newPersons = [Person(3, 'Paul'), Person(3, 'Karl')];

//should fail and trigger rollback because ids are the same
try {
await personDao.replacePersons(newPersons);
} catch (sfe) {
// the type SqfliteFfiException is not in scope, so we have to do it this way
expect(sfe.runtimeType.toString(), equals('SqfliteFfiException'));
}

final actual = await personDao.findAllPersons();
expect(actual, equals(persons));
});

test('Reactivity is retained when using transactions', () async {
final persons = [Person(1, 'Simon'), Person(2, 'Frank')];
await personDao.insertPersons(persons);
Expand Down