Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.

Commit b66527c

Browse files
committed
fix: check max attributes based on attributes count and not tags count
1 parent 6548dad commit b66527c

3 files changed

Lines changed: 59 additions & 4 deletions

File tree

src/BatchEventData.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { BatchEventData, Consts } from './BatchEventData';
2+
import * as Logger from './helpers/Logger';
3+
4+
describe('BatchEventData', () => {
5+
it(`handles less than or equal ${Consts.EventDataMaxTags} tags`, () => {
6+
const batchEventData = new BatchEventData();
7+
const spy = jest.spyOn(Logger, 'Log');
8+
9+
for (let i = 1; i <= Consts.EventDataMaxTags; i++) {
10+
batchEventData.addTag(`tag ${i}`);
11+
}
12+
13+
expect(spy).not.toHaveBeenCalled();
14+
});
15+
it(`handles less than or equal ${
16+
Consts.EventDataMaxValues
17+
} attributes`, () => {
18+
const batchEventData = new BatchEventData();
19+
const spy = jest.spyOn(Logger, 'Log');
20+
21+
for (let i = 1; i <= Consts.EventDataMaxValues; i++) {
22+
batchEventData.put(`key_${i}`, 'value');
23+
}
24+
25+
expect(spy).not.toHaveBeenCalled();
26+
});
27+
it(`skips other tags after the first ${Consts.EventDataMaxTags}`, () => {
28+
const batchEventData = new BatchEventData();
29+
const spy = jest.spyOn(Logger, 'Log');
30+
31+
for (let i = 1; i <= Consts.EventDataMaxTags; i++) {
32+
batchEventData.addTag(`tag ${i}`);
33+
}
34+
35+
batchEventData.addTag('too much');
36+
37+
expect(spy).toHaveBeenCalled();
38+
});
39+
it(`skips other attributes after the first ${
40+
Consts.EventDataMaxValues
41+
}`, () => {
42+
const batchEventData = new BatchEventData();
43+
const spy = jest.spyOn(Logger, 'Log');
44+
45+
for (let i = 1; i <= Consts.EventDataMaxValues; i++) {
46+
batchEventData.put(`key_${i}`, 'value');
47+
}
48+
49+
batchEventData.put('too_much', 'value');
50+
51+
expect(spy).toHaveBeenCalled();
52+
});
53+
});

src/BatchEventData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Log from './helpers/Logger';
1+
import { Log } from './helpers/Logger';
22
import { isString, isNumber, isBoolean } from './helpers/TypeHelpers';
33

4-
const Consts = {
4+
export const Consts = {
55
AttributeKeyRegexp: /^[a-zA-Z0-9_]{1,30}$/,
66
EventDataMaxTags: 10,
77
EventDataMaxValues: 10,
@@ -93,7 +93,7 @@ export class BatchEventData {
9393
key = key.toLowerCase();
9494

9595
if (
96-
Object.keys(this._tags).length >= Consts.EventDataMaxValues &&
96+
Object.keys(this._attributes).length >= Consts.EventDataMaxValues &&
9797
!this._attributes.hasOwnProperty(key)
9898
) {
9999
Log(

src/helpers/Logger.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const DEBUG = false;
22

3-
export default function Log(debug: boolean, ...message: any[]) {
3+
export function Log(debug: boolean, ...message: any[]) {
44
const args = ['[Batch]'].concat(Array.prototype.slice.call(arguments, 1));
55
if (DEBUG && debug) {
66
console.debug.apply(console, args);
77
} else if (debug === false) {
88
console.log.apply(console, args);
99
}
1010
}
11+
12+
export default Log;

0 commit comments

Comments
 (0)