1+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ // SPDX-License-Identifier: MIT-0
3+
4+ import { App , Stack } from '@aws-cdk/core' ;
5+ import { ContextOptions } from '../src/common/context-options' ;
6+ import * as trackedConstruct from '../src/common/tracked-construct' ;
7+
8+ import '@aws-cdk/assert/jest' ;
9+
10+ test ( 'tracked construct add tracking code to description if not explicitely disabled' , ( ) => {
11+
12+ // GIVEN
13+ const initialStackDescription = 'My Analytics stack' ;
14+ const trackingCode = 'trackingcode' ;
15+ const testApp = new App ( ) ;
16+ const exampleStack = new Stack ( testApp , 'testTrackedConstruct' , {
17+ description : initialStackDescription ,
18+ } ) ;
19+
20+ // WHEN
21+ new trackedConstruct . TrackedConstruct ( exampleStack , 'MyCoreAnalyticsConstruct' , { trackingCode : trackingCode } ) ;
22+
23+ // THEN
24+ expect ( exampleStack . templateOptions ) . toHaveProperty ( 'description' , `${ initialStackDescription } (${ trackingCode } )` ) ;
25+ } ) ;
26+
27+
28+ test ( 'tracked construct don\'t add tracking code to description if explicitely disabled' , ( ) => {
29+
30+ // GIVEN
31+ const initialStackDescription = 'My Analytics stack' ;
32+ const trackingCode = 'trackingcode' ;
33+ const context : any = { } ;
34+ context [ ContextOptions . DISABLE_CONSTRUCTS_DEPLOYMENT_TRACKING ] = true ;
35+ const testApp = new App ( { context } ) ;
36+ const exampleStack = new Stack ( testApp , 'testTrackedConstruct' , {
37+ description : initialStackDescription ,
38+ } ) ;
39+
40+ // WHEN
41+ new trackedConstruct . TrackedConstruct ( exampleStack , 'MyCoreAnalyticsConstruct' , { trackingCode : trackingCode } ) ;
42+
43+ // THEN
44+ expect ( exampleStack . templateOptions ) . toHaveProperty ( 'description' , initialStackDescription ) ;
45+ } ) ;
0 commit comments