add back client parameter for testing

This commit is contained in:
mertalev
2025-09-18 20:31:29 -04:00
parent df186cc326
commit f406ba1e6c
2 changed files with 3 additions and 6 deletions

View File

@@ -25,8 +25,10 @@ class SyncApiRepository {
Future<void> Function(List<SyncEvent>, Function() abort, Function() reset) onData, {
Function()? onReset,
int batchSize = kSyncEventBatchSize,
http.Client? httpClient,
}) async {
final stopwatch = Stopwatch()..start();
final client = httpClient ?? _client;
final endpoint = "${_api.apiClient.basePath}/sync/stream";
final headers = {'Content-Type': 'application/json', 'Accept': 'application/jsonlines+json'};
@@ -78,7 +80,7 @@ class SyncApiRepository {
final reset = onReset ?? () {};
try {
final response = await _client.send(request);
final response = await client.send(request);
if (response.statusCode != 200) {
final errorBody = await response.stream.bytesToString();

View File

@@ -118,7 +118,6 @@ void main() {
expect(onDataCallCount, 1);
expect(abortWasCalledInCallback, isTrue);
expect(receivedEventsBatch1.length, testBatchSize);
verify(() => mockHttpClient.close()).called(1);
});
test('streamChanges does not process remaining lines in finally block if aborted', () async {
@@ -159,7 +158,6 @@ void main() {
expect(onDataCallCount, 1);
expect(abortWasCalledInCallback, isTrue);
verify(() => mockHttpClient.close()).called(1);
});
test('streamChanges processes remaining lines in finally block if not aborted', () async {
@@ -204,7 +202,6 @@ void main() {
expect(onDataCallCount, 2);
expect(receivedEventsBatch1.length, testBatchSize);
expect(receivedEventsBatch2.length, 1);
verify(() => mockHttpClient.close()).called(1);
});
test('streamChanges handles stream error gracefully', () async {
@@ -229,7 +226,6 @@ void main() {
await expectLater(streamChangesFuture, throwsA(streamError));
expect(onDataCallCount, 0);
verify(() => mockHttpClient.close()).called(1);
});
test('streamChanges throws ApiException on non-200 status code', () async {
@@ -257,6 +253,5 @@ void main() {
);
expect(onDataCallCount, 0);
verify(() => mockHttpClient.close()).called(1);
});
}