scenarioSendOnline function

Future<void> scenarioSendOnline(
  1. FakeServer server,
  2. WorldSeed w,
  3. ScenarioClient client
)

04 16.1: a message sent online; its echo confirms the outbox entry while the response is still on its way (the fake holds it), and exactly one message exists on both sides.

Implementation

Future<void> scenarioSendOnline(
  FakeServer server,
  WorldSeed w,
  ScenarioClient client,
) async {
  await client.start();
  server.faults.delay(const Duration(seconds: 2), operationId: 'createMessage');
  final id = await client.send(w.releaseNotes, 'Hello Sam');
  await waitFor(
    'the echo of $id',
    () async => (await _withId(client, w.releaseNotes, id)).isNotEmpty,
  );
  await waitFor(
    'the confirmed outbox entry',
    () async => (await client.outbox()).isEmpty,
  );
  _check(
    server.requestsOf('createMessage').isEmpty,
    'the echo, not the response, confirmed the entry: '
    '${[for (final r in server.requestsOf('createMessage')) r.status]}',
  );
  await waitFor(
    'the delayed response',
    () => server.requestsOf('createMessage').length == 1,
  );
  _check(
    server.requestsOf('createMessage').single.status == 201,
    'the response was 201',
  );
  _check(
    (await _withId(client, w.releaseNotes, id)).length == 1,
    'exactly one local message',
  );
  _check(
    server.world
            .messagesOf(w.releaseNotes)
            .where((m) => m['client_msg_id'] == id)
            .length ==
        1,
    'exactly one message on the server',
  );
  _contract(server);
}