| 1 | import 'package:flutter_test/flutter_test.dart'; |
| 2 | import 'package:localmind/core/constants/app_constants.dart'; |
| 3 | import 'package:localmind/core/models/enums.dart'; |
| 4 | import 'package:localmind/features/servers/data/models/server.dart'; |
| 5 | |
| 6 | void main() { |
| 7 | group('Server base URL & endpoints for Ollama Cloud', () { |
| 8 | Server makeCloudServer({String? apiKey}) { |
| 9 | return Server( |
| 10 | id: 'cloud-1', |
| 11 | name: 'Ollama Cloud', |
| 12 | type: ServerType.ollamaCloud, |
| 13 | host: AppConstants.ollamaCloudBaseUrl, |
| 14 | port: AppConstants.ollamaCloudDefaultPort, |
| 15 | apiKey: apiKey, |
| 16 | createdAt: DateTime.now(), |
| 17 | lastConnectedAt: DateTime.now(), |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | test('baseUrl resolves to https://ollama.com', () { |
| 22 | final server = makeCloudServer(); |
| 23 | expect(server.baseUrl, 'https://ollama.com'); |
| 24 | }); |
| 25 | |
| 26 | test('displayAddress renders as ollama.com', () { |
| 27 | final server = makeCloudServer(); |
| 28 | expect(server.displayAddress, 'ollama.com'); |
| 29 | }); |
| 30 | |
| 31 | test('chat endpoint uses /api/chat on ollama.com', () { |
| 32 | final server = makeCloudServer(); |
| 33 | expect(server.chatEndpoint, 'https://ollama.com/api/chat'); |
| 34 | }); |
| 35 | |
| 36 | test('models endpoint uses /api/tags on ollama.com', () { |
| 37 | final server = makeCloudServer(); |
| 38 | expect(server.modelsEndpoint, 'https://ollama.com/api/tags'); |
| 39 | }); |
| 40 | |
| 41 | test('running models endpoint is empty for cloud (no /api/ps)', () { |
| 42 | final server = makeCloudServer(); |
| 43 | expect(server.runningModelsEndpoint, isEmpty); |
| 44 | }); |
| 45 | |
| 46 | test('load/unload endpoints are empty for cloud', () { |
| 47 | final server = makeCloudServer(); |
| 48 | expect(server.loadModelEndpoint, isEmpty); |
| 49 | expect(server.unloadModelEndpoint, isEmpty); |
| 50 | }); |
| 51 | |
| 52 | test('api key is sent as Bearer authorization header', () { |
| 53 | final server = makeCloudServer(apiKey: 'test-key-123'); |
| 54 | expect(server.authHeaders, {'Authorization': 'Bearer test-key-123'}); |
| 55 | }); |
| 56 | |
| 57 | test('no Authorization header when api key is missing', () { |
| 58 | final server = makeCloudServer(); |
| 59 | expect(server.authHeaders, isEmpty); |
| 60 | }); |
| 61 | |
| 62 | test('isOllamaCloud and isOllamaFamily getters work', () { |
| 63 | final cloud = makeCloudServer(); |
| 64 | expect(cloud.isOllamaCloud, isTrue); |
| 65 | expect(cloud.isOllamaFamily, isTrue); |
| 66 | |
| 67 | final local = Server( |
| 68 | id: 'local-1', |
| 69 | name: 'Local', |
| 70 | type: ServerType.ollama, |
| 71 | host: 'localhost', |
| 72 | port: 11434, |
| 73 | createdAt: DateTime.now(), |
| 74 | lastConnectedAt: DateTime.now(), |
| 75 | ); |
| 76 | expect(local.isOllamaCloud, isFalse); |
| 77 | expect(local.isOllamaFamily, isTrue); |
| 78 | }); |
| 79 | }); |
| 80 | |
| 81 | group('buildServerBaseUrl ollamaCloud short-circuits', () { |
| 82 | test('returns https://ollama.com regardless of host', () { |
| 83 | final url = buildServerBaseUrl( |
| 84 | 'some-host.example', |
| 85 | 12345, |
| 86 | ServerType.ollamaCloud, |
| 87 | ); |
| 88 | expect(url, 'https://ollama.com'); |
| 89 | }); |
| 90 | }); |
| 91 | |
| 92 | group('displayServerAddress for ollamaCloud', () { |
| 93 | test('returns ollama.com', () { |
| 94 | final display = displayServerAddress( |
| 95 | 'localhost', |
| 96 | 11434, |
| 97 | ServerType.ollamaCloud, |
| 98 | ); |
| 99 | expect(display, 'ollama.com'); |
| 100 | }); |
| 101 | }); |
| 102 | } |