Skip to content

Commit

Permalink
Add includeBinary to data funcs (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
njooma authored Jan 23, 2025
1 parent 5d442c7 commit d3719aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
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);
});

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

0 comments on commit d3719aa

Please sign in to comment.