Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
255 changes: 255 additions & 0 deletions src/app/app-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }),
});
});
});
});
124 changes: 123 additions & 1 deletion src/app/app-client.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -1175,4 +1176,125 @@ export class AppClient {
): Promise<CreateKeyFromExistingKeyAuthorizationsResponse> {
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<Record<string, JsonValue>> {
const response = await this.client.getOrganizationMetadata({
organizationId: id,
});
const jsonResponse = response.toJson() as {
data?: Record<string, JsonValue>;
};
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<string, JsonValue>
): Promise<void> {
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<Record<string, JsonValue>> {
const response = await this.client.getLocationMetadata({ locationId: id });
const jsonResponse = response.toJson() as {
data?: Record<string, JsonValue>;
};
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<string, JsonValue>
): Promise<void> {
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<Record<string, JsonValue>> {
const response = await this.client.getRobotMetadata({ id });
const jsonResponse = response.toJson() as {
data?: Record<string, JsonValue>;
};
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<string, JsonValue>
): Promise<void> {
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<Record<string, JsonValue>> {
const response = await this.client.getRobotPartMetadata({ id });
const jsonResponse = response.toJson() as {
data?: Record<string, JsonValue>;
};
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<string, JsonValue>
): Promise<void> {
await this.client.updateRobotPartMetadata({
id,
data: Struct.fromJson(data),
});
}
}