From ae1679e8a43a89284427c86cf7faca1d28bab212 Mon Sep 17 00:00:00 2001 From: mqus <8398165+mqus@users.noreply.github.com> Date: Thu, 4 Jun 2020 15:35:38 +0200 Subject: [PATCH] add integration test for transaction rollback (#346) * add integration test for transaction rollback --- floor/test/integration/database_test.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/floor/test/integration/database_test.dart b/floor/test/integration/database_test.dart index b7f017d2..420a7a25 100644 --- a/floor/test/integration/database_test.dart +++ b/floor/test/integration/database_test.dart @@ -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);