From 3c8adabe09361e18c1e76c813d0e99bbb79bbb42 Mon Sep 17 00:00:00 2001 From: Juntao Wang Date: Tue, 10 Oct 2023 11:39:52 -0400 Subject: [PATCH] Make data connection bucket field mandatory --- .../pages/projects/dataConnections/const.ts | 1 + .../spawner/__tests__/spawnerUtils.spec.ts | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 frontend/src/pages/projects/screens/spawner/__tests__/spawnerUtils.spec.ts diff --git a/frontend/src/pages/projects/dataConnections/const.ts b/frontend/src/pages/projects/dataConnections/const.ts index 50987adb93..48c481f649 100644 --- a/frontend/src/pages/projects/dataConnections/const.ts +++ b/frontend/src/pages/projects/dataConnections/const.ts @@ -39,6 +39,7 @@ export const AWS_FIELDS: FieldOptions[] = [ { key: AWS_KEYS.AWS_S3_BUCKET, label: 'Bucket', + isRequired: true, }, ]; diff --git a/frontend/src/pages/projects/screens/spawner/__tests__/spawnerUtils.spec.ts b/frontend/src/pages/projects/screens/spawner/__tests__/spawnerUtils.spec.ts new file mode 100644 index 0000000000..24368c80b5 --- /dev/null +++ b/frontend/src/pages/projects/screens/spawner/__tests__/spawnerUtils.spec.ts @@ -0,0 +1,63 @@ +import { AWS_KEYS } from '~/pages/projects/dataConnections/const'; +import { isAWSValid } from '~/pages/projects/screens/spawner/spawnerUtils'; +import { EnvVariableDataEntry } from '~/pages/projects/types'; + +describe('isAWSValid', () => { + const getMockAWSData = ({ + name = 'test-name', + accessKey = 'test-access-key', + accessSecret = 'test-access-secret', + bucket = 'test-bucket', + endpoint = 'test-endpoint', + region = '', + }): EnvVariableDataEntry[] => [ + { + key: AWS_KEYS.NAME, + value: name, + }, + { + key: AWS_KEYS.ACCESS_KEY_ID, + value: accessKey, + }, + { + key: AWS_KEYS.SECRET_ACCESS_KEY, + value: accessSecret, + }, + { + key: AWS_KEYS.S3_ENDPOINT, + value: endpoint, + }, + { + key: AWS_KEYS.DEFAULT_REGION, + value: region, + }, + { + key: AWS_KEYS.AWS_S3_BUCKET, + value: bucket, + }, + ]; + + it('should be valid when all the required fields are met', () => { + expect(isAWSValid(getMockAWSData({}))).toBe(true); + }); + + it('should be invalid when the name field is missing', () => { + expect(isAWSValid(getMockAWSData({ name: '' }))).toBe(false); + }); + + it('should be invalid when the access key field is missing', () => { + expect(isAWSValid(getMockAWSData({ accessKey: '' }))).toBe(false); + }); + + it('should be invalid when the secret key field is missing', () => { + expect(isAWSValid(getMockAWSData({ accessSecret: '' }))).toBe(false); + }); + + it('should be invalid when the endpoint field is missing', () => { + expect(isAWSValid(getMockAWSData({ endpoint: '' }))).toBe(false); + }); + + it('should be invalid when the bucket field is missing', () => { + expect(isAWSValid(getMockAWSData({ bucket: '' }))).toBe(false); + }); +});