Skip to content

Commit

Permalink
test: fix ddb import e2e tests (aws-amplify#8711)
Browse files Browse the repository at this point in the history
Co-authored-by: Ghosh <[email protected]>
  • Loading branch information
2 people authored and akshbhu committed Nov 8, 2021
1 parent a2dd106 commit a5c42fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
21 changes: 5 additions & 16 deletions packages/amplify-e2e-core/src/categories/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,7 @@ export function addDynamoDBWithGSIWithSettings(projectDir: string, settings: Add
const addColumn = (name, type) => {
chain.wait('What would you like to name this column').sendLine(name);

singleSelect(chain.wait('Choose the data type'), type, [
'string',
'number',
'binary',
'boolean',
'list',
'map',
'null',
'string-set',
'number-set',
'binary-set',
]);
chain.wait('Choose the data type').sendCarriageReturn(); // Always selects string
};

const addAnotherColumn = () => {
Expand Down Expand Up @@ -309,23 +298,23 @@ export function addDynamoDBWithGSIWithSettings(projectDir: string, settings: Add

chain.wait('Would you like to add another column').sendConfirmNo();

singleSelect(chain.wait('Choose the data type'), 'pk', ['pk', 'sk', 'gsi-pk', 'gsi-sk', 'title', 'description']);
chain.wait('Choose partition key for the table').sendCarriageReturn(); // choose pk

chain.wait('Do you want to add a sort key to your table').sendConfirmYes();

singleSelect(chain.wait('Choose sort key for the table'), 'sk', ['sk', 'gsi-pk', 'gsi-sk', 'title', 'description']);
chain.wait('Choose sort key for the table').sendCarriageReturn(); // choose sk

chain
.wait('Do you want to add global secondary indexes to your table?')
.sendConfirmYes()
.wait('Provide the GSI name')
.sendLine(settings.gsiName);

singleSelect(chain.wait('Choose partition key for the GSI'), 'gsi-pk', ['sk', 'gsi-pk', 'gsi-sk', 'title', 'description']);
chain.wait('Choose partition key for the GSI').send(KEY_DOWN_ARROW).send(KEY_DOWN_ARROW).sendCarriageReturn(); // choose gsi-pk

chain.wait('Do you want to add a sort key to your global secondary index').sendConfirmYes();

singleSelect(chain.wait('Choose sort key for the GSI'), 'gsi-sk', ['sk', 'gsi-sk', 'title', 'description']);
chain.wait('Choose sort key for the GSI').send(KEY_DOWN_ARROW).send(KEY_DOWN_ARROW).sendCarriageReturn(); // choose gsi-sk

chain
.wait('Do you want to add more global secondary indexes to your table')
Expand Down
27 changes: 20 additions & 7 deletions packages/amplify-e2e-tests/src/import-helpers/expects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import _ from 'lodash';
import { getProjectMeta, getBackendAmplifyMeta, getTeamProviderInfo, getBackendConfig } from 'amplify-e2e-core';
import { AuthProjectDetails, DynamoDBProjectDetails, readRootStack, StorageProjectDetails } from '.';
import { AuthParameters } from 'amplify-category-auth';
import { AuthParameters } from '@aws-amplify/amplify-category-auth';

const ddbAttrTypeMapping = {
string: 'S',
number: 'N',
binary: 'B',
boolean: 'BOOL',
list: 'L',
map: 'M',
null: 'NULL',
'string-set': 'SS',
'number-set': 'NS',
'binary-set': 'BS',
};

export const expectAuthProjectDetailsMatch = (projectDetails: AuthProjectDetails, ogProjectDetails: AuthProjectDetails) => {
expect(projectDetails.parameters.authSelections).toEqual(ogProjectDetails.parameters.authSelections);
Expand Down Expand Up @@ -132,18 +145,18 @@ export const expectDynamoDBProjectDetailsMatch = (projectDetails: DynamoDBProjec
expect(projectDetails.meta.Name).toEqual(ogProjectDetails.meta.Name);
expect(projectDetails.meta.Region).toEqual(ogProjectDetails.meta.Region);
expect(projectDetails.meta.PartitionKeyName).toEqual(ogProjectDetails.meta.PartitionKeyName);
expect(projectDetails.meta.PartitionKeyType).toEqual(ogProjectDetails.meta.PartitionKeyType);
expect(projectDetails.meta.PartitionKeyType).toEqual(ddbAttrTypeMapping[ogProjectDetails.meta.PartitionKeyType]);
expect(projectDetails.meta.SortKeyName).toEqual(ogProjectDetails.meta.SortKeyName);
expect(projectDetails.meta.SortKeyType).toEqual(ogProjectDetails.meta.SortKeyType);
expect(projectDetails.meta.SortKeyType).toEqual(ddbAttrTypeMapping[ogProjectDetails.meta.SortKeyType]);
expect(projectDetails.meta.Arn).toEqual(ogProjectDetails.meta.Arn);
expect(projectDetails.meta.StreamArn).toEqual(ogProjectDetails.meta.StreamArn);

expect(projectDetails.team.tableName).toEqual(ogProjectDetails.meta.Name);
expect(projectDetails.team.region).toEqual(ogProjectDetails.meta.Region);
expect(projectDetails.team.partitionKeyName).toEqual(ogProjectDetails.meta.PartitionKeyName);
expect(projectDetails.team.partitionKeyType).toEqual(ogProjectDetails.meta.PartitionKeyType);
expect(projectDetails.team.partitionKeyType).toEqual(ddbAttrTypeMapping[ogProjectDetails.meta.PartitionKeyType]);
expect(projectDetails.team.sortKeyName).toEqual(ogProjectDetails.meta.SortKeyName);
expect(projectDetails.team.sortKeyType).toEqual(ogProjectDetails.meta.SortKeyType);
expect(projectDetails.team.sortKeyType).toEqual(ddbAttrTypeMapping[ogProjectDetails.meta.SortKeyType]);
expect(projectDetails.team.arn).toEqual(ogProjectDetails.meta.Arn);
expect(projectDetails.team.streamArn).toEqual(ogProjectDetails.meta.StreamArn);
};
Expand All @@ -163,9 +176,9 @@ export const expectDynamoDBLocalAndOGMetaFilesOutputMatching = (projectRoot: str
expect(storageMeta.output.Name).toEqual(ogStorageMeta.output.Name);
expect(storageMeta.output.Region).toEqual(ogStorageMeta.output.Region);
expect(storageMeta.output.PartitionKeyName).toEqual(ogStorageMeta.output.PartitionKeyName);
expect(storageMeta.output.PartitionKeyType).toEqual(ogStorageMeta.output.PartitionKeyType);
expect(storageMeta.output.PartitionKeyType).toEqual(ddbAttrTypeMapping[ogStorageMeta.output.PartitionKeyType]);
expect(storageMeta.output.SortKeyName).toEqual(ogStorageMeta.output.SortKeyName);
expect(storageMeta.output.SortKeyType).toEqual(ogStorageMeta.output.SortKeyType);
expect(storageMeta.output.SortKeyType).toEqual(ddbAttrTypeMapping[ogStorageMeta.output.SortKeyType]);
expect(storageMeta.output.Arn).toEqual(ogStorageMeta.output.Arn);
expect(storageMeta.output.StreamArn).toEqual(ogStorageMeta.output.StreamArn);
};
Expand Down

0 comments on commit a5c42fc

Please sign in to comment.