Connect sign-up to Sendico Facts intake (#46)

This commit is contained in:
Stephan D committed 2026-10-15 00:55:19 +02:00
1 parent 30f0455122
commit a584c8189a
40 files changed
+1616 -35

No files matched your search

@@ -10,6 +10,43 @@ import 'package:sxchnge_auth/sxchnge_auth.dart';
void main() {
http.Response response(Map<String, Object?> data, [int status = 202]) =>
http.Response(jsonEncode({'data': data}), status);
test(
'signup distinguishes support recovery and keeps the retry key',
() async {
final keys = <String>[];
var failed = true;
final service = BackendAuthServices(
baseUri: Uri.parse('https://api.example/api/v1'),
clientId: 'web',
client: MockClient((request) async {
keys.add(jsonDecode(request.body)['idempotencyKey'] as String);
return failed
? response({'error': 'signup_attention_required'}, 503)
: response({'userId': 'user'});
}),
);
addTearDown(service.close);
const input = SignupRequest(
name: 'Ada',
email: 'ada@example.com',
password: 'password preserved',
locale: 'en',
);
await expectLater(
service.signup(input),
throwsA(
isA<AuthException>().having(
(error) => error.code,
'code',
AuthError.signupNeedsAssistance,
),
),
);
failed = false;
expect((await service.signup(input)).isSimulated, isFalse);
expect(keys[0], keys[1]);
},
);
test('signup receipt avoids duplicate delivery and subsequent resend reaches API', () async {
final paths = <String>[];
final service = BackendAuthServices(
@@ -148,6 +185,34 @@ void main() {
),
);
});
test(
'verification recovery preserves assistance instead of requesting retry',
() async {
final service = BackendAuthServices(
baseUri: Uri.parse('https://api.example/api/v1'),
clientId: 'web',
client: MockClient(
(_) async => response({'error': 'signup_attention_required'}, 503),
),
);
addTearDown(service.close);
final provider = VerificationProvider(service);
addTearDown(provider.dispose);
await provider.send(email: 'ada@example.com', locale: 'en');
expect(provider.state.status, VerificationStatus.error);
expect(provider.state.error, VerificationError.needsAssistance);
await expectLater(
service.confirm(token: 'old-token'),
throwsA(
isA<VerificationException>().having(
(e) => e.code,
'code',
VerificationError.needsAssistance,
),
),
);
},
);
test(
'resend preserves server challenge and retries the same delivery key',
() async {