@@ -6,6 +6,7 @@ import 'package:http/http.dart' as http;
66import 'package:test/scaffolding.dart' ;
77import 'package:zulip/api/core.dart' ;
88import 'package:zulip/api/exception.dart' ;
9+ import 'package:zulip/model/binding.dart' ;
910import 'package:zulip/model/localizations.dart' ;
1011
1112import '../model/binding.dart' ;
@@ -320,6 +321,41 @@ void main() {
320321 check (st.toString ()).contains ("distinctivelyNamedFromJson" );
321322 }
322323 });
324+
325+ group ('ApiConnection user-agent' , () {
326+ Future <void > checkUserAgent (String expectedUserAgent) async {
327+ return FakeApiConnection .with_ (account: eg.selfAccount,
328+ userAgentHeader: testBinding.userAgentHeader (),
329+ (connection) async {
330+ connection.prepare (json: {});
331+ await connection.get (kExampleRouteName, (json) => json, 'example/route' , null );
332+ check (connection.lastRequest! ).isA< http.Request > ()
333+ .headers.deepEquals ({
334+ ...authHeader (email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey),
335+ ...{'User-Agent' : expectedUserAgent},
336+ });
337+ });
338+ }
339+
340+ final packageInfo = PackageInfo (version: '0.0.1' , buildNumber: '1' );
341+
342+ final testCases = [
343+ ('ZulipFlutter/0.0.1+1 (Android 14)' , AndroidDeviceInfo (release: '14' , sdkInt: 34 ), packageInfo),
344+ ('ZulipFlutter/0.0.1+1 (iOS 17.4)' , IosDeviceInfo (systemVersion: '17.4' ), packageInfo),
345+ ('ZulipFlutter/0.0.1+1 (macOS 14.5.0)' , MacOsDeviceInfo (majorVersion: 14 , minorVersion: 5 , patchVersion: 0 ), packageInfo),
346+ ('ZulipFlutter/0.0.1+1 (Windows)' , WindowsDeviceInfo (), packageInfo),
347+ ('ZulipFlutter/0.0.1+1 (Linux; Fedora Linux 40)' , LinuxDeviceInfo (name: 'Fedora Linux' , versionId: '40' ), packageInfo),
348+ ('ZulipFlutter/0.0.1+1 (Linux; Fedora Linux)' , LinuxDeviceInfo (name: 'Fedora Linux' , versionId: null ), packageInfo),
349+ ];
350+
351+ for (final (userAgent, deviceInfo, pacakgeInfo) in testCases) {
352+ test ('matches $userAgent ' , () async {
353+ testBinding.deviceInfoResult = deviceInfo;
354+ testBinding.packageInfoResult = pacakgeInfo;
355+ await checkUserAgent (userAgent);
356+ });
357+ }
358+ });
323359}
324360
325361class DistinctiveError extends Error {
0 commit comments