Skip to content
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
43 changes: 41 additions & 2 deletions web/packages/teleport/src/Bots/Details/BotDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,42 @@ describe('BotDetails', () => {
).toBeInTheDocument();
});

describe('should show bot join tokens empty message', () => {
it('when an empty list is returned', async () => {
withFetchSuccess();
withFetchJoinTokensSuccess({ tokens: [] });
withFetchInstancesSuccess();
withListLocksSuccess();
renderComponent();
await waitForLoadingBot();
await waitForLoadingTokens();

const panel = screen
.getByRole('heading', { name: 'Join Tokens' })
.closest('section');
expect(panel).toBeInTheDocument();

expect(within(panel!).getByText('No join tokens')).toBeInTheDocument();
});

it('when null is returned', async () => {
withFetchSuccess();
withFetchJoinTokensSuccess({ tokens: null });
withFetchInstancesSuccess();
withListLocksSuccess();
renderComponent();
await waitForLoadingBot();
await waitForLoadingTokens();

const panel = screen
.getByRole('heading', { name: 'Join Tokens' })
.closest('section');
expect(panel).toBeInTheDocument();

expect(within(panel!).getByText('No join tokens')).toBeInTheDocument();
});
});

it('should show bot instances', async () => {
withFetchSuccess();
withFetchJoinTokensSuccess();
Expand Down Expand Up @@ -728,8 +764,11 @@ const withFetchSuccess = () => {
server.use(getBotSuccess());
};

const withFetchJoinTokensSuccess = () => {
server.use(listV2TokensSuccess());
const withFetchJoinTokensSuccess = (options?: {
hasNextPage?: boolean;
tokens?: string[] | null;
}) => {
server.use(listV2TokensSuccess(options));
};

const withFetchJoinTokensMfaError = () => {
Expand Down
2 changes: 1 addition & 1 deletion web/packages/teleport/src/Bots/Details/BotDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ function JoinTokens(props: { botName: string; onViewAllClicked: () => void }) {

{isSuccess ? (
<>
{data.items.length ? (
{data.items?.length ? (
<LabelsContainer>
{data.items
.toSorted((a, b) => a.safeName.localeCompare(b.safeName))
Expand Down
4 changes: 4 additions & 0 deletions web/packages/teleport/src/services/joinToken/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export function validateListJoinTokensResponse(
return false;
}

if (!data.items) {
return true;
}

if (!Array.isArray(data.items)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion web/packages/teleport/src/services/joinToken/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ export type JoinTokenRequest = {
};

export type ListJoinTokensResponse = {
items: JoinToken[];
items?: JoinToken[] | null;
next_page_token?: string;
};
53 changes: 28 additions & 25 deletions web/packages/teleport/src/test/helpers/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,39 @@ export const listV2TokensError = (

export const listV2TokensSuccess = (options?: {
hasNextPage?: boolean;
tokens?: string[];
tokens?: string[] | null;
}) => {
const { hasNextPage = false, tokens } = options ?? {};
return http.get(cfg.api.joinToken.listV2, () => {
return HttpResponse.json(
{
items: (
tokens ?? [
'token',
'ec2',
'iam',
'github',
'circleci',
'kubernetes',
'azure',
'gitlab',
'gcp',
'spacelift',
'tpm',
'terraform_cloud',
'bitbucket',
'oracle',
'azure_devops',
'bound_keypair',
]
).map(method => ({
id: `token-${method}`,
safeName: method,
method: method,
})),
items:
tokens === null
? null
: (
tokens ?? [
'token',
'ec2',
'iam',
'github',
'circleci',
'kubernetes',
'azure',
'gitlab',
'gcp',
'spacelift',
'tpm',
'terraform_cloud',
'bitbucket',
'oracle',
'azure_devops',
'bound_keypair',
]
).map(method => ({
id: `token-${method}`,
safeName: method,
method: method,
})),
next_page_token: hasNextPage ? 'yes' : undefined,
},
{ status: 200 }
Expand Down
Loading