Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
shroff committed Jan 12, 2025
1 parent 44092e4 commit 0c2c752
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions drift/test/engines/interceptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ void main() {
await database.users.delete().go();
expect(events, ['insert', 'update', 'delete']);
});

test('calls interceptor methods in runWithInterceptor', () async {
final interceptor = EmittingInterceptor();
final events = <String>[];
interceptor.events.stream.listen(events.add);

final database = TodoDb(testInMemoryDatabase());
expect(await database.categories.select().get(), isEmpty);

await database.runWithInterceptor(
() => database.batch((batch) {
batch.insert(database.categories,
CategoriesCompanion.insert(description: 'from batch'));
}),
interceptor: interceptor,
);
expect(events, ['begin', 'batched', 'commit']);
events.clear();

await database.users.insertOne(
UsersCompanion.insert(name: 'Simon B', profilePicture: Uint8List(0)));
await database.runWithInterceptor(
() =>
database.users.update().write(UsersCompanion(isAwesome: Value(true))),
interceptor: interceptor,
);
await database.users.delete().go();
expect(events, ['update']);
});
}

class EmittingInterceptor extends QueryInterceptor {
Expand Down

0 comments on commit 0c2c752

Please sign in to comment.