add back client parameter for testing
This commit is contained in:
@@ -25,8 +25,10 @@ class SyncApiRepository {
|
|||||||
Future<void> Function(List<SyncEvent>, Function() abort, Function() reset) onData, {
|
Future<void> Function(List<SyncEvent>, Function() abort, Function() reset) onData, {
|
||||||
Function()? onReset,
|
Function()? onReset,
|
||||||
int batchSize = kSyncEventBatchSize,
|
int batchSize = kSyncEventBatchSize,
|
||||||
|
http.Client? httpClient,
|
||||||
}) async {
|
}) async {
|
||||||
final stopwatch = Stopwatch()..start();
|
final stopwatch = Stopwatch()..start();
|
||||||
|
final client = httpClient ?? _client;
|
||||||
final endpoint = "${_api.apiClient.basePath}/sync/stream";
|
final endpoint = "${_api.apiClient.basePath}/sync/stream";
|
||||||
|
|
||||||
final headers = {'Content-Type': 'application/json', 'Accept': 'application/jsonlines+json'};
|
final headers = {'Content-Type': 'application/json', 'Accept': 'application/jsonlines+json'};
|
||||||
@@ -78,7 +80,7 @@ class SyncApiRepository {
|
|||||||
final reset = onReset ?? () {};
|
final reset = onReset ?? () {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final response = await _client.send(request);
|
final response = await client.send(request);
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
final errorBody = await response.stream.bytesToString();
|
final errorBody = await response.stream.bytesToString();
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ void main() {
|
|||||||
expect(onDataCallCount, 1);
|
expect(onDataCallCount, 1);
|
||||||
expect(abortWasCalledInCallback, isTrue);
|
expect(abortWasCalledInCallback, isTrue);
|
||||||
expect(receivedEventsBatch1.length, testBatchSize);
|
expect(receivedEventsBatch1.length, testBatchSize);
|
||||||
verify(() => mockHttpClient.close()).called(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('streamChanges does not process remaining lines in finally block if aborted', () async {
|
test('streamChanges does not process remaining lines in finally block if aborted', () async {
|
||||||
@@ -159,7 +158,6 @@ void main() {
|
|||||||
|
|
||||||
expect(onDataCallCount, 1);
|
expect(onDataCallCount, 1);
|
||||||
expect(abortWasCalledInCallback, isTrue);
|
expect(abortWasCalledInCallback, isTrue);
|
||||||
verify(() => mockHttpClient.close()).called(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('streamChanges processes remaining lines in finally block if not aborted', () async {
|
test('streamChanges processes remaining lines in finally block if not aborted', () async {
|
||||||
@@ -204,7 +202,6 @@ void main() {
|
|||||||
expect(onDataCallCount, 2);
|
expect(onDataCallCount, 2);
|
||||||
expect(receivedEventsBatch1.length, testBatchSize);
|
expect(receivedEventsBatch1.length, testBatchSize);
|
||||||
expect(receivedEventsBatch2.length, 1);
|
expect(receivedEventsBatch2.length, 1);
|
||||||
verify(() => mockHttpClient.close()).called(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('streamChanges handles stream error gracefully', () async {
|
test('streamChanges handles stream error gracefully', () async {
|
||||||
@@ -229,7 +226,6 @@ void main() {
|
|||||||
await expectLater(streamChangesFuture, throwsA(streamError));
|
await expectLater(streamChangesFuture, throwsA(streamError));
|
||||||
|
|
||||||
expect(onDataCallCount, 0);
|
expect(onDataCallCount, 0);
|
||||||
verify(() => mockHttpClient.close()).called(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('streamChanges throws ApiException on non-200 status code', () async {
|
test('streamChanges throws ApiException on non-200 status code', () async {
|
||||||
@@ -257,6 +253,5 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(onDataCallCount, 0);
|
expect(onDataCallCount, 0);
|
||||||
verify(() => mockHttpClient.close()).called(1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user