Skip to content

Commit 4dd8a9a

Browse files
committed
Add batch API
1 parent 1e1ec45 commit 4dd8a9a

File tree

11 files changed

+1232
-0
lines changed

11 files changed

+1232
-0
lines changed

packages/cloud_firestore_odm/example/integration_test/document_reference_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,50 @@ void main() {
5050
);
5151
});
5252

53+
test('batch', () async {
54+
final collection = await initializeTest(MovieCollectionReference());
55+
56+
const movieToUpdate = '123';
57+
const movieToSet = '456';
58+
const movieToDelete = '789';
59+
60+
await collection.doc(movieToUpdate).set(createMovie(title: 'title1'));
61+
await collection.doc(movieToSet).set(createMovie(title: 'title2'));
62+
await collection.doc(movieToDelete).set(createMovie(title: 'title3'));
63+
64+
expect(
65+
await Future.wait([
66+
collection.doc(movieToUpdate).get().then((e) => e.exists),
67+
collection.doc(movieToSet).get().then((e) => e.exists),
68+
collection.doc(movieToDelete).get().then((e) => e.exists),
69+
]),
70+
[true, true, true],
71+
);
72+
73+
const updatedTitle = 'updatedTitle';
74+
const newTitle = 'newTitle';
75+
final newMovie = createMovie(title: newTitle);
76+
77+
final batch = FirebaseFirestore.instance.batch();
78+
collection.doc(movieToUpdate).batchUpdate(batch, title: updatedTitle);
79+
collection.doc(movieToSet).batchSet(batch, newMovie);
80+
collection.doc(movieToDelete).batchDelete(batch);
81+
await batch.commit();
82+
83+
expect(
84+
await Future.wait([
85+
collection.doc(movieToUpdate).get().then((e) => e.data?.title),
86+
collection.doc(movieToSet).get().then((e) => e.data),
87+
collection.doc(movieToDelete).get().then((e) => e.exists),
88+
]),
89+
[
90+
updatedTitle,
91+
isA<Movie>().having((e) => e.title, newTitle, newTitle),
92+
false,
93+
],
94+
);
95+
});
96+
5397
test('delete', () async {
5498
final collection = await initializeTest(MovieCollectionReference());
5599

packages/cloud_firestore_odm/example/lib/integration.g.dart

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cloud_firestore_odm/example/lib/integration/enums.g.dart

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cloud_firestore_odm/example/lib/integration/freezed.g.dart

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cloud_firestore_odm/example/lib/integration/named_query.g.dart

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)