From 65dd221a85a3f286945fc1224549f14d64fc10a2 Mon Sep 17 00:00:00 2001 From: Chandrasekhar Ramakrishnan Date: Tue, 27 Aug 2024 09:21:03 +0200 Subject: [PATCH] do not call save credentials if the validation failed --- .../project/components/cloudStorage/CloudStorageModal.tsx | 4 +++- tests/cypress/e2e/projectV2DataSourceCredentials.spec.ts | 7 ++++++- tests/cypress/support/renkulab-fixtures/cloudStorage.ts | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/src/features/project/components/cloudStorage/CloudStorageModal.tsx b/client/src/features/project/components/cloudStorage/CloudStorageModal.tsx index 976e98bbed..fa62caaeac 100644 --- a/client/src/features/project/components/cloudStorage/CloudStorageModal.tsx +++ b/client/src/features/project/components/cloudStorage/CloudStorageModal.tsx @@ -391,7 +391,8 @@ export default function CloudStorageModal({ const shouldSaveCredentials = !!( isV2 && storageDetails.options && - state.saveCredentials + state.saveCredentials && + validationSucceeded ); if (!shouldSaveCredentials) { return; @@ -423,6 +424,7 @@ export default function CloudStorageModal({ schema, storageDetails.options, storageDetails.schema, + validationSucceeded, ]); // Visual elements diff --git a/tests/cypress/e2e/projectV2DataSourceCredentials.spec.ts b/tests/cypress/e2e/projectV2DataSourceCredentials.spec.ts index a82a904541..6c6a6d9ab1 100644 --- a/tests/cypress/e2e/projectV2DataSourceCredentials.spec.ts +++ b/tests/cypress/e2e/projectV2DataSourceCredentials.spec.ts @@ -55,7 +55,12 @@ describe("Set up data sources with credentials", () => { fixture: "cloudStorage/cloud-storage-with-secrets-values-empty.json", name: "getCloudStorageV2", }) - .testCloudStorage({ success: false }); + .testCloudStorage({ success: false }) + .postCloudStorageSecrets({ + content: [], + // No call to postCloudStorageSecrets is expected + shouldNotBeCalled: true, + }); cy.visit("/v2/projects/user1-uuid/test-2-v2-project"); cy.wait("@readProjectV2"); // add data source diff --git a/tests/cypress/support/renkulab-fixtures/cloudStorage.ts b/tests/cypress/support/renkulab-fixtures/cloudStorage.ts index 380b3f7d13..5b09fd2ed9 100644 --- a/tests/cypress/support/renkulab-fixtures/cloudStorage.ts +++ b/tests/cypress/support/renkulab-fixtures/cloudStorage.ts @@ -36,6 +36,7 @@ interface PostCloudStorageSecretsArgs extends CloudStorageSecretsArgs { name: string; value: string; }[]; + shouldNotBeCalled?: boolean; } interface TestCloudStorageArgs extends SimpleFixture { @@ -112,6 +113,7 @@ export function CloudStorage(Parent: T) { content, fixture = "cloudStorage/cloud-storage-secrets.json", name = "postCloudStorageSecrets", + shouldNotBeCalled = false, storageId = 2, } = args ?? {}; cy.fixture(fixture).then((secrets) => { @@ -120,6 +122,8 @@ export function CloudStorage(Parent: T) { "POST", `/ui-server/api/data/storages_v2/${storageId}/secrets`, (req) => { + if (shouldNotBeCalled) + throw new Error("No call to post secrets expected"); const newSecrets = req.body; expect(newSecrets.length).equal(content.length); newSecrets.forEach((secret, index) => {