diff --git a/src/app/app-client.spec.ts b/src/app/app-client.spec.ts index 8e3870470..07614b282 100644 --- a/src/app/app-client.spec.ts +++ b/src/app/app-client.spec.ts @@ -1733,4 +1733,259 @@ describe('AppClient tests', () => { expect(response.id).toEqual('id'); }); }); + + describe('getOrganizationMetadata', () => { + beforeEach(() => { + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + getOrganizationMetadata: () => + new pb.GetOrganizationMetadataResponse(), + }); + }); + }); + + it('returns an empty object if there is no Struct', async () => { + const response = await subject().getOrganizationMetadata('orgId'); + expect(response).toEqual({}); + }); + + it('preserves the map key when a Struct is found', async () => { + const testResponse = new pb.GetOrganizationMetadataResponse({ + data: Struct.fromJson({ key1: 'value1' }), + }); + + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + getOrganizationMetadata: () => testResponse, + }); + }); + + const response = await subject().getOrganizationMetadata('orgId'); + expect(response).toEqual({ key1: 'value1' }); + }); + }); + + describe('updateOrganizationMetadata', () => { + let capturedRequest: pb.UpdateOrganizationMetadataRequest; + + beforeEach(() => { + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + updateOrganizationMetadata: (req) => { + capturedRequest = req; + return new pb.UpdateOrganizationMetadataResponse(); + }, + }); + }); + }); + + it('should handle empty metadata correctly', async () => { + await subject().updateOrganizationMetadata('orgId', {}); + + expect(capturedRequest).toEqual({ + organizationId: 'orgId', + data: Struct.fromJson({}), + }); + }); + + it('should successfully update metadata with valid data', async () => { + await subject().updateOrganizationMetadata('orgId', { key1: 'value1' }); + + expect(capturedRequest).toEqual({ + organizationId: 'orgId', + data: Struct.fromJson({ key1: 'value1' }), + }); + }); + }); + + describe('getLocationMetadata', () => { + beforeEach(() => { + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + getLocationMetadata: () => new pb.GetLocationMetadataResponse(), + }); + }); + }); + + it('returns an empty object if there is no Struct', async () => { + const response = await subject().getLocationMetadata('orgId'); + expect(response).toEqual({}); + }); + + it('preserves the map key when a Struct is found', async () => { + const testResponse = new pb.GetLocationMetadataResponse({ + data: Struct.fromJson({ key1: 'value1' }), + }); + + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + getLocationMetadata: () => testResponse, + }); + }); + + const response = await subject().getLocationMetadata('orgId'); + expect(response).toEqual({ key1: 'value1' }); + }); + }); + + describe('updateLocationMetadata', () => { + let capturedRequest: pb.UpdateLocationMetadataResponse; + + beforeEach(() => { + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + updateLocationMetadata: (req) => { + capturedRequest = req; + return new pb.UpdateLocationMetadataResponse(); + }, + }); + }); + }); + + it('should handle empty metadata correctly', async () => { + await subject().updateLocationMetadata('locId', {}); + + expect(capturedRequest).toEqual({ + locationId: 'locId', + data: Struct.fromJson({}), + }); + }); + + it('should successfully update metadata with valid data', async () => { + await subject().updateLocationMetadata('locId', { key1: 'value1' }); + + expect(capturedRequest).toEqual({ + locationId: 'locId', + data: Struct.fromJson({ key1: 'value1' }), + }); + }); + }); + + describe('getRobotMetadata', () => { + beforeEach(() => { + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + getRobotMetadata: () => new pb.GetRobotMetadataResponse(), + }); + }); + }); + + it('returns an empty object if there is no Struct', async () => { + const response = await subject().getRobotMetadata('orgId'); + expect(response).toEqual({}); + }); + + it('preserves the map key when a Struct is found', async () => { + const testResponse = new pb.GetRobotMetadataResponse({ + data: Struct.fromJson({ key1: 'value1' }), + }); + + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + getRobotMetadata: () => testResponse, + }); + }); + + const response = await subject().getRobotMetadata('orgId'); + expect(response).toEqual({ key1: 'value1' }); + }); + }); + + describe('updateRobotMetadata', () => { + let capturedRequest: pb.UpdateRobotMetadataResponse; + + beforeEach(() => { + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + updateRobotMetadata: (req) => { + capturedRequest = req; + return new pb.UpdateLocationMetadataResponse(); + }, + }); + }); + }); + + it('should handle empty metadata correctly', async () => { + await subject().updateRobotMetadata('robotId', {}); + + expect(capturedRequest).toEqual({ + id: 'robotId', + data: Struct.fromJson({}), + }); + }); + + it('should successfully update metadata with valid data', async () => { + await subject().updateRobotMetadata('robotId', { key1: 'value1' }); + + expect(capturedRequest).toEqual({ + id: 'robotId', + data: Struct.fromJson({ key1: 'value1' }), + }); + }); + }); + + describe('getRobotPartMetadata', () => { + beforeEach(() => { + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + getRobotPartMetadata: () => new pb.GetRobotPartMetadataResponse(), + }); + }); + }); + + it('returns an empty object if there is no Struct', async () => { + const response = await subject().getRobotPartMetadata('orgId'); + expect(response).toEqual({}); + }); + + it('preserves the map key when a Struct is found', async () => { + const testResponse = new pb.GetRobotPartMetadataResponse({ + data: Struct.fromJson({ key1: 'value1' }), + }); + + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + getRobotPartMetadata: () => testResponse, + }); + }); + + const response = await subject().getRobotPartMetadata('orgId'); + expect(response).toEqual({ key1: 'value1' }); + }); + }); + + describe('updateRobotPartMetadata', () => { + let capturedRequest: pb.UpdateRobotPartMetadataResponse; + + beforeEach(() => { + mockTransport = createRouterTransport(({ service }) => { + service(AppService, { + updateRobotPartMetadata: (req) => { + capturedRequest = req; + return new pb.UpdateRobotPartMetadataResponse(); + }, + }); + }); + }); + + it('should handle empty metadata correctly', async () => { + await subject().updateRobotPartMetadata('robotPartId', {}); + + expect(capturedRequest).toEqual({ + id: 'robotPartId', + data: Struct.fromJson({}), + }); + }); + + it('should successfully update metadata with valid data', async () => { + await subject().updateRobotPartMetadata('robotPartId', { + key1: 'value1', + }); + + expect(capturedRequest).toEqual({ + id: 'robotPartId', + data: Struct.fromJson({ key1: 'value1' }), + }); + }); + }); }); diff --git a/src/app/app-client.ts b/src/app/app-client.ts index 5260d1328..ec0602635 100644 --- a/src/app/app-client.ts +++ b/src/app/app-client.ts @@ -1,4 +1,5 @@ -import type { Struct } from '@bufbuild/protobuf'; +import type { JsonValue } from '@bufbuild/protobuf'; +import { Struct } from '@bufbuild/protobuf'; import { createClient, type Client, type Transport } from '@connectrpc/connect'; import { PackageType } from '../gen/app/packages/v1/packages_pb'; import { AppService } from '../gen/app/v1/app_connect'; @@ -1175,4 +1176,125 @@ export class AppClient { ): Promise { return this.client.createKeyFromExistingKeyAuthorizations({ id }); } + + /** + * Retrieves user-defined metadata for an organization. + * + * @param id The ID of the organization + * @returns The metadata associated with the organization + */ + async getOrganizationMetadata( + id: string + ): Promise> { + const response = await this.client.getOrganizationMetadata({ + organizationId: id, + }); + const jsonResponse = response.toJson() as { + data?: Record; + }; + return jsonResponse.data ?? {}; + } + + /** + * Updates user-defined metadata for an organization. + * + * @param id The ID of the organization + * @param data The metadata to update + */ + async updateOrganizationMetadata( + id: string, + data: Record + ): Promise { + await this.client.updateOrganizationMetadata({ + organizationId: id, + data: Struct.fromJson(data), + }); + } + + /** + * Retrieves user-defined metadata for a location. + * + * @param id The ID of the location + * @returns The metadata associated with the location + */ + async getLocationMetadata(id: string): Promise> { + const response = await this.client.getLocationMetadata({ locationId: id }); + const jsonResponse = response.toJson() as { + data?: Record; + }; + return jsonResponse.data ?? {}; + } + + /** + * Updates user-defined metadata for a location. + * + * @param id The ID of the location + * @param data The metadata to update + */ + async updateLocationMetadata( + id: string, + data: Record + ): Promise { + await this.client.updateLocationMetadata({ + locationId: id, + data: Struct.fromJson(data), + }); + } + + /** + * Retrieves user-defined metadata for a robot. + * + * @param id The ID of the robot + * @returns The metadata associated with the robot + */ + async getRobotMetadata(id: string): Promise> { + const response = await this.client.getRobotMetadata({ id }); + const jsonResponse = response.toJson() as { + data?: Record; + }; + return jsonResponse.data ?? {}; + } + + /** + * Updates user-defined metadata for a robot. + * + * @param id The ID of the robot + * @param data The metadata to update + */ + async updateRobotMetadata( + id: string, + data: Record + ): Promise { + await this.client.updateRobotMetadata({ id, data: Struct.fromJson(data) }); + } + + /** + * Retrieves user-defined metadata for a robot part. + * + * @param id The ID of the robot part + * @returns The metadata associated with the robot part + */ + async getRobotPartMetadata(id: string): Promise> { + const response = await this.client.getRobotPartMetadata({ id }); + const jsonResponse = response.toJson() as { + data?: Record; + }; + return jsonResponse.data ?? {}; + } + + /** + * Updates user-defined metadata for a robot part. + * + * @param id The ID of the robot part + * @param data The metadata to update + */ + async updateRobotPartMetadata( + id: string, + data: Record + ): Promise { + await this.client.updateRobotPartMetadata({ + id, + data: Struct.fromJson(data), + }); + } }