diff --git a/packages/@aws-cdk/aws-codepipeline-actions/lib/manual-approval-action.ts b/packages/@aws-cdk/aws-codepipeline-actions/lib/manual-approval-action.ts index 3a318011caad3..bd946a205327d 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/lib/manual-approval-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/lib/manual-approval-action.ts @@ -76,13 +76,15 @@ export class ManualApprovalAction extends Action { } return { - configuration: this._notificationTopic - ? { - NotificationArn: this._notificationTopic.topicArn, - CustomData: this.props.additionalInformation, - ExternalEntityLink: this.props.externalEntityLink, - } - : undefined, + configuration: undefinedIfAllValuesAreEmpty({ + NotificationArn: this._notificationTopic?.topicArn, + CustomData: this.props.additionalInformation, + ExternalEntityLink: this.props.externalEntityLink, + }), }; } } + +function undefinedIfAllValuesAreEmpty(object: object): object | undefined { + return Object.values(object).some(v => v !== undefined) ? object : undefined; +} diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/test.manual-approval.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/test.manual-approval.ts new file mode 100644 index 0000000000000..0af9f68823077 --- /dev/null +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/test.manual-approval.ts @@ -0,0 +1,78 @@ +import { expect, haveResourceLike} from '@aws-cdk/assert'; +import * as codepipeline from '@aws-cdk/aws-codepipeline'; +import * as sns from '@aws-cdk/aws-sns'; +import { SecretValue, Stack } from '@aws-cdk/core'; +import { Test } from 'nodeunit'; +import * as cpactions from '../lib'; + +// tslint:disable:object-literal-key-quotes + +export = { + 'manual approval Action': { + 'allows passing an SNS Topic when constructing it'(test: Test) { + const stack = new Stack(); + const topic = new sns.Topic(stack, 'Topic'); + const manualApprovalAction = new cpactions.ManualApprovalAction({ + actionName: 'Approve', + notificationTopic: topic, + }); + const pipeline = new codepipeline.Pipeline(stack, 'pipeline'); + const stage = pipeline.addStage({ stageName: 'stage' }); + stage.addAction(manualApprovalAction); + + test.equal(manualApprovalAction.notificationTopic, topic); + + test.done(); + }, + + 'renders CustomData and ExternalEntityLink even if notificationTopic was not passed'(test: Test) { + const stack = new Stack(); + new codepipeline.Pipeline(stack, 'pipeline', { + stages: [ + { + stageName: 'Source', + actions: [new cpactions.GitHubSourceAction({ + actionName: 'Source', + output: new codepipeline.Artifact(), + oauthToken: SecretValue.plainText('secret'), + owner: 'aws', + repo: 'aws-cdk', + })], + }, + { + stageName: 'Approve', + actions: [ + new cpactions.ManualApprovalAction({ + actionName: 'Approval', + additionalInformation: 'extra info', + externalEntityLink: 'external link', + }), + ], + }, + ], + }); + + expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + "Stages": [ + { + "Name": "Source", + }, + { + "Name": "Approve", + "Actions": [ + { + "Name": "Approval", + "Configuration": { + "CustomData": "extra info", + "ExternalEntityLink": "external link", + }, + }, + ], + }, + ], + })); + + test.done(); + }, + }, +}; diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts index 98441ff3c83a1..5bb4fafc565c6 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts @@ -371,22 +371,6 @@ export = { test.done(); }, - 'manual approval Action': { - 'allows passing an SNS Topic when constructing it'(test: Test) { - const stack = new Stack(); - const topic = new sns.Topic(stack, 'Topic'); - const manualApprovalAction = new cpactions.ManualApprovalAction({ - actionName: 'Approve', - notificationTopic: topic, - }); - stageForTesting(stack).addAction(manualApprovalAction); - - test.equal(manualApprovalAction.notificationTopic, topic); - - test.done(); - }, - }, - 'PipelineProject': { 'with a custom Project Name': { 'sets the source and artifacts to CodePipeline'(test: Test) { @@ -977,8 +961,3 @@ export = { }, }, }; - -function stageForTesting(stack: Stack): codepipeline.IStage { - const pipeline = new codepipeline.Pipeline(stack, 'pipeline'); - return pipeline.addStage({ stageName: 'stage' }); -}