-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ignore corrupt events on disk (users might edit it on web)
- Loading branch information
Showing
3 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:wiredash/src/analytics/event_store.dart'; | ||
|
||
import '../util/flutter_error.dart'; | ||
|
||
void main() { | ||
test('ignore invalid events on disk', () async { | ||
SharedPreferences.setMockInitialValues({}); | ||
final errors = captureFlutterErrors(); | ||
final eventStore = PersistentAnalyticsEventStore( | ||
sharedPreferences: SharedPreferences.getInstance, | ||
); | ||
|
||
final prefs = await SharedPreferences.getInstance(); | ||
await prefs.setString( | ||
'io.wiredash.events.default|1234567890|abc', '{"invalid": "event"}'); | ||
final events = await eventStore.getEvents(null); | ||
|
||
errors.restoreDefaultErrorHandlers(); | ||
|
||
expect(events, hasLength(0)); | ||
// reported warning | ||
expect( | ||
errors.presentErrorText, | ||
contains( | ||
'Error when parsing event io.wiredash.events.default|1234567890|abc. Removing', | ||
), | ||
); | ||
expect( | ||
prefs.getString('io.wiredash.events.default|1234567890|abc'), | ||
isNull, | ||
reason: 'Invalid event should be removed from disk', | ||
); | ||
}); | ||
} |