Files
plezy/test/services/trackers/tracker_http_client_test.dart
T
edde746 a33c423985 refactor(models): stop parsing wire fields and enum members nothing consumes
Parse-only DTO surface deleted across trackers and catalog models: quality-preset storageKey/fromStorage round-trips (persistence uses EnumPref on .name), PlexHome's placeholder identity fields (id stays — deriveHomeSecret reads it), SeerrUser.email/avatar, SimklSearchResult.endpointType, SimklDetail.type, SimklAllItemsEntry.status/isShow, TraktCatalogEntry.rank, CatalogItem.relevance, and the never-produced CatalogRankScope.favorited/.seasonal members with their label arms. Tracker root: OAuthProxyStart.expiresIn, TrackerSession.scope/isExpired, copyWith slimmed to its one real parameter, TrackerHttpClient.service. TrackerAccountStore.service and the trackerAccountStore() alias are live (persisted-blob validation, callers) and stay.
2026-08-17 19:02:24 +02:00

74 lines
2.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
import 'package:plezy/services/trackers/tracker_http_client.dart';
TrackerHttpClient _client(void Function(http.Request) capture) {
return TrackerHttpClient(
logLabel: 'MAL',
httpClient: MockClient((request) async {
capture(request);
return http.Response('{}', 200);
}),
);
}
void main() {
group('TrackerHttpClient.sendJson content type', () {
test('defaults a JSON content type when the caller omits one', () async {
http.Request? sent;
final client = _client((r) => sent = r);
await client.sendJson(
'POST',
Uri.parse('https://api.example.com/x'),
headers: {'Accept': 'application/json'},
body: {'a': 1},
);
expect(sent!.headers['content-type'], contains('application/json'));
client.dispose();
});
test('preserves a caller-provided content type', () async {
http.Request? sent;
final client = _client((r) => sent = r);
await client.sendJson(
'POST',
Uri.parse('https://api.example.com/x'),
headers: {'Content-Type': 'application/vnd.api+json'},
body: {'a': 1},
);
expect(sent!.headers['content-type'], contains('application/vnd.api+json'));
client.dispose();
});
test('preserves a caller-provided content type case-insensitively', () async {
http.Request? sent;
final client = _client((r) => sent = r);
await client.sendJson(
'POST',
Uri.parse('https://api.example.com/x'),
headers: {'content-type': 'application/vnd.api+json'},
body: {'a': 1},
);
expect(sent!.headers['content-type'], contains('application/vnd.api+json'));
client.dispose();
});
test('does not add a content type when there is no body', () async {
http.Request? sent;
final client = _client((r) => sent = r);
await client.sendJson('GET', Uri.parse('https://api.example.com/x'), headers: {'Accept': 'application/json'});
expect(sent!.headers.containsKey('content-type'), isFalse);
client.dispose();
});
});
}