Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,30 @@ describe('Migration table import validation', () => {
deleteProjectDir(gen1ProjRoot);
});

/*
AttributeDefintions - done
KeySchema
GlobalSecondaryIndexes - done
BillingModeSummary - done
ProvisionedThroughput
StreamSpecification
SSEDescription
DeletionProtectionEnabled
*/

// Test cases for test.each need to be defined before beforeAll.
// The tests cases need data defined in beforeAll.
// Define the test name first then get the definition later (after beforeAll).
// For each test case, there should be a matching key in the test definitions.
// The test definitions include a schema, overrides, and the expected error messages.
const testCases = ['extraGSIOnGen2', 'billingMode'];
const getTestDefinition = (testCaseName: string): [TestDefinition, string, string[]] => {
const testCases = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you derive this with Object.keys(testDefinitions)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to refactor this further since I now realize that the test definition is the same for each test.

'extraGSIOnGen2',
'billingMode',
'keySchema',
'provisionedThroughput',
'streamSpecification',
'sseDescription',
'deletionProtectionEnabled',
];
type TestCase = [
// CloudFormfation test definition
TestDefinition,
// Overrides to apply to the stack. If empty, no overrides are applied.
// The overrides should export a function called applyOverrides that takes an AmplifyGraphqlApi object.
string,
// Expected CloudFormation error messages
string[],
];
const getTestDefinition = (testCaseName: string): TestCase => {
const testDefinitions: Record<string, [TestDefinition, string, string[]]> = {
extraGSIOnGen2: [
{
Expand Down Expand Up @@ -126,6 +132,134 @@ describe('Migration table import validation', () => {
'BillingModeSummary does not match the expected value.\nActual: {"BillingMode":"PAY_PER_REQUEST"}\nExpected: {"BillingMode":"PROVISIONED"}',
],
],
keySchema: [
{
schema: /* GraphQL */ `
type Todo @model @auth(rules: [{ allow: public }]) {
id: ID!
content: String
}
`,
strategy: {
dbType: 'DYNAMODB' as const,
provisionStrategy: 'IMPORTED_AMPLIFY_TABLE' as const,
tableName: dataSourceMapping.Todo,
},
},
`
import { AmplifyGraphqlApi } from '@aws-amplify/graphql-api-construct';
import { BillingMode } from 'aws-cdk-lib/aws-dynamodb';

export const applyOverrides = (api: AmplifyGraphqlApi): void => {
const todoTable = api.resources.cfnResources.additionalCfnResources['Todo'];
todoTable.addOverride('Properties.keySchema', [{ attributeName: 'fakekey', keyType: 'HASH' }]);
};
`,
[
'KeySchema does not match the expected value.\nActual: [{"AttributeName":"id","KeyType":"HASH"}]\nExpected: [{"AttributeName":"fakekey","KeyType":"HASH"}]',
],
],
provisionedThroughput: [
{
schema: /* GraphQL */ `
type Todo @model @auth(rules: [{ allow: public }]) {
id: ID!
content: String
}
`,
strategy: {
dbType: 'DYNAMODB' as const,
provisionStrategy: 'IMPORTED_AMPLIFY_TABLE' as const,
tableName: dataSourceMapping.Todo,
},
},
`
import { AmplifyGraphqlApi } from '@aws-amplify/graphql-api-construct';
import { BillingMode } from 'aws-cdk-lib/aws-dynamodb';

export const applyOverrides = (api: AmplifyGraphqlApi): void => {
const todoTable = api.resources.cfnResources.additionalCfnResources['Todo'];
todoTable.addOverride('Properties.provisionedThroughput', {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5,
});
};
`,
[
'ProvisionedThroughput does not match the expected value.\nActual: {"ReadCapacityUnits":0,"WriteCapacityUnits":0}\nExpected: {"WriteCapacityUnits":5,"ReadCapacityUnits":5}',
],
],
streamSpecification: [
{
schema: /* GraphQL */ `
type Todo @model @auth(rules: [{ allow: public }]) {
id: ID!
content: String
}
`,
strategy: {
dbType: 'DYNAMODB' as const,
provisionStrategy: 'IMPORTED_AMPLIFY_TABLE' as const,
tableName: dataSourceMapping.Todo,
},
},
`
import { AmplifyGraphqlApi } from '@aws-amplify/graphql-api-construct';
import { BillingMode } from 'aws-cdk-lib/aws-dynamodb';

export const applyOverrides = (api: AmplifyGraphqlApi): void => {
const todoTable = api.resources.cfnResources.additionalCfnResources['Todo'];
todoTable.addOverride('Properties.streamSpecification', {
streamViewType: "KEYS_ONLY"
});
};
`,
[
'StreamSpecification does not match the expected value.\nActual: {"StreamEnabled":true,"StreamViewType":"NEW_AND_OLD_IMAGES"}\nExpected: {"StreamEnabled":true,"StreamViewType":"KEYS_ONLY"}',
],
],
sseDescription: [
{
schema: /* GraphQL */ `
type Todo @model @auth(rules: [{ allow: public }]) {
id: ID!
content: String
}
`,
strategy: {
dbType: 'DYNAMODB' as const,
provisionStrategy: 'IMPORTED_AMPLIFY_TABLE' as const,
tableName: dataSourceMapping.Todo,
},
},
'',
['SSEDescription does not match the expected value.\nActual: undefined\nExpected: {"SSEType":"KMS","Status":"ENABLED"}'],
],
deletionProtectionEnabled: [
{
schema: /* GraphQL */ `
type Todo @model @auth(rules: [{ allow: public }]) {
id: ID!
content: String
}
`,
strategy: {
dbType: 'DYNAMODB' as const,
provisionStrategy: 'IMPORTED_AMPLIFY_TABLE' as const,
tableName: dataSourceMapping.Todo,
},
},
`
import { AmplifyGraphqlApi } from '@aws-amplify/graphql-api-construct';
import { BillingMode } from 'aws-cdk-lib/aws-dynamodb';

export const applyOverrides = (api: AmplifyGraphqlApi): void => {
const todoTable = api.resources.cfnResources.additionalCfnResources['Todo'];
todoTable.addOverride('Properties.deletionProtectionEnabled', true);
};
`,
['DeletionProtectionEnabled does not match the expected value.\nActual: false\nExpected: true'],
],
};

return testDefinitions[testCaseName];
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10322,9 +10322,9 @@ async@^2.6.4:
lodash "^4.17.14"

async@^3.2.0, async@^3.2.3, async@^3.2.4:
version "3.2.5"
resolved "https://registry.npmjs.org/async/-/async-3.2.5.tgz#ebd52a8fdaf7a2289a24df399f8d8485c8a46b66"
integrity sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==
version "3.2.6"
resolved "https://registry.npmjs.org/async/-/async-3.2.6.tgz#1b0728e14929d51b85b449b7f06e27c1145e38ce"
integrity sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==

asynciterator.prototype@^1.0.0:
version "1.0.0"
Expand Down