@@ -101,6 +101,45 @@ describe('Working with dimensions', () => {
101
101
) ;
102
102
} ) ;
103
103
104
+ it ( 'handles dimension sets with default dimensions and overrides' , ( ) => {
105
+ // Prepare
106
+ const metrics = new Metrics ( {
107
+ namespace : DEFAULT_NAMESPACE ,
108
+ defaultDimensions : {
109
+ environment : 'prod' ,
110
+ region : 'us-east-1' ,
111
+ } ,
112
+ } ) ;
113
+
114
+ // Act
115
+ // Add a dimension set that overrides one of the default dimensions
116
+ metrics . addDimensions ( {
117
+ environment : 'staging' , // This should override the default 'prod' value
118
+ feature : 'search' ,
119
+ } ) ;
120
+
121
+ metrics . addMetric ( 'api_calls' , MetricUnit . Count , 1 ) ;
122
+ metrics . publishStoredMetrics ( ) ;
123
+
124
+ // Assess
125
+ expect ( console . log ) . toHaveEmittedEMFWith (
126
+ expect . objectContaining ( {
127
+ service : 'hello-world' ,
128
+ environment : 'staging' , // Should use the overridden value
129
+ region : 'us-east-1' , // Should keep the default value
130
+ feature : 'search' , // Should add the new dimension
131
+ api_calls : 1 ,
132
+ } )
133
+ ) ;
134
+ expect ( console . log ) . toHaveEmittedMetricWith (
135
+ expect . objectContaining ( {
136
+ Dimensions : [
137
+ [ 'service' , 'environment' , 'region' , 'feature' ] , // Should include all dimensions
138
+ ] ,
139
+ } )
140
+ ) ;
141
+ } ) ;
142
+
104
143
it ( 'adds one dimension to the metric' , ( ) => {
105
144
// Prepare
106
145
const metrics = new Metrics ( {
0 commit comments