From 5bb4d043a5b4f1382778c989691e35f38e4e3252 Mon Sep 17 00:00:00 2001 From: Alexander Wilde Date: Sun, 20 Nov 2022 23:44:29 +0000 Subject: [PATCH] Add tests for deleteAll --- drift/test/database/batch_test.dart | 12 ++++++++---- drift/test/database/statements/delete_test.dart | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drift/test/database/batch_test.dart b/drift/test/database/batch_test.dart index fa255a4b..dadb344b 100644 --- a/drift/test/database/batch_test.dart +++ b/drift/test/database/batch_test.dart @@ -39,7 +39,9 @@ void main() { CategoriesCompanion(id: Value(2), description: Value('new2')), ]); - b.deleteWhere(db.categories, (_) => const Constant(true)); + b.deleteWhere<$CategoriesTable, Category>( + db.categories, (tbl) => tbl.id.equals(1)); + b.deleteAll(db.categories); b.delete(db.todosTable, const TodosTableCompanion(id: Value(3))); b.update(db.users, const UsersCompanion(name: Value('new name 2'))); @@ -56,6 +58,7 @@ void main() { 'UPDATE "users" SET "name" = ?;', 'UPDATE "users" SET "name" = ? WHERE "name" = ?;', 'UPDATE "categories" SET "desc" = ?, "priority" = 0 WHERE "id" = ?;', + 'DELETE FROM "categories" WHERE "id" = ?;', 'DELETE FROM "categories" WHERE 1;', 'DELETE FROM "todos" WHERE "id" = ?;', 'some custom statement', @@ -67,10 +70,11 @@ void main() { ArgumentsForBatchedStatement(2, ['Another', 'old']), ArgumentsForBatchedStatement(3, ['new1', 1]), ArgumentsForBatchedStatement(3, ['new2', 2]), - ArgumentsForBatchedStatement(4, []), - ArgumentsForBatchedStatement(5, [3]), + ArgumentsForBatchedStatement(4, [1]), + ArgumentsForBatchedStatement(5, []), + ArgumentsForBatchedStatement(6, [3]), ArgumentsForBatchedStatement(1, ['new name 2']), - ArgumentsForBatchedStatement(6, [4]), + ArgumentsForBatchedStatement(7, [4]), ], ), ), diff --git a/drift/test/database/statements/delete_test.dart b/drift/test/database/statements/delete_test.dart index 3b9a11d2..6359e41a 100644 --- a/drift/test/database/statements/delete_test.dart +++ b/drift/test/database/statements/delete_test.dart @@ -124,5 +124,11 @@ void main() { verify( executor.runDelete('DELETE FROM "users" WHERE "id" < ?;', const [3])); }); + + test('deleteAll', () async { + await db.users.deleteAll(); + + verify(executor.runDelete('DELETE FROM "users";', const [])); + }); }); }