Skip to content

Commit f1261cb

Browse files
committed
Respond to comments: include check that values are not blank, and adjust test format.
1 parent 227af70 commit f1261cb

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

packages/performance/src/resources/trace.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ describe('Firebase Performance > trace', () => {
117117
expect(trace.getMetric('cacheHits')).to.eql(600);
118118
});
119119

120-
it("throws error if metric doesn't exist and has invalid name", () => {
120+
it('throws error if metric doesn\'t exist and has invalid name', () => {
121121
expect(() => trace.incrementMetric('_invalidMetric', 1)).to.throw();
122122
});
123123
});
124124

125125
describe('#putMetric', () => {
126-
it('creates new metric if one doesnt exist and has valid name.', () => {
126+
it('creates new metric if one doesn\'t exist and has valid name.', () => {
127127
trace.putMetric('cacheHits', 200);
128128

129129
expect(trace.getMetric('cacheHits')).to.eql(200);
@@ -136,7 +136,7 @@ describe('Firebase Performance > trace', () => {
136136
expect(trace.getMetric('cacheHits')).to.eql(400);
137137
});
138138

139-
it("throws error if metric doesn't exist and has invalid name", () => {
139+
it('throws error if metric doesn\'t exist and has invalid name', () => {
140140
expect(() => trace.putMetric('_invalidMetric', 1)).to.throw();
141141
});
142142
});

packages/performance/src/utils/attribute_utils.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ describe('Firebase Performance > attribute_utils', () => {
176176
});
177177

178178
describe('#isValidCustomAttributeName', () => {
179-
afterEach(() => {
180-
restore();
181-
});
182-
183179
it('returns true when name is valid', () => {
184180
expect(isValidCustomAttributeName('validCustom_Attribute_Name')).to.be
185181
.true;
186182
});
187183

184+
it('returns false when name is blank', () => {
185+
expect(isValidCustomAttributeName('')).to.be.false;
186+
});
187+
188188
it('returns false when name is too long', () => {
189189
expect(
190190
isValidCustomAttributeName('invalid_custom_name_over_forty_characters')
@@ -206,14 +206,14 @@ describe('Firebase Performance > attribute_utils', () => {
206206
});
207207

208208
describe('#isValidCustomAttributeValue', () => {
209-
afterEach(() => {
210-
restore();
211-
});
212-
213209
it('returns true when value is valid', () => {
214210
expect(isValidCustomAttributeValue('valid_attribute_value')).to.be.true;
215211
});
216212

213+
it('returns false when value is blank', () => {
214+
expect(isValidCustomAttributeValue('')).to.be.false;
215+
});
216+
217217
it('returns false when value is too long', () => {
218218
const longAttributeValue =
219219
'too_long_attribute_value_over_one_hundred_characters_too_long_attribute_value_over_one_' +

packages/performance/src/utils/attributes_utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function getEffectiveConnectionType(): EffectiveConnectionType {
9595
}
9696

9797
export function isValidCustomAttributeName(name: string): boolean {
98-
if (name.length > MAX_ATTRIBUTE_NAME_LENGTH) {
98+
if (name.length == 0 || name.length > MAX_ATTRIBUTE_NAME_LENGTH) {
9999
return false;
100100
}
101101
const matchesReservedPrefix = RESERVED_ATTRIBUTE_PREFIXES.some(prefix =>
@@ -105,5 +105,5 @@ export function isValidCustomAttributeName(name: string): boolean {
105105
}
106106

107107
export function isValidCustomAttributeValue(value: string): boolean {
108-
return value.length <= MAX_ATTRIBUTE_VALUE_LENGTH;
108+
return value.length != 0 && value.length <= MAX_ATTRIBUTE_VALUE_LENGTH;
109109
}

packages/performance/src/utils/metric_utils.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { restore } from 'sinon';
1918
import { expect } from 'chai';
2019

2120
import { isValidCustomMetricName } from './metric_utils';
@@ -24,14 +23,14 @@ import '../../test/setup';
2423

2524
describe('Firebase Performance > metric_utils', () => {
2625
describe('#isValidCustomMetricName', () => {
27-
afterEach(() => {
28-
restore();
29-
});
30-
3126
it('returns true when name is valid', () => {
3227
expect(isValidCustomMetricName('validCustom_Metric_Name')).to.be.true;
3328
});
3429

30+
it('returns false when name is blank', () => {
31+
expect(isValidCustomMetricName('')).to.be.false;
32+
});
33+
3534
it('returns false when name is too long', () => {
3635
const longMetricName =
3736
'too_long_metric_name_over_one_hundred_characters_too_long_metric_name_over_one_' +

packages/performance/src/utils/metric_utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const MAX_METRIC_NAME_LENGTH = 100;
1919
const RESERVED_AUTO_PREFIX = '_';
2020

2121
export function isValidCustomMetricName(name: string): boolean {
22-
if (name.length > MAX_METRIC_NAME_LENGTH) {
22+
if (name.length == 0 || name.length > MAX_METRIC_NAME_LENGTH) {
2323
return false;
2424
}
2525
return !name.startsWith(RESERVED_AUTO_PREFIX);

0 commit comments

Comments
 (0)