Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -1,7 +1,15 @@
import { expect } from '@jest/globals';
import { toBeACloudFormationCommand } from './custom-test-matchers';
import { DescribeStackResourcesCommand } from '@aws-sdk/client-cloudformation';

// Mock AWS SDK config loading
jest.mock('@smithy/shared-ini-file-loader', () => ({
loadSharedConfigFiles: jest.fn().mockResolvedValue({
configFile: { default: {} },
credentialsFile: { default: {} },
}),
getProfileName: jest.fn().mockReturnValue('default'),
}));

expect.extend({
toBeACloudFormationCommand,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,34 @@ export const renderStorage = (storageParams: StorageRenderParameters = {}) => {

const postImportStatements = [];

// Remove name parameter - let Gen 2 auto-generate storage names
const amplifyGen1EnvStatement = createVariableStatement(
factory.createVariableDeclaration(
gen2BranchNameVariableName,
undefined,
undefined,
factory.createIdentifier('process.env.AWS_BRANCH ?? "sandbox"'),
),
);
postImportStatements.push(amplifyGen1EnvStatement);

if (storageParams.storageIdentifier) {
const splitStorageIdentifier = storageParams.storageIdentifier.split('-');
const storageNameWithoutBackendEnvName = splitStorageIdentifier.slice(0, -1).join('-');

const storageNameAssignment = createTemplateLiteral(`${storageNameWithoutBackendEnvName}-`, gen2BranchNameVariableName, '');
const nameProperty = factory.createPropertyAssignment(factory.createIdentifier('name'), storageNameAssignment);

// Add comments as leading trivia
ts.addSyntheticLeadingComment(nameProperty, ts.SyntaxKind.SingleLineCommentTrivia, ` Use this bucket name post refactor`, true);
ts.addSyntheticLeadingComment(
nameProperty,
ts.SyntaxKind.SingleLineCommentTrivia,
` name: '${storageParams.storageIdentifier}',`,
true,
);

propertyAssignments.push(nameProperty);
}
if (storageParams.accessPatterns) {
propertyAssignments.push(getAccessPatterns(storageParams.accessPatterns));
}
Expand Down
Loading