Skip to content

Commit

Permalink
moved table interface and object check to buildDynamoDBTable function
Browse files Browse the repository at this point in the history
  • Loading branch information
mickychetta committed Apr 7, 2022
1 parent 1476e71 commit 8f22294
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export interface BuildDynamoDBTableWithStreamProps {

export function buildDynamoDBTable(scope: Construct, props: BuildDynamoDBTableProps): [dynamodb.ITable, dynamodb.Table?] {
// Conditional DynamoDB Table creation
if (props.existingTableObj) {
if (props.existingTableObj && props.existingTableInterface) {
throw new Error('Error - Either provide existingTableInterface or existingTableObj, but not both.');
} else if (props.existingTableObj) {
return [props.existingTableObj, props.existingTableObj];
} else if (props.existingTableInterface) {
return [props.existingTableInterface, undefined];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ export function CheckProps(propsObject: VerifiedProps | any) {
errorFound = true;
}

if (propsObject.existingTableObj && propsObject.existingTableInterface) {
errorMessages += 'Error - Either provide existingTableInterface or existingTableObj, but not both.\n';
errorFound = true;
}

if (propsObject.existingStreamObj && propsObject.kinesisStreamProps) {
errorMessages += 'Error - Either provide existingStreamObj or kinesisStreamProps, but not both.\n';
errorFound = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,27 @@ test('test getPartitionKeyNameFromTable()', () => {

expect(testKeyName).toEqual(partitionKeyName);
});

test('Test providing both existingTableInterface and existingTableObj', () => {
const stack = new Stack();

const tableProps: dynamodb.TableProps = {
partitionKey: {
name: 'table_id',
type: dynamodb.AttributeType.STRING
},
stream: dynamodb.StreamViewType.NEW_IMAGE
};

const existingTableInterface = new dynamodb.Table(stack, 'DynamoTable', tableProps)
;
const newProps = {
existingTableInterface,
existingTableObj: existingTableInterface
};
const app = () => {
defaults.buildDynamoDBTable(stack, newProps);
};

expect(app).toThrowError('Error - Either provide existingTableInterface or existingTableObj, but not both.');
});
Original file line number Diff line number Diff line change
Expand Up @@ -498,28 +498,4 @@ test('Test unsuccessful CheckListValues', () => {

// Assertion
expect(app).toThrowError('Invalid test value submitted - three');
});

test('Test providing both existingTableInterface and existingTableObj', () => {
const stack = new Stack();

const tableProps: dynamodb.TableProps = {
partitionKey: {
name: 'table_id',
type: dynamodb.AttributeType.STRING
},
stream: dynamodb.StreamViewType.NEW_IMAGE
};

const existingTableInterface = new dynamodb.Table(stack, 'DynamoTable', tableProps)
;
const newProps = {
existingTableInterface,
existingTableObj: existingTableInterface
};
const app = () => {
defaults.CheckProps(newProps);
};

expect(app).toThrowError('Error - Either provide existingTableInterface or existingTableObj, but not both.\n');
});

0 comments on commit 8f22294

Please sign in to comment.