Skip to content

Commit edeb4a1

Browse files
committed
test: add test for default dimensions with addDimensions
1 parent 5c434a8 commit edeb4a1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

packages/metrics/tests/unit/dimensions.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,45 @@ describe('Working with dimensions', () => {
101101
);
102102
});
103103

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+
104143
it('adds one dimension to the metric', () => {
105144
// Prepare
106145
const metrics = new Metrics({

0 commit comments

Comments
 (0)