Files
pipelines/app/test/application/server_endpoint_test.dart

62 lines
2.0 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
void main() {
test('web infers its own origin over ws at /connect', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/runs?filter=active'),
web: true,
);
expect(server.uri, Uri.parse('ws://127.0.0.1:8096/connect'));
expect(server.error, isNull);
expect(server.requiresConfiguration, isFalse);
});
test('secure web origin uses wss and the default port', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('https://pipelines.example.test/runs'),
web: true,
);
expect(server.uri, Uri.parse('wss://pipelines.example.test/connect'));
});
test('web never guesses an endpoint when the page is not HTTP(S)', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('file:///tmp/index.html'),
web: true,
);
expect(server.uri, isNull);
expect(server.error, contains('page URL'));
});
test('native requires an explicit endpoint instead of a baked host', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: false,
);
expect(server.uri, isNull);
expect(server.requiresConfiguration, isTrue);
expect(server.error, isNull);
});
test('native validates and normalizes the configured endpoint', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: false,
configured: ' ws://192.168.1.20:8081 ',
);
expect(server.uri, Uri.parse('ws://192.168.1.20:8081/connect'));
expect(server.requiresConfiguration, isFalse);
});
test('invalid native configuration reports the reason, never a fallback', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: false,
configured: 'https://pipelines.example.test',
);
expect(server.uri, isNull);
expect(server.error, contains('Unsupported scheme'));
});
}