Skip to content

Commit 9dcc47c

Browse files
committed
chore: add duplicate api key name test
1 parent eb889d4 commit 9dcc47c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

integration/tests/machine-auth/component.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,41 @@ test.describe('api keys component @machine', () => {
758758
});
759759
});
760760

761+
test('shows error when creating API key with duplicate name', async ({ page, context }) => {
762+
const u = createTestUtils({ app, page, context });
763+
await u.po.signIn.goTo();
764+
await u.po.signIn.waitForMounted();
765+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeAdmin.email, password: fakeAdmin.password });
766+
await u.po.expect.toBeSignedIn();
767+
768+
await u.po.page.goToRelative('/api-keys');
769+
await u.po.apiKeys.waitForMounted();
770+
771+
const duplicateName = `${fakeAdmin.firstName}-duplicate-${Date.now()}`;
772+
773+
// Create the first API key
774+
await u.po.apiKeys.clickAddButton();
775+
await u.po.apiKeys.waitForFormOpened();
776+
await u.po.apiKeys.typeName(duplicateName);
777+
await u.po.apiKeys.selectExpiration('1d');
778+
await u.po.apiKeys.clickSaveButton();
779+
780+
await u.po.apiKeys.waitForCopyModalOpened();
781+
await u.po.apiKeys.clickCopyAndCloseButton();
782+
await u.po.apiKeys.waitForCopyModalClosed();
783+
await u.po.apiKeys.waitForFormClosed();
784+
785+
// Try to create another API key with the same name
786+
await u.po.apiKeys.clickAddButton();
787+
await u.po.apiKeys.waitForFormOpened();
788+
await u.po.apiKeys.typeName(duplicateName);
789+
await u.po.apiKeys.selectExpiration('1d');
790+
await u.po.apiKeys.clickSaveButton();
791+
792+
// Verify error message is displayed
793+
await expect(u.page.getByText('API Key name already exists.')).toBeVisible({ timeout: 5000 });
794+
});
795+
761796
test('shows error when API key usage is exceeded for free plan', async ({ page, context }) => {
762797
const u = createTestUtils({ app, page, context });
763798
await u.po.signIn.goTo();

0 commit comments

Comments
 (0)