feat(review): request a store review after a 3-star win, once
Adds an in-app review prompt gated by ReviewPromptPolicy: only after a 3-star stage win, once the player has cleared >=5 stages, at most once ever (persisted reviewRequested flag). ReviewService swallows all failures and only burns the one-shot when the store actually shows the sheet, so an unavailable store retries on a later win. StoreReviewer wraps in_app_review behind a Reviewer seam so unit tests skip platform channels. 13 new tests; full suite 194 green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import 'package:block_seasons/data/save_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
Future<SaveRepository> freshRepo() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
return SaveRepository(await SharedPreferences.getInstance());
|
||||
}
|
||||
|
||||
test('reviewRequested starts false', () async {
|
||||
final repo = await freshRepo();
|
||||
expect(repo.reviewRequested, isFalse);
|
||||
});
|
||||
|
||||
test('markReviewRequested flips the flag and persists across reload', () async {
|
||||
final repo = await freshRepo();
|
||||
await repo.markReviewRequested();
|
||||
expect(repo.reviewRequested, isTrue);
|
||||
|
||||
// A fresh repository over the same prefs must see the saved flag.
|
||||
final reloaded = SaveRepository(await SharedPreferences.getInstance());
|
||||
expect(reloaded.reviewRequested, isTrue);
|
||||
});
|
||||
|
||||
test('stagesClearedCount counts distinct stages cleared with >=1 star',
|
||||
() async {
|
||||
final repo = await freshRepo();
|
||||
expect(repo.stagesClearedCount, 0);
|
||||
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's1', stars: 1, score: 100);
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's2', stars: 3, score: 300);
|
||||
// Replaying the same stage must not double-count.
|
||||
await repo.recordResult(
|
||||
seasonId: 'season_001', stageId: 's1', stars: 2, score: 500);
|
||||
|
||||
expect(repo.stagesClearedCount, 2);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user