diff --git a/lib/utils/iap/ms_store_collections_sync.dart b/lib/utils/iap/ms_store_collections_sync.dart index d400313a..3614116f 100644 --- a/lib/utils/iap/ms_store_collections_sync.dart +++ b/lib/utils/iap/ms_store_collections_sync.dart @@ -46,6 +46,9 @@ class MsStoreCollectionsSync { serviceTicket: ticket.serviceTicket, publisherUserId: ticket.publisherUserId, ); + // The Store answers an empty key instead of an error when it can't + // make one (e.g. an unpackaged build). + if (key.isEmpty) throw StateError('Microsoft Store returned no collections ID key'); final base = await submitKey(key); if (base != 'none') await writeFlag(_flagFor(userId), base); await refreshEntitlements(); diff --git a/test/utils/iap/ms_store_collections_sync_test.dart b/test/utils/iap/ms_store_collections_sync_test.dart index dd1074ef..cc6c6a1c 100644 --- a/test/utils/iap/ms_store_collections_sync_test.dart +++ b/test/utils/iap/ms_store_collections_sync_test.dart @@ -74,4 +74,24 @@ void main() { await sync.sync(); expect(errors.single, isA()); }); + + test('an empty Store key (unpackaged build, Store unavailable) is never sent', () async { + final errors = []; + final sync = MsStoreCollectionsSync( + currentUserId: () => 'user-1', + requestTicket: () async => (serviceTicket: 'T', publisherUserId: 'user-1'), + collectionsIdKey: ({required serviceTicket, required publisherUserId}) async => '', + submitKey: (_) async { + calls.add('sync'); + return 'active'; + }, + refreshEntitlements: () async {}, + readFlag: (_) async => null, + writeFlag: (_, _) async {}, + onError: (e, s) => errors.add(e), + ); + await sync.sync(); + expect(calls, isEmpty); + expect(errors.single, isA()); + }); }