|
| 1 | +import 'package:pub_api_client/src/endpoints.dart'; |
| 2 | +import 'package:pub_api_client/src/models/search_order.dart'; |
| 3 | +import 'package:test/test.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + group('Endpoint', () { |
| 7 | + late Endpoint endpoint; |
| 8 | + |
| 9 | + setUp(() { |
| 10 | + endpoint = Endpoint(null); |
| 11 | + }); |
| 12 | + |
| 13 | + test('constructor uses default base URL when null is provided', () { |
| 14 | + expect(endpoint.baseUrl, equals(Endpoint.defaultBaseUrl)); |
| 15 | + }); |
| 16 | + |
| 17 | + test('constructor uses custom base URL when provided', () { |
| 18 | + final customEndpoint = Endpoint('https://custom.pub.dev'); |
| 19 | + expect(customEndpoint.baseUrl, equals('https://custom.pub.dev')); |
| 20 | + }); |
| 21 | + |
| 22 | + test('packageInfo returns correct URL', () { |
| 23 | + expect(endpoint.packageInfo('flutter'), |
| 24 | + equals('${Endpoint.defaultBaseUrl}/api/packages/flutter')); |
| 25 | + }); |
| 26 | + |
| 27 | + test('packageScore returns correct URL', () { |
| 28 | + expect(endpoint.packageScore('dart'), |
| 29 | + equals('${Endpoint.defaultBaseUrl}/api/packages/dart/score')); |
| 30 | + }); |
| 31 | + |
| 32 | + test('packageMetrics returns correct URL', () { |
| 33 | + expect(endpoint.packageMetrics('http'), |
| 34 | + equals('${Endpoint.defaultBaseUrl}/api/packages/http/metrics')); |
| 35 | + }); |
| 36 | + |
| 37 | + test('packageOptions returns correct URL', () { |
| 38 | + expect(endpoint.packageOptions('test'), |
| 39 | + equals('${Endpoint.defaultBaseUrl}/api/packages/test/options')); |
| 40 | + }); |
| 41 | + |
| 42 | + test('packagePublisher returns correct URL', () { |
| 43 | + expect(endpoint.packagePublisher('bloc'), |
| 44 | + equals('${Endpoint.defaultBaseUrl}/api/packages/bloc/publisher')); |
| 45 | + }); |
| 46 | + |
| 47 | + test('packageDocumentation returns correct URL', () { |
| 48 | + expect(endpoint.packageDocumentation('provider'), |
| 49 | + equals('${Endpoint.defaultBaseUrl}/api/documentation/provider')); |
| 50 | + }); |
| 51 | + |
| 52 | + test('packageVersions returns correct URL', () { |
| 53 | + expect(endpoint.packageVersions('rxdart'), |
| 54 | + equals('${Endpoint.defaultBaseUrl}/packages/rxdart.json')); |
| 55 | + }); |
| 56 | + |
| 57 | + test('packageVersionInfo returns correct URL', () { |
| 58 | + expect( |
| 59 | + endpoint.packageVersionInfo('get_it', '1.0.0'), |
| 60 | + equals( |
| 61 | + '${Endpoint.defaultBaseUrl}/api/packages/get_it/versions/1.0.0')); |
| 62 | + }); |
| 63 | + |
| 64 | + test('packageNames returns correct URL', () { |
| 65 | + expect(endpoint.packageNames, |
| 66 | + equals('${Endpoint.defaultBaseUrl}/api/package-names')); |
| 67 | + }); |
| 68 | + |
| 69 | + test('likePackage returns correct URL', () { |
| 70 | + expect(endpoint.likePackage('dio'), |
| 71 | + equals('${Endpoint.defaultBaseUrl}/api/account/likes/dio')); |
| 72 | + }); |
| 73 | + |
| 74 | + test('likedPackages returns correct URL', () { |
| 75 | + expect(endpoint.likedPackages, |
| 76 | + equals('${Endpoint.defaultBaseUrl}/api/account/likes')); |
| 77 | + }); |
| 78 | + |
| 79 | + test('search returns correct URL with parameters', () { |
| 80 | + expect( |
| 81 | + endpoint.search('flutter', 1, SearchOrder.top), |
| 82 | + equals( |
| 83 | + '${Endpoint.defaultBaseUrl}/api/search?q=flutter&page=1&sort=top')); |
| 84 | + }); |
| 85 | + |
| 86 | + test('nextPage returns correct URL with custom base URL', () { |
| 87 | + final customEndpoint = Endpoint('https://custom.pub.dev'); |
| 88 | + expect( |
| 89 | + customEndpoint |
| 90 | + .nextPage('https://pub.dev/api/search?q=flutter&page=2'), |
| 91 | + equals('https://custom.pub.dev/api/search?q=flutter&page=2')); |
| 92 | + }); |
| 93 | + }); |
| 94 | +} |
0 commit comments