feat(app,learn,todo): the operator's "This instance" card, screen and badge (ADR 0021, step 1)
Whoever operates the instance approves, refuses and suspends accounts
and names other operators in the app (D21 to D24, D34):
- halkyon_app: InstanceOperatorRepository on
ServerpodInstanceOperatorGateway (the module's instanceOperator
endpoint; refusals as OperatorFailed: notFound, isOperator,
lastOperator, notAllowed for 401 and 403, failed), in AppDependencies.
OperatingCubit counts the accounts that wait: asked as the person's
app opens, after every change, and every 5 minutes only while they
operate the instance, so nobody else's app keeps asking.
InstanceOperatorCard (or its tiles) and WaitingAccountsBadge show
nothing at all for anyone else. InstanceOperatorScreen, laid out as
Settings: the accounts that wait, each showing its four words to read
out before Approve (D33), Refuse for new ones after asking; who
operates, Take back after asking, the last always kept; Name an
operator by handle; Find an account by the start of its handle, with
Suspend after asking and Name as operator. English and German texts
("Admin" as the role word in German).
- Learn: the card right after the Sync card in Settings, which the
cogs' count leads to as their dot leads to Sync; the count on the
Settings cogs of Home and Profile.
- Todo: the tiles in the account sheet and the count on its button.
Todo's server is a member, whose `operating()` is always null, so
nothing shows there until it holds the register.
Tests: the gateway's mapping, the repository, both cubits with their
denials, the card, the badge and the screen; Learn's Settings shows the
card and the count to an operator and neither to anyone else.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
7ac715cd97
commit
31b9c17850
2 changed files with 2999 additions and 28 deletions
|
|
@ -0,0 +1,182 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
|
||||
/// The operator's screen (Halkyon Learn's ADR 0021, D21 to D24): the
|
||||
/// accounts that wait, who operates, accounts found by handle, and each
|
||||
/// action one at a time.
|
||||
void main() {
|
||||
late FakeInstanceOperatorGateway gateway;
|
||||
late InstanceOperatorCubit cubit;
|
||||
|
||||
final anna = OperatedAccount(
|
||||
id: 'anna',
|
||||
handle: 'anna',
|
||||
since: DateTime.utc(2026, 10),
|
||||
isOperator: true,
|
||||
);
|
||||
final ben = OperatedAccount(
|
||||
id: 'ben',
|
||||
handle: 'ben',
|
||||
since: DateTime.utc(2026, 10, 24),
|
||||
waitingSince: DateTime.utc(2026, 10, 24, 9),
|
||||
words: const ['abandon', 'ability', 'able', 'about'],
|
||||
);
|
||||
final bea = OperatedAccount(
|
||||
id: 'bea',
|
||||
handle: 'bea',
|
||||
since: DateTime.utc(2026, 10, 2),
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
gateway = FakeInstanceOperatorGateway()
|
||||
..operates = true
|
||||
..add(anna)
|
||||
..add(ben)
|
||||
..add(bea);
|
||||
final operators = InstanceOperatorRepository(gateway);
|
||||
cubit = InstanceOperatorCubit(operators);
|
||||
addTearDown(() async {
|
||||
await cubit.close();
|
||||
await operators.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
test('reads who waits and who operates', () async {
|
||||
expect(cubit.state.loading, isTrue);
|
||||
await cubit.load();
|
||||
|
||||
expect(cubit.state.loading, isFalse);
|
||||
expect(cubit.state.waiting, [ben]);
|
||||
expect(cubit.state.operators, [anna]);
|
||||
});
|
||||
|
||||
test(
|
||||
"can't read them where the person doesn't operate the instance",
|
||||
() async {
|
||||
gateway.operates = false;
|
||||
await cubit.load();
|
||||
|
||||
expect(
|
||||
cubit.state.unreadable,
|
||||
const OperatorFailed(OperatorProblem.notAllowed),
|
||||
);
|
||||
expect(cubit.state.waiting, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test('approving reads the lists anew: the account no longer waits', () async {
|
||||
await cubit.load();
|
||||
await cubit.approve('ben');
|
||||
|
||||
expect(cubit.state.waiting, isEmpty);
|
||||
expect(cubit.state.busy, isNull);
|
||||
expect(cubit.state.problem, isNull);
|
||||
expect(gateway.calls, contains('approve ben'));
|
||||
});
|
||||
|
||||
test('one action at a time: another asked meanwhile is ignored', () async {
|
||||
await cubit.load();
|
||||
final approving = cubit.approve('ben');
|
||||
expect(cubit.state.busy, 'ben');
|
||||
await cubit.suspend('bea');
|
||||
await approving;
|
||||
|
||||
expect(gateway.calls, isNot(contains('suspend bea')));
|
||||
expect(cubit.state.busy, isNull);
|
||||
});
|
||||
|
||||
test('a refusal is said, nothing changed, and the next action clears '
|
||||
'it', () async {
|
||||
await cubit.load();
|
||||
await cubit.suspend('anna');
|
||||
|
||||
expect(
|
||||
cubit.state.problem,
|
||||
const OperatorFailed(OperatorProblem.isOperator),
|
||||
);
|
||||
expect(cubit.state.operators, [anna]);
|
||||
|
||||
await cubit.takeBack('anna');
|
||||
expect(
|
||||
cubit.state.problem,
|
||||
const OperatorFailed(OperatorProblem.lastOperator),
|
||||
);
|
||||
|
||||
await cubit.approve('ben');
|
||||
expect(cubit.state.problem, isNull);
|
||||
});
|
||||
|
||||
test('finds accounts as a handle is typed, and finds them anew after an '
|
||||
'action', () async {
|
||||
await cubit.load();
|
||||
await cubit.find('be');
|
||||
expect(cubit.state.found, [bea, ben]);
|
||||
|
||||
await cubit.suspend('bea');
|
||||
expect(cubit.state.query, 'be');
|
||||
expect(cubit.state.found.first.suspended, isTrue);
|
||||
expect(cubit.state.waiting.map((each) => each.id), ['ben', 'bea']);
|
||||
});
|
||||
|
||||
test('an older search answering late is dropped', () async {
|
||||
await cubit.load();
|
||||
final first = cubit.find('b');
|
||||
final second = cubit.find('an');
|
||||
await second;
|
||||
await first;
|
||||
|
||||
expect(cubit.state.query, 'an');
|
||||
expect(cubit.state.found, [anna]);
|
||||
});
|
||||
|
||||
test('naming an operator by handle names and approves them', () async {
|
||||
await cubit.load();
|
||||
final naming = cubit.appoint('@ben');
|
||||
expect(cubit.state.busy, '@ben');
|
||||
await naming;
|
||||
|
||||
expect(cubit.state.operators.map((each) => each.id), ['anna', 'ben']);
|
||||
expect(cubit.state.waiting, isEmpty);
|
||||
});
|
||||
|
||||
test('a handle nobody has is refused', () async {
|
||||
await cubit.load();
|
||||
await cubit.appoint('cleo');
|
||||
|
||||
expect(cubit.state.problem, const OperatorFailed(OperatorProblem.notFound));
|
||||
});
|
||||
|
||||
test('refusing a new account deletes it; a suspended one is never '
|
||||
'refused, only approved', () async {
|
||||
await cubit.load();
|
||||
await cubit.refuse('ben');
|
||||
expect(gateway.accounts, isNot(contains('ben')));
|
||||
|
||||
await cubit.suspend('bea');
|
||||
await cubit.refuse('bea');
|
||||
expect(cubit.state.problem, const OperatorFailed(OperatorProblem.notFound));
|
||||
expect(gateway.accounts, contains('bea'));
|
||||
});
|
||||
|
||||
test('the instance out of reach fails as such', () async {
|
||||
await cubit.load();
|
||||
gateway.failing = const OperatorFailed(OperatorProblem.failed);
|
||||
unawaited(cubit.approve('ben'));
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(cubit.state.problem, const OperatorFailed(OperatorProblem.failed));
|
||||
expect(
|
||||
cubit.state.unreadable,
|
||||
const OperatorFailed(OperatorProblem.failed),
|
||||
);
|
||||
|
||||
// Read again once it answers.
|
||||
gateway.failing = null;
|
||||
await cubit.load();
|
||||
expect(cubit.state.unreadable, isNull);
|
||||
expect(cubit.state.waiting, [ben]);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:fake_async/fake_async.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
|
||||
/// How many accounts wait, for the badge on an operator's Settings and its
|
||||
/// "This instance" card (Halkyon Learn's ADR 0021, D34).
|
||||
void main() {
|
||||
late FakeInstanceOperatorGateway gateway;
|
||||
late InstanceOperatorRepository operators;
|
||||
|
||||
OperatedAccount waiting(String id) => OperatedAccount(
|
||||
id: id,
|
||||
handle: id,
|
||||
since: DateTime.utc(2026, 10, 24),
|
||||
waitingSince: DateTime.utc(2026, 10, 24, 9),
|
||||
words: const ['abandon', 'ability', 'able', 'about'],
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
gateway = FakeInstanceOperatorGateway()
|
||||
..operates = true
|
||||
..add(waiting('ben'));
|
||||
operators = InstanceOperatorRepository(gateway);
|
||||
});
|
||||
|
||||
int operatingCalls() =>
|
||||
gateway.calls.where((call) => call == 'operating').length;
|
||||
|
||||
test('asks as it opens, every 5 minutes, and after every change made '
|
||||
'here', () {
|
||||
fakeAsync((async) {
|
||||
final cubit = OperatingCubit(operators);
|
||||
async.flushMicrotasks();
|
||||
expect(cubit.state, 1);
|
||||
|
||||
gateway.add(waiting('cleo'));
|
||||
async.elapse(const Duration(minutes: 5));
|
||||
expect(cubit.state, 2);
|
||||
|
||||
unawaited(operators.approve('ben'));
|
||||
async.flushMicrotasks();
|
||||
expect(cubit.state, 1);
|
||||
expect(operatingCalls(), 3);
|
||||
|
||||
unawaited(cubit.close());
|
||||
async.elapse(const Duration(minutes: 10));
|
||||
expect(operatingCalls(), 3);
|
||||
});
|
||||
});
|
||||
|
||||
test("is null for someone who doesn't operate the instance, whose app "
|
||||
'asks once and no more', () {
|
||||
fakeAsync((async) {
|
||||
gateway.operates = false;
|
||||
final cubit = OperatingCubit(operators);
|
||||
async.elapse(const Duration(minutes: 30));
|
||||
|
||||
expect(cubit.state, isNull);
|
||||
expect(operatingCalls(), 1);
|
||||
unawaited(cubit.close());
|
||||
});
|
||||
});
|
||||
|
||||
test('an operator whose role was taken back meanwhile sees the card '
|
||||
'go', () {
|
||||
fakeAsync((async) {
|
||||
final cubit = OperatingCubit(operators);
|
||||
async.flushMicrotasks();
|
||||
expect(cubit.state, 1);
|
||||
|
||||
gateway.failing = const OperatorFailed(OperatorProblem.notAllowed);
|
||||
async.elapse(const Duration(minutes: 5));
|
||||
expect(cubit.state, isNull);
|
||||
unawaited(cubit.close());
|
||||
});
|
||||
});
|
||||
|
||||
test('out of reach, what was known stays', () {
|
||||
fakeAsync((async) {
|
||||
final cubit = OperatingCubit(operators);
|
||||
async.flushMicrotasks();
|
||||
|
||||
gateway.failing = const OperatorFailed(OperatorProblem.failed);
|
||||
async.elapse(const Duration(minutes: 5));
|
||||
expect(cubit.state, 1);
|
||||
unawaited(cubit.close());
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue