826e420423
A native foreground service keeps an authenticated websocket to the connected server (handed over by the app on every connect), subscribes with a replay cursor, shows each notification with kind-based channels and grouping, opens pipelines:// links on tap, and clears taps, dismissals and cross-device clears. It starts at boot and app launch, backs off and follows network changes. Settings gains the delivery switch, status, notification and battery-exemption actions, and the server's optional ntfy_enabled toggle.
83 lines
2.7 KiB
Dart
83 lines
2.7 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
|
import 'package:pipelines_app/features/notification_service/notification_service_bridge.dart';
|
|
import 'package:pipelines_app/features/notification_service/notification_service_handoff.dart';
|
|
|
|
import '../settings/fake_channel.dart';
|
|
import 'fake_notification_service.dart';
|
|
|
|
void main() {
|
|
test('each connection hands the proven server to the service', () async {
|
|
final channels = <FakeChannel>[];
|
|
final client = PipelinesClient(
|
|
channelFactory: (uri) {
|
|
final channel = FakeChannel(uri)..markReady();
|
|
channels.add(channel);
|
|
return channel;
|
|
},
|
|
);
|
|
final service = FakeNotificationService();
|
|
final handoff = NotificationServiceHandoff(
|
|
bridge: service,
|
|
client: client,
|
|
serverId: 'home',
|
|
headersFor: (uri) => uri.host == 'b'
|
|
? {'Cookie': 'pipelines_session=abc'}
|
|
: const <String, String>{},
|
|
);
|
|
// The app starts the service at launch when it is enabled.
|
|
expect(service.calls.single.$1, 'start');
|
|
|
|
await client.connectAny([
|
|
Uri.parse('wss://b:8443/connect'),
|
|
Uri.parse('ws://a:8081/connect'),
|
|
]);
|
|
await pumpEventQueue();
|
|
final configure = service.calls.last;
|
|
expect(configure.$1, 'configure');
|
|
expect(configure.$2, {
|
|
'serverId': 'home',
|
|
'endpoints': ['wss://b:8443/connect', 'ws://a:8081/connect'],
|
|
'cookie': 'pipelines_session=abc',
|
|
});
|
|
|
|
handoff.dispose();
|
|
await client.dispose();
|
|
});
|
|
|
|
test('without a server id the connected address names the server', () async {
|
|
final client = PipelinesClient(
|
|
channelFactory: (uri) => FakeChannel(uri)..markReady(),
|
|
);
|
|
final service = FakeNotificationService();
|
|
final handoff = NotificationServiceHandoff(
|
|
bridge: service,
|
|
client: client,
|
|
serverId: null,
|
|
headersFor: (_) => const <String, String>{},
|
|
);
|
|
await client.connect(Uri.parse('ws://a:8081/connect'));
|
|
await pumpEventQueue();
|
|
expect(service.calls.last.$2['serverId'], 'ws://a:8081/connect');
|
|
expect(service.calls.last.$2['cookie'], '');
|
|
handoff.dispose();
|
|
await client.dispose();
|
|
});
|
|
|
|
test('an unsupported platform is never called', () async {
|
|
final client = PipelinesClient(
|
|
channelFactory: (uri) => FakeChannel(uri)..markReady(),
|
|
);
|
|
final handoff = NotificationServiceHandoff(
|
|
bridge: const UnsupportedNotificationServiceBridge(),
|
|
client: client,
|
|
serverId: 'home',
|
|
headersFor: (_) => throw StateError('must not read credentials'),
|
|
);
|
|
await client.connect(Uri.parse('ws://a:8081/connect'));
|
|
await pumpEventQueue();
|
|
handoff.dispose();
|
|
await client.dispose();
|
|
});
|
|
}
|