Skip to content

Commit

Permalink
[WOR-1438] Fix bug with request of token with undefined googleProject (
Browse files Browse the repository at this point in the history
  • Loading branch information
cahrens authored Jan 26, 2024
1 parent 41a98d2 commit 601d60c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/pages/workspaces/WorkspacesList/RenderedWorkspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ const ActionsCell = (props: ActionsCellProps): ReactNode => {
workspaceId: string,
policies?: WorkspacePolicy[],
bucketName?: string,
description?: string
description?: string,
googleProject?: string
): Workspace => {
// The workspaces from the list API have fewer properties to keep the payload as small as possible.
const listWorkspace = getWorkspace(workspaceId);
Expand All @@ -395,14 +396,20 @@ const ActionsCell = (props: ActionsCellProps): ReactNode => {
extendedWorkspace.workspace.bucketName = bucketName;
}

if (googleProject !== undefined && isGoogleWorkspace(extendedWorkspace)) {
extendedWorkspace.workspace.googleProject = googleProject;
}

if (description !== undefined && extendedWorkspace.workspace.attributes !== undefined) {
extendedWorkspace.workspace.attributes.description = description;
}
return extendedWorkspace;
};

const onClone = (policies, bucketName, description) =>
setUserActions({ cloningWorkspace: extendWorkspace(workspaceId, policies, bucketName, description) });
const onClone = (policies, bucketName, description, googleProject) =>
setUserActions({
cloningWorkspace: extendWorkspace(workspaceId, policies, bucketName, description, googleProject),
});
const onDelete = () => setUserActions({ deletingWorkspaceId: workspaceId });
const onLock = () => setUserActions({ lockingWorkspaceId: workspaceId });
const onShare = (policies, bucketName) =>
Expand Down
10 changes: 6 additions & 4 deletions src/pages/workspaces/workspace/WorkspaceMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ describe('DynamicWorkspaceMenuContent fetches specific workspace details', () =>
// @ts-expect-error - Limit return values based on what is requested
workspace: {
cloudPlatform: 'Gcp',
googleProject: 'googleProjectName',
bucketName: 'fc-bucketname',
isLocked: false,
state: 'Ready',
Expand Down Expand Up @@ -394,7 +395,7 @@ describe('DynamicWorkspaceMenuContent fetches specific workspace details', () =>
policies: [protectedDataPolicy],
};

const onClone = jest.fn((_policies, _bucketName, _description) => {});
const onClone = jest.fn((_policies, _bucketName, _description, _googleProject) => {});
const onShare = jest.fn((_policies, _bucketName) => {});
const namespace = 'test-namespace';
const name = 'test-name';
Expand Down Expand Up @@ -423,6 +424,7 @@ describe('DynamicWorkspaceMenuContent fetches specific workspace details', () =>
'workspace.bucketName',
'workspace.attributes.description',
'workspace.cloudPlatform',
'workspace.googleProject',
'workspace.isLocked',
'workspace.state',
];
Expand All @@ -434,7 +436,7 @@ describe('DynamicWorkspaceMenuContent fetches specific workspace details', () =>
expect(workspaceDetails).toHaveBeenCalledWith({ namespace, name }, expectedRequestedFields);
});

it('passes onClone the bucketName and description for a Google workspace', async () => {
it('passes onClone the bucketName, description, and googleProject for a Google workspace', async () => {
// Arrange
const user = userEvent.setup();
asMockedFn(useWorkspaceDetails).mockReturnValue({
Expand All @@ -450,7 +452,7 @@ describe('DynamicWorkspaceMenuContent fetches specific workspace details', () =>
// Assert
const menuItem = screen.getByText('Clone');
await user.click(menuItem);
expect(onClone).toBeCalledWith([], 'fc-bucketname', descriptionText);
expect(onClone).toBeCalledWith([], 'fc-bucketname', descriptionText, 'googleProjectName');
});

it('passes onClone the policies and description for an Azure workspace', async () => {
Expand All @@ -469,7 +471,7 @@ describe('DynamicWorkspaceMenuContent fetches specific workspace details', () =>
// Assert
const menuItem = screen.getByText('Clone');
await user.click(menuItem);
expect(onClone).toBeCalledWith([protectedDataPolicy], undefined, descriptionText);
expect(onClone).toBeCalledWith([protectedDataPolicy], undefined, descriptionText, undefined);
});

it('passes onShare the bucketName for a Google workspace', async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/pages/workspaces/workspace/WorkspaceMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type DynamicWorkspaceInfo = { name: string; namespace: string };
type WorkspaceInfo = DynamicWorkspaceInfo | LoadedWorkspaceInfo;

interface WorkspaceMenuCallbacks {
onClone: (policies?: WorkspacePolicy[], bucketName?: string, description?: string) => void;
onClone: (policies?: WorkspacePolicy[], bucketName?: string, description?: string, googleProject?: string) => void;
onShare: (policies?: WorkspacePolicy[], bucketName?: string) => void;
onLock: () => void;
onDelete: () => void;
Expand Down Expand Up @@ -99,10 +99,12 @@ const DynamicWorkspaceMenuContent = (props: DynamicWorkspaceMenuContentProps) =>
'workspace.bucketName',
'workspace.attributes.description',
'workspace.cloudPlatform',
'workspace.googleProject',
'workspace.isLocked',
'workspace.state',
]) as { workspace?: Workspace };
const bucketName = !!workspace && isGoogleWorkspace(workspace) ? workspace.workspace.bucketName : undefined;
const googleProject = !!workspace && isGoogleWorkspace(workspace) ? workspace.workspace.googleProject : undefined;

const descriptionText =
!!workspace && workspace.workspace.attributes !== undefined
Expand All @@ -123,7 +125,7 @@ const DynamicWorkspaceMenuContent = (props: DynamicWorkspaceMenuContentProps) =>
callbacks: {
...callbacks,
onShare: () => callbacks.onShare(workspace?.policies, bucketName),
onClone: () => callbacks.onClone(workspace?.policies, bucketName, descriptionText),
onClone: () => callbacks.onClone(workspace?.policies, bucketName, descriptionText, googleProject),
},
});
};
Expand Down

0 comments on commit 601d60c

Please sign in to comment.