-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When approaching limit or limit reached for the number of API tokens, we show a corresponding message.
- Loading branch information
Showing
3 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
frontend/src/component/admin/apiToken/CreateApiToken/CreateApiToken.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { render } from 'utils/testRenderer'; | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import { CreateApiToken } from './CreateApiToken'; | ||
import { | ||
ADMIN, | ||
CREATE_CLIENT_API_TOKEN, | ||
CREATE_FRONTEND_API_TOKEN, | ||
} from '@server/types/permissions'; | ||
|
||
const permissions = [ | ||
{ permission: CREATE_CLIENT_API_TOKEN }, | ||
{ permission: CREATE_FRONTEND_API_TOKEN }, | ||
{ permission: ADMIN }, | ||
]; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupApi = (existingTokensCount: number) => { | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
flags: { | ||
resourceLimits: true, | ||
}, | ||
resourceLimits: { | ||
apiTokens: 1, | ||
}, | ||
versionInfo: { | ||
current: { enterprise: 'version' }, | ||
}, | ||
}); | ||
|
||
testServerRoute(server, '/api/admin/api-tokens', { | ||
tokens: [...Array(existingTokensCount).keys()].map((_, i) => ({ | ||
secret: `token${i}`, | ||
})), | ||
}); | ||
}; | ||
|
||
test('Enabled new token button when limits, version and permission allow for it', async () => { | ||
setupApi(0); | ||
render(<CreateApiToken />, { | ||
permissions, | ||
}); | ||
|
||
const button = await screen.findByText('Create token'); | ||
expect(button).toBeDisabled(); | ||
|
||
await waitFor(async () => { | ||
const button = await screen.findByText('Create token'); | ||
expect(button).not.toBeDisabled(); | ||
}); | ||
}); | ||
|
||
test('Token limit reached', async () => { | ||
setupApi(1); | ||
render(<CreateApiToken />, { | ||
permissions, | ||
}); | ||
|
||
await screen.findByText('You have reached the limit for API tokens'); | ||
|
||
const button = await screen.findByText('Create token'); | ||
expect(button).toBeDisabled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters