Skip to content
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

[RSDK-10127] Add get and update metadata functions #360

Merged
merged 3 commits into from
Mar 18, 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
72 changes: 72 additions & 0 deletions lib/src/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -729,4 +729,76 @@ class AppClient {
final request = CreateKeyFromExistingKeyAuthorizationsRequest()..id = id;
return await _client.createKeyFromExistingKeyAuthorizations(request);
}

/// Retrieves user-defined [Metadata] for an organization.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<GetOrganizationMetadataResponse> getOrganizationMetadata(String organizationId) async {
final request = GetOrganizationMetadataRequest()..organizationId = organizationId;
return await _client.getOrganizationMetadata(request);
}

/// Updates user-defined [Metadata] for an organization.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<void> updateOrganizationMetadata(String organizationId, Map<String, dynamic> data) async {
final request = UpdateOrganizationMetadataRequest()
..organizationId = organizationId
..data = data.toStruct();
await _client.updateOrganizationMetadata(request);
}

/// Retrieves user-defined [Metadata] for a location.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<GetLocationMetadataResponse> getLocationMetadata(String locationId) async {
final request = GetLocationMetadataRequest()..locationId = locationId;
return await _client.getLocationMetadata(request);
}

/// Updates user-defined [Metadata] for a location.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<void> updateLocationMetadata(String locationId, Map<String, dynamic> data) async {
final request = UpdateLocationMetadataRequest()
..locationId = locationId
..data = data.toStruct();
await _client.updateLocationMetadata(request);
}

/// Retrieves user-defined [Metadata] for a robot.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<GetRobotMetadataResponse> getRobotMetadata(String robotId) async {
final request = GetRobotMetadataRequest()..id = robotId;
return await _client.getRobotMetadata(request);
}

/// Updates user-defined [Metadata] for a robot.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<void> updateRobotMetadata(String robotId, Map<String, dynamic> data) async {
final request = UpdateRobotMetadataRequest()
..id = robotId
..data = data.toStruct();
await _client.updateRobotMetadata(request);
}

/// Retrieves user-defined [Metadata] for a robot part.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<GetRobotPartMetadataResponse> getRobotPartMetadata(String robotPartId) async {
final request = GetRobotPartMetadataRequest()..id = robotPartId;
return await _client.getRobotPartMetadata(request);
}

/// Updates user-defined [Metadata] for a robot part.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<void> updateRobotPartMetadata(String robotPartId, Map<String, dynamic> data) async {
final request = UpdateRobotPartMetadataRequest()
..id = robotPartId
..data = data.toStruct();
await _client.updateRobotPartMetadata(request);
}
}
52 changes: 52 additions & 0 deletions test/unit_test/app/app_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -754,5 +754,57 @@ void main() {
final response = await appClient.createKeyFromExistingKeyAuthorizations('id');
expect(response, equals(expected));
});

test('getOrganizationMetadata', () async {
final expected = GetOrganizationMetadataResponse()..data = (Struct()..fields['key'] = (Value()..stringValue = 'value'));
when(serviceClient.getOrganizationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getOrganizationMetadata('orgId');
expect(response, equals(expected));
});
Comment on lines +758 to +763
Copy link
Member

Choose a reason for hiding this comment

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

This test looks good, but we should probably add tests for all the other methods you implemented as well!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Naveed and I were just debugging before I put all of the tests up - thanks for calling this out!


test('updateOrganizationMetadata', () async {
when(serviceClient.updateOrganizationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(UpdateOrganizationMetadataResponse()));
await appClient.updateOrganizationMetadata('orgId', {'key': 'value'});
verify(serviceClient.updateOrganizationMetadata(any)).called(1);
});

test('getLocationMetadata', () async {
final expected = GetLocationMetadataResponse()..data = (Struct()..fields['key'] = (Value()..stringValue = 'value'));
when(serviceClient.getLocationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getLocationMetadata('orgId');
expect(response, equals(expected));
});

test('updateLocationMetadata', () async {
when(serviceClient.updateLocationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(UpdateLocationMetadataResponse()));
await appClient.updateLocationMetadata('orgId', {'key': 'value'});
verify(serviceClient.updateLocationMetadata(any)).called(1);
});

test('getRobotMetadata', () async {
final expected = GetRobotMetadataResponse()..data = (Struct()..fields['key'] = (Value()..stringValue = 'value'));
when(serviceClient.getRobotMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getRobotMetadata('orgId');
expect(response, equals(expected));
});

test('updateRobotMetadata', () async {
when(serviceClient.updateRobotMetadata(any)).thenAnswer((_) => MockResponseFuture.value(UpdateRobotMetadataResponse()));
await appClient.updateRobotMetadata('orgId', {'key': 'value'});
verify(serviceClient.updateRobotMetadata(any)).called(1);
});

test('getRobotPartMetadata', () async {
final expected = GetRobotPartMetadataResponse()..data = (Struct()..fields['key'] = (Value()..stringValue = 'value'));
when(serviceClient.getRobotPartMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getRobotPartMetadata('orgId');
expect(response, equals(expected));
});

test('updateRobotPartMetadata', () async {
when(serviceClient.updateRobotPartMetadata(any)).thenAnswer((_) => MockResponseFuture.value(UpdateRobotPartMetadataResponse()));
await appClient.updateRobotPartMetadata('orgId', {'key': 'value'});
verify(serviceClient.updateRobotPartMetadata(any)).called(1);
});
});
}
Loading