|  | 
|  | 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 | +  group('Version', () { | 
|  | 10 | +    test('extracts current version from yaml', () { | 
|  | 11 | +      final path = '${Directory.current.path}/test/fixtures/fake_spec.yaml'; | 
|  | 12 | + | 
|  | 13 | +      final version = Version.current(path); | 
|  | 14 | + | 
|  | 15 | +      expect(version, equals('0.9.1')); | 
|  | 16 | +    }); | 
|  | 17 | + | 
|  | 18 | +    test("responds with invalid when can't read file", () { | 
|  | 19 | +      final path = '${Directory.current.path}/test/fixtures/invalid_spec.yaml'; | 
|  | 20 | + | 
|  | 21 | +      final version = Version.current(path); | 
|  | 22 | + | 
|  | 23 | +      expect(version, equals('invalid')); | 
|  | 24 | +    }); | 
|  | 25 | + | 
|  | 26 | +    test('gets current package version', () { | 
|  | 27 | +      final path = '${Directory.current.path}/pubspec.yaml'; | 
|  | 28 | +      String pubspec = new File(path).readAsStringSync(); | 
|  | 29 | + | 
|  | 30 | +      final version = Version.current(path); | 
|  | 31 | + | 
|  | 32 | +      expect(pubspec, contains(version)); | 
|  | 33 | +    }); | 
|  | 34 | +  }); | 
|  | 35 | + | 
|  | 36 | +  group('Analytics', () { | 
|  | 37 | +    setUpClient(); | 
|  | 38 | + | 
|  | 39 | +    test('sends the User-Agent header in every call', () { | 
|  | 40 | +      final headers = client.http.headers(); | 
|  | 41 | + | 
|  | 42 | +      expect(headers.keys, contains('User-Agent')); | 
|  | 43 | +      expect(headers['User-Agent'], isNotNull); | 
|  | 44 | +    }); | 
|  | 45 | + | 
|  | 46 | +    test('has current version from pubspec.yaml', () { | 
|  | 47 | +      final headers = client.http.headers(); | 
|  | 48 | + | 
|  | 49 | +      expect(headers['User-Agent'], equals(Version.qualifiedVersion)); | 
|  | 50 | +    }); | 
|  | 51 | +  }); | 
|  | 52 | +} | 
0 commit comments