Skip to content

Commit

Permalink
fix(firestore, web): Propagate FirebaseException properly, fix `mer…
Browse files Browse the repository at this point in the history
…geFields` bug, fix `bytesLoaded` different type under different conditions (#12334)
  • Loading branch information
russellwheatley committed Feb 16, 2024
1 parent c42b57c commit fdde75b
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 126 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ jobs:
runs-on: macos-latest
timeout-minutes: 15
strategy:
# Temp measure for testing web tests. Please remove as soon as e2e tests are stable.
fail-fast: false
matrix:
working_directory:
['tests', 'packages/cloud_firestore/cloud_firestore/example']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ bool _testException(Object? objectException) {
final exception = objectException! as core_interop.JSError;
// ignore: unnecessary_cast
final message = exception.message as String;
return message.contains('Firebase');
// Firestore web does not contain `Firebase` in the message so we check the exception itself.
return message.contains('Firebase') ||
exception.toString().contains('FirebaseError');
}

/// Transforms internal errors in something more readable for end-users.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ void runDocumentReferenceTests() {
fail('Should have thrown a [FirebaseException]');
});
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);

group('DocumentReference.delete()', () {
Expand Down Expand Up @@ -255,9 +253,7 @@ void runDocumentReferenceTests() {
return;
}
fail('Should have thrown a [FirebaseException]');
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
},
skip: kIsWeb,
);
});

Expand Down Expand Up @@ -320,7 +316,6 @@ void runDocumentReferenceTests() {
equals({'foo': 'bar', 'bar': 456, 'baz': 'foo'}),
);
},
skip: kIsWeb,
);

testWidgets(
Expand All @@ -340,9 +335,7 @@ void runDocumentReferenceTests() {
return;
}
fail('Should have thrown a [FirebaseException]');
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
},
skip: kIsWeb,
);

testWidgets('set and return all possible datatypes', (_) async {
Expand Down Expand Up @@ -513,8 +506,6 @@ void runDocumentReferenceTests() {
);
}
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ void runLoadBundleTests() {
.having((e) => e.code, 'code', 'load-bundle-error'),
),
);
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
},
skip: kIsWeb,
);

testWidgets(
Expand Down Expand Up @@ -181,16 +179,13 @@ void runLoadBundleTests() {
'wrong-name',
options: const GetOptions(source: Source.cache),
),
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
// expect(error, isA<FirebaseException>());
throwsA(
isA<FirebaseException>()
.having((e) => e.code, 'code', 'non-existent-named-query'),
),
);
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb || defaultTargetPlatform == TargetPlatform.windows,
skip: defaultTargetPlatform == TargetPlatform.windows,
);
});

Expand Down Expand Up @@ -241,8 +236,7 @@ void runLoadBundleTests() {
),
);
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb || defaultTargetPlatform == TargetPlatform.windows,
skip: defaultTargetPlatform == TargetPlatform.windows,
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'dart:math';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

void runQueryTests() {
Expand Down Expand Up @@ -210,8 +209,6 @@ void runQueryTests() {
}
fail('Should have thrown a [FirebaseException]');
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);

testWidgets(
Expand All @@ -234,8 +231,6 @@ void runQueryTests() {
);
}
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);
});

Expand Down Expand Up @@ -378,9 +373,7 @@ void runQueryTests() {
}

fail('Should have thrown a [FirebaseException]');
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
},
skip: kIsWeb,
);
});

Expand Down Expand Up @@ -2221,8 +2214,8 @@ void runQueryTests() {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('multiple-conjunctive-queries');

try {
await collection
await expectLater(
collection
.where(
Filter.and(
Filter('rating1', isEqualTo: 3.8),
Expand Down Expand Up @@ -2259,22 +2252,13 @@ void runQueryTests() {
),
)
.orderBy('rating1', descending: true)
.get();
} catch (e) {
expect(
(e as FirebaseException)
.message!
.contains('Client specified an invalid argument.') ||
e.message!.contains(
'An error occurred while parsing query arguments',
),
isTrue,
);
expect(e, isA<FirebaseException>());
}
.get(),
throwsA(
isA<FirebaseException>()
.having((e) => e.code, 'code', 'invalid-argument'),
),
);
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);

testWidgets('allow multiple disjunctive queries', (_) async {
Expand Down Expand Up @@ -2398,8 +2382,8 @@ void runQueryTests() {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('multiple-disjunctive-queries');

try {
await collection
await expectLater(
collection
.where(
Filter.or(
Filter('rating', isEqualTo: 3.8),
Expand Down Expand Up @@ -2442,22 +2426,13 @@ void runQueryTests() {
),
)
.orderBy('rating', descending: true)
.get();
} catch (e) {
expect(
(e as FirebaseException)
.message!
.contains('Client specified an invalid argument.') ||
e.message!.contains(
'An error occurred while parsing query arguments',
),
isTrue,
);
expect(e, isA<FirebaseException>());
}
.get(),
throwsA(
isA<FirebaseException>()
.having((e) => e.code, 'code', 'invalid-argument'),
),
);
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);

testWidgets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ void runSecondAppTests() {
),
);
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb || defaultTargetPlatform == TargetPlatform.windows,
skip: defaultTargetPlatform == TargetPlatform.windows,
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ void runSecondDatabaseTests() {
);
QuerySnapshot<Map<String, dynamic>> snapshot = await collection.get();

await Future.forEach(snapshot.docs,
(QueryDocumentSnapshot<Map<String, dynamic>> documentSnapshot) {
List<Future> deleteFutures = snapshot.docs.map((documentSnapshot) {
return documentSnapshot.reference.delete();
});
}).toList();

await Future.wait(deleteFutures);
return collection;
}

Expand Down Expand Up @@ -185,8 +186,6 @@ void runSecondDatabaseTests() {
}
fail('Should have thrown a [FirebaseException]');
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);
});

Expand Down Expand Up @@ -332,9 +331,7 @@ void runSecondDatabaseTests() {
}

fail('Should have thrown a [FirebaseException]');
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
},
skip: kIsWeb,
);
});

Expand Down Expand Up @@ -1772,8 +1769,8 @@ void runSecondDatabaseTests() {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('multiple-conjunctive-queries');

try {
await collection
await expectLater(
collection
.where(
Filter.and(
Filter('rating1', isEqualTo: 3.8),
Expand Down Expand Up @@ -1810,22 +1807,13 @@ void runSecondDatabaseTests() {
),
)
.orderBy('rating1', descending: true)
.get();
} catch (e) {
expect(
(e as FirebaseException)
.message!
.contains('Client specified an invalid argument.') ||
e.message!.contains(
'An error occurred while parsing query arguments',
),
isTrue,
);
expect(e, isA<FirebaseException>());
}
.get(),
throwsA(
isA<FirebaseException>()
.having((e) => e.code, 'code', 'invalid-argument'),
),
);
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);

testWidgets(
Expand All @@ -1834,8 +1822,8 @@ void runSecondDatabaseTests() {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('multiple-disjunctive-queries');

try {
await collection
await expectLater(
collection
.where(
Filter.or(
Filter('rating', isEqualTo: 3.8),
Expand Down Expand Up @@ -1878,22 +1866,13 @@ void runSecondDatabaseTests() {
),
)
.orderBy('rating', descending: true)
.get();
} catch (e) {
expect(
(e as FirebaseException)
.message!
.contains('Client specified an invalid argument.') ||
e.message!.contains(
'An error occurred while parsing query arguments',
),
isTrue,
);
expect(e, isA<FirebaseException>());
}
.get(),
throwsA(
isA<FirebaseException>()
.having((e) => e.code, 'code', 'invalid-argument'),
),
);
},
// This will fail until this is resolved: https://github.com/dart-lang/sdk/issues/52572
skip: kIsWeb,
);

testWidgets('isEqualTo filter', (_) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

void runWriteBatchTests() {
Expand Down Expand Up @@ -100,14 +99,11 @@ void runWriteBatchTests() {
batch.update(doc3, <String, dynamic>{'bar': 'ben'});
batch.set(doc4, <String, dynamic>{'bar': 'ben'}, SetOptions(merge: true));

// TODO(ehesp): firebase-dart does not support mergeFields
if (!kIsWeb) {
batch.set(
doc5,
<String, dynamic>{'bar': 'ben'},
SetOptions(mergeFields: ['bar']),
);
}
batch.set(
doc5,
<String, dynamic>{'bar': 'ben'},
SetOptions(mergeFields: ['bar']),
);

await batch.commit();

Expand All @@ -127,14 +123,11 @@ void runWriteBatchTests() {
snapshot.docs.firstWhere((doc) => doc.id == 'doc4').data(),
equals(<String, dynamic>{'foo': 'bar', 'bar': 'ben'}),
);
// ignore: todo
// TODO(ehesp): firebase-dart does not support mergeFields
if (!kIsWeb) {
expect(
snapshot.docs.firstWhere((doc) => doc.id == 'doc5').data(),
equals(<String, dynamic>{'foo': 'bar', 'bar': 'ben'}),
);
}

expect(
snapshot.docs.firstWhere((doc) => doc.id == 'doc5').data(),
equals(<String, dynamic>{'foo': 'bar', 'bar': 'ben'}),
);
});
});
}

0 comments on commit fdde75b

Please sign in to comment.