Skip to content

Add includeBinary to data funcs #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/src/app/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,24 @@ class DataClient {
///
/// For more information, see [Data Client API](https://docs.viam.com/appendix/apis/data-client/).
Future<BinaryDataByFilterResponse> binaryDataByFilter(
{Filter? filter, int? limit, Order? sortOrder, String? last, countOnly = false}) async {
{Filter? filter, int? limit, Order? sortOrder, String? last, bool countOnly = false, bool includeBinary = false}) async {
final dataRequest = _makeDataRequest(filter, limit, last, sortOrder);
final request = BinaryDataByFilterRequest()
..dataRequest = dataRequest
..countOnly = false;
..countOnly = countOnly
..includeBinary = includeBinary;
return await _dataClient.binaryDataByFilter(request);
}

/// Retrieve binary data by IDs
///
/// For more information, see [Data Client API](https://docs.viam.com/appendix/apis/data-client/).
Future<List<BinaryData>> binaryDataByIds(List<BinaryID> binaryIds) async {
final request = BinaryDataByIDsRequest()..binaryIds.addAll(binaryIds);
Future<BinaryDataByIDsResponse> binaryDataByIds(List<BinaryID> binaryIds, {bool includeBinary = false}) async {
final request = BinaryDataByIDsRequest()
..binaryIds.addAll(binaryIds)
..includeBinary = includeBinary;
final response = await _dataClient.binaryDataByIDs(request);
return response.data;
return response;
}

/// Obtain unified tabular data and metadata, queried with SQL.
Expand Down
27 changes: 18 additions & 9 deletions test/unit_test/app/data_client_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:typed_data';

import 'package:bson/bson.dart' hide Timestamp;
import 'package:fixnum/fixnum.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -101,14 +99,20 @@ void main() {
const limit = 10;
const last = 'last';
const sortOrder = Order.ORDER_ASCENDING;
bool includeBinary = false;

when(serviceClient.binaryDataByFilter(any)).thenAnswer((_) => MockResponseFuture.value(BinaryDataByFilterResponse()
..count = Int64(limit)
..last = last));
when(serviceClient.binaryDataByFilter(any)).thenAnswer((invocation) {
includeBinary = (invocation.positionalArguments[0] as BinaryDataByFilterRequest).includeBinary;
return MockResponseFuture.value(BinaryDataByFilterResponse()
..count = Int64(limit)
..last = last);
});

final response = await dataClient.binaryDataByFilter(filter: filter, limit: limit, sortOrder: sortOrder, last: last);
final response =
await dataClient.binaryDataByFilter(filter: filter, limit: limit, sortOrder: sortOrder, last: last, includeBinary: true);
expect(response.count, equals(Int64(limit)));
expect(response.last, equals(last));
expect(includeBinary, isTrue);
});

test('binaryDataByFilter_countOnly', () async {
Expand All @@ -135,11 +139,16 @@ void main() {
BinaryData()..binary = [2, 3, 4, 5],
BinaryData()..binary = [3, 4, 5, 6],
];
bool includeBinary = false;

when(serviceClient.binaryDataByIDs(any)).thenAnswer((_) => MockResponseFuture.value(BinaryDataByIDsResponse()..data.addAll(data)));
when(serviceClient.binaryDataByIDs(any)).thenAnswer((invocation) {
includeBinary = (invocation.positionalArguments[0] as BinaryDataByIDsRequest).includeBinary;
return MockResponseFuture.value(BinaryDataByIDsResponse()..data.addAll(data));
});

final response = await dataClient.binaryDataByIds(ids);
expect(response, equals(data));
final response = await dataClient.binaryDataByIds(ids, includeBinary: true);
expect(response.data, equals(data));
expect(includeBinary, isTrue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not test response.count as well now that the response has changed?

});

test('tabularDataBySql', () async {
Expand Down
Loading