|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:meilisearch/src/version.dart'; |
| 4 | +import 'package:test/test.dart'; |
| 5 | + |
| 6 | +import 'utils/client.dart'; |
| 7 | + |
| 8 | +void main() { |
| 9 | + final RegExp semVer = new RegExp( |
| 10 | + r"version\:.(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"); |
| 11 | + |
| 12 | + group('Version', () { |
| 13 | + test('matches with the current package version in pubspec.yaml', () { |
| 14 | + final path = '${Directory.current.path}/pubspec.yaml'; |
| 15 | + String data = new File(path).readAsStringSync(); |
| 16 | + String? version = semVer.stringMatch(data)?.replaceFirst('version: ', ''); |
| 17 | + |
| 18 | + expect(version, isNotNull); |
| 19 | + expect(Version.current, isNotNull); |
| 20 | + expect(Version.current, equals(version)); |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + group('Analytics', () { |
| 25 | + setUpClient(); |
| 26 | + |
| 27 | + test('sends the User-Agent header in every call', () { |
| 28 | + final headers = client.http.headers(); |
| 29 | + |
| 30 | + expect(headers.keys, contains('User-Agent')); |
| 31 | + expect(headers['User-Agent'], isNotNull); |
| 32 | + }); |
| 33 | + |
| 34 | + test('has current version data from Version class', () { |
| 35 | + final headers = client.http.headers(); |
| 36 | + |
| 37 | + expect(headers['User-Agent'], equals(Version.qualifiedVersion)); |
| 38 | + }); |
| 39 | + }); |
| 40 | +} |
0 commit comments