purchasesRoleAppTest function

Future<MatrixAppTest> purchasesRoleAppTest({
  1. bool among(
    1. MatrixApp app
    )?,
})

The test of the purchases role that the CLI keeps in its app_tests/purchases_role, for the apps with the role, whichever module provides it, that among accepts, or all of them:

  • appPurchases, over a service of purchases of the test that scripts what a provider answers, and with a controller of its own: a call made before the first start waits for it, and the start completes after it and after the purchase that its completion makes; the start waits for the access at most startWait, and a later access still becomes the value; the controller asks again when the user comes back to the app, and takes each change that the service tells of; a change of the user waits for the purchase on its way, which belongs to the user who made it; a provider without what it needs leaves the app without purchases, prints its hint once and stops nothing; and a call fails only with a PurchasesFailure, a cancel completes with false, and an answer that gives no premium access fails with notConfigured;
  • appPurchases over the service of the provider, with users of the test: the offer has at least one plan, each with an id of its own, a title, a price in a currency and periods of one unit or more; a fresh user who buys a plan has premium access as the plan gives it, which the listeners hear of once, with no other change right after it, and a restore gives; a fresh user who restores gets what the device bought; and the purchases of each user stay apart;
  • the next start, initPurchases() again, gives a user the premium access that the user bought.

The test knows only the role. It relies on the convention that the mocks of every provider keep to, as the role says, and identifies a throwaway user before its fresh users, so that none of them takes over what the user of the device bought. Its probe, probePurchases() of integration_test/purchases_role/probe.dart, only reads, for the start check on a device: the access of the app is the one that the service of the provider gives, and a provider that is not set up, or a store that does not answer, is no problem while the app shows no premium access. The test runs the probe too.

Implementation

Future<MatrixAppTest> purchasesRoleAppTest({
  bool Function(MatrixApp app)? among,
}) async =>
    MatrixAppTest(
      '${await appTestsDirectoryOf('smf_flutter_cli')}/purchases_role',
      appliesTo: (app) =>
          app.hook!.presentRoles.contains(purchasesRole) &&
          (among?.call(app) ?? true),
      roles: {purchasesRole},
      startProbe: const MatrixStartProbe(
        'integration_test/purchases_role/probe.dart',
        'probePurchases',
      ),
    );