Skip to content

Commit

Permalink
Add listMachineFragments (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
njooma authored Oct 21, 2024
1 parent e729080 commit 0ab9c4a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
29 changes: 29 additions & 0 deletions src/app/app-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,35 @@ describe('AppClient tests', () => {
});
});

describe('listMachineFragment tests', () => {
let request: pb.ListMachineFragmentsRequest;
const response = [fragment];
beforeEach(() => {
mockTransport = createRouterTransport(({ service }) => {
service(AppService, {
listMachineFragments: (req) => {
request = req;
return new pb.ListMachineFragmentsResponse({
fragments: response,
});
},
});
});
});

it('listMachineFragments', async () => {
const machineId = 'MACHINE_ID';
const additionalFragmentIds = ['FRAGMENT ID 1', 'FRAGMENT ID 2'];
const resp = await subject().listMachineFragments(
machineId,
additionalFragmentIds
);
expect(request.machineId).toEqual(machineId);
expect(request.additionalFragmentIds).toEqual(additionalFragmentIds);
expect(resp).toEqual(response);
});
});

describe('addRole tests', () => {
const expectedRequest = new pb.AddRoleRequest({
authorization,
Expand Down
31 changes: 24 additions & 7 deletions src/app/app-client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { Struct } from '@bufbuild/protobuf';
import {
createPromiseClient,
type PromiseClient,
type Transport,
} from '@connectrpc/connect';
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';
import {
Expand Down Expand Up @@ -114,10 +110,10 @@ export const createPermission = (
};

export class AppClient {
private client: PromiseClient<typeof AppService>;
private client: Client<typeof AppService>;

constructor(transport: Transport) {
this.client = createPromiseClient(AppService, transport);
this.client = createClient(AppService, transport);
}

/**
Expand Down Expand Up @@ -827,6 +823,27 @@ export class AppClient {
await this.client.deleteFragment({ id });
}

/**
* @param machineId The machine ID used to filter fragments defined in a
* machine's parts. Also returns any fragments nested within the fragments
* defined in parts.
* @param additionalFragmentIds Additional fragment IDs to append to the
* response. Useful when needing to view fragments that will be
* provisionally added to the machine alongside existing fragments.
* @returns The list of top level and nested fragments for a machine, as well
* as additionally specified fragment IDs.
*/
async listMachineFragments(
machineId: string,
additionalFragmentIds?: string[]
): Promise<Fragment[]> {
const resp = await this.client.listMachineFragments({
machineId,
additionalFragmentIds,
});
return resp.fragments;
}

/**
* Add a role under an organization.
*
Expand Down

0 comments on commit 0ab9c4a

Please sign in to comment.