Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Adding null-safe handling for Transaction.get in cloud_firestore (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
killermonk authored and mravn-google committed May 14, 2018
1 parent 21f9908 commit 576522c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -12,3 +12,4 @@ Pol Batlló <pol.batllo@gmail.com>
Anatoly Pulyaevskiy
Stefano Rodriguez <hlsroddy@gmail.com>
Salvatore Giordano <salvatoregiordanoo@gmail.com>
Brian Armstrong <brian@flutter.institute>
2 changes: 1 addition & 1 deletion packages/cloud_firestore/lib/src/transaction.dart
Expand Up @@ -22,7 +22,7 @@ class Transaction {
});
if (result != null) {
return new DocumentSnapshot._(documentReference.path,
result['data'].cast<String, dynamic>(), Firestore.instance);
result['data']?.cast<String, dynamic>(), Firestore.instance);
} else {
return null;
}
Expand Down
26 changes: 22 additions & 4 deletions packages/cloud_firestore/test/cloud_firestore_test.dart
Expand Up @@ -113,10 +113,15 @@ void main() {
case 'Firestore#runTransaction':
return <String, dynamic>{'1': 3};
case 'Transaction#get':
return <String, dynamic>{
'path': 'foo/bar',
'data': <String, dynamic>{'key1': 'val1'}
};
if (methodCall.arguments['path'] == 'foo/bar') {
return <String, dynamic>{
'path': 'foo/bar',
'data': <String, dynamic>{'key1': 'val1'}
};
} else if (methodCall.arguments['path'] == 'foo/notExists') {
return <String, dynamic>{'path': 'foo/notExists', 'data': null};
}
throw new PlatformException(code: 'UNKNOWN_PATH');
case 'Transaction#set':
return null;
case 'Transaction#update':
Expand Down Expand Up @@ -167,6 +172,19 @@ void main() {
]);
});

test('get notExists', () async {
final DocumentReference documentReference =
firestore.document('foo/notExists');
await transaction.get(documentReference);
expect(log, <Matcher>[
isMethodCall('Transaction#get', arguments: <String, dynamic>{
'app': app.name,
'transactionId': 0,
'path': documentReference.path
})
]);
});

test('delete', () async {
final DocumentReference documentReference =
firestore.document('foo/bar');
Expand Down

0 comments on commit 576522c

Please sign in to comment.