Skip to content

Commit 8e0c7ad

Browse files
committed
tests for variations of custom func sigs
1 parent f2957dc commit 8e0c7ad

File tree

12 files changed

+176
-24
lines changed

12 files changed

+176
-24
lines changed

tests/analyzeGo.test.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test.describe('analyzeGoFile', () => {
2121
assert.ok(amplitudeEvent);
2222
assert.strictEqual(amplitudeEvent.source, 'amplitude');
2323
assert.strictEqual(amplitudeEvent.functionName, 'amplitudeTrack');
24-
assert.strictEqual(amplitudeEvent.line, 44);
24+
assert.strictEqual(amplitudeEvent.line, 52);
2525
assert.deepStrictEqual(amplitudeEvent.properties, {
2626
UserID: { type: 'string' },
2727
name: { type: 'string' },
@@ -35,7 +35,7 @@ test.describe('analyzeGoFile', () => {
3535
assert.ok(segmentEvent);
3636
assert.strictEqual(segmentEvent.source, 'segment');
3737
assert.strictEqual(segmentEvent.functionName, 'segmentTrack');
38-
assert.strictEqual(segmentEvent.line, 21);
38+
assert.strictEqual(segmentEvent.line, 29);
3939
assert.deepStrictEqual(segmentEvent.properties, {
4040
UserId: { type: 'string' },
4141
plan: { type: 'string' },
@@ -47,7 +47,7 @@ test.describe('analyzeGoFile', () => {
4747
assert.ok(mixpanelEvent);
4848
assert.strictEqual(mixpanelEvent.source, 'mixpanel');
4949
assert.strictEqual(mixpanelEvent.functionName, 'mixpanelTrack');
50-
assert.strictEqual(mixpanelEvent.line, 33);
50+
assert.strictEqual(mixpanelEvent.line, 41);
5151
assert.deepStrictEqual(mixpanelEvent.properties, {
5252
DistinctId: { type: 'string' },
5353
plan: { type: 'string' },
@@ -59,7 +59,7 @@ test.describe('analyzeGoFile', () => {
5959
assert.ok(posthogEvent);
6060
assert.strictEqual(posthogEvent.source, 'posthog');
6161
assert.strictEqual(posthogEvent.functionName, 'posthogTrack');
62-
assert.strictEqual(posthogEvent.line, 64);
62+
assert.strictEqual(posthogEvent.line, 72);
6363
assert.deepStrictEqual(posthogEvent.properties, {
6464
DistinctId: { type: 'string' },
6565
login_type: { type: 'string' },
@@ -72,7 +72,7 @@ test.describe('analyzeGoFile', () => {
7272
assert.ok(snowplowEvent);
7373
assert.strictEqual(snowplowEvent.source, 'snowplow');
7474
assert.strictEqual(snowplowEvent.functionName, 'snowplowTrack');
75-
assert.strictEqual(snowplowEvent.line, 81);
75+
assert.strictEqual(snowplowEvent.line, 89);
7676
assert.deepStrictEqual(snowplowEvent.properties, {
7777
Category: { type: 'string' },
7878
Property: { type: 'string' },
@@ -84,7 +84,7 @@ test.describe('analyzeGoFile', () => {
8484
assert.ok(customEvent);
8585
assert.strictEqual(customEvent.source, 'custom');
8686
assert.strictEqual(customEvent.functionName, 'main');
87-
assert.strictEqual(customEvent.line, 105);
87+
assert.strictEqual(customEvent.line, 113);
8888
assert.deepStrictEqual(customEvent.properties, {
8989
userId: { type: 'string' },
9090
foo: { type: 'string' },
@@ -163,7 +163,7 @@ test.describe('analyzeGoFile', () => {
163163
assert.ok(eventMap['Signed Up']);
164164
assert.strictEqual(eventMap['Signed Up'].eventName, 'Signed Up');
165165
assert.strictEqual(eventMap['Signed Up'].source, 'segment');
166-
assert.strictEqual(eventMap['Signed Up'].line, 21);
166+
assert.strictEqual(eventMap['Signed Up'].line, 29);
167167
assert.strictEqual(eventMap['Signed Up'].functionName, 'segmentTrack');
168168
assert.deepStrictEqual(eventMap['Signed Up'].properties, {
169169
UserId: { type: 'string' },
@@ -174,7 +174,7 @@ test.describe('analyzeGoFile', () => {
174174
assert.ok(eventMap['some_event']);
175175
assert.strictEqual(eventMap['some_event'].eventName, 'some_event');
176176
assert.strictEqual(eventMap['some_event'].source, 'mixpanel');
177-
assert.strictEqual(eventMap['some_event'].line, 33);
177+
assert.strictEqual(eventMap['some_event'].line, 41);
178178
assert.strictEqual(eventMap['some_event'].functionName, 'mixpanelTrack');
179179
assert.deepStrictEqual(eventMap['some_event'].properties, {
180180
DistinctId: { type: 'string' },
@@ -185,7 +185,7 @@ test.describe('analyzeGoFile', () => {
185185
assert.ok(eventMap['Button Clicked']);
186186
assert.strictEqual(eventMap['Button Clicked'].eventName, 'Button Clicked');
187187
assert.strictEqual(eventMap['Button Clicked'].source, 'amplitude');
188-
assert.strictEqual(eventMap['Button Clicked'].line, 44);
188+
assert.strictEqual(eventMap['Button Clicked'].line, 52);
189189
assert.strictEqual(eventMap['Button Clicked'].functionName, 'amplitudeTrack');
190190
assert.deepStrictEqual(eventMap['Button Clicked'].properties, {
191191
UserID: { type: 'string' },
@@ -198,7 +198,7 @@ test.describe('analyzeGoFile', () => {
198198
assert.ok(eventMap['user_signed_up']);
199199
assert.strictEqual(eventMap['user_signed_up'].eventName, 'user_signed_up');
200200
assert.strictEqual(eventMap['user_signed_up'].source, 'posthog');
201-
assert.strictEqual(eventMap['user_signed_up'].line, 64);
201+
assert.strictEqual(eventMap['user_signed_up'].line, 72);
202202
assert.strictEqual(eventMap['user_signed_up'].functionName, 'posthogTrack');
203203
assert.deepStrictEqual(eventMap['user_signed_up'].properties, {
204204
DistinctId: { type: 'string' },
@@ -210,7 +210,7 @@ test.describe('analyzeGoFile', () => {
210210
assert.ok(eventMap['add-to-basket']);
211211
assert.strictEqual(eventMap['add-to-basket'].eventName, 'add-to-basket');
212212
assert.strictEqual(eventMap['add-to-basket'].source, 'snowplow');
213-
assert.strictEqual(eventMap['add-to-basket'].line, 81);
213+
assert.strictEqual(eventMap['add-to-basket'].line, 89);
214214
assert.strictEqual(eventMap['add-to-basket'].functionName, 'snowplowTrack');
215215
assert.deepStrictEqual(eventMap['add-to-basket'].properties, {
216216
Category: { type: 'string' },
@@ -221,7 +221,7 @@ test.describe('analyzeGoFile', () => {
221221
assert.ok(eventMap['custom_event']);
222222
assert.strictEqual(eventMap['custom_event'].eventName, 'custom_event');
223223
assert.strictEqual(eventMap['custom_event'].source, 'custom');
224-
assert.strictEqual(eventMap['custom_event'].line, 105);
224+
assert.strictEqual(eventMap['custom_event'].line, 113);
225225
assert.strictEqual(eventMap['custom_event'].functionName, 'main');
226226
assert.deepStrictEqual(eventMap['custom_event'].properties, {
227227
userId: { type: 'string' },
@@ -241,4 +241,20 @@ test.describe('analyzeGoFile', () => {
241241
}
242242
});
243243
});
244+
245+
test('should detect events for all custom function signature variations', async () => {
246+
const variants = [
247+
{ sig: 'customTrackFunction0', event: 'custom_event0' },
248+
{ sig: 'customTrackFunction1(EVENT_NAME, PROPERTIES)', event: 'custom_event1' },
249+
{ sig: 'customTrackFunction2(userId, EVENT_NAME, PROPERTIES)', event: 'custom_event2' },
250+
{ sig: 'customTrackFunction3(EVENT_NAME, PROPERTIES, userEmail)', event: 'custom_event3' },
251+
{ sig: 'customTrackFunction4(userId, EVENT_NAME, userAddress, PROPERTIES, userEmail)', event: 'custom_event4' },
252+
];
253+
254+
for (const { sig, event } of variants) {
255+
const events = await analyzeGoFile(testFilePath, sig);
256+
const found = events.find(e => e.eventName === event && e.source === 'custom');
257+
assert.ok(found, `Should detect ${event} for signature ${sig}`);
258+
}
259+
});
244260
});

tests/analyzeJavaScript.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,20 @@ test.describe('analyzeJsFile', () => {
317317
// Event name is first param, properties are third param
318318
assert.ok(mparticleEvent.properties.order_id);
319319
});
320+
321+
test('should detect events for all custom function signature variations', () => {
322+
const variants = [
323+
{ sig: 'customTrackFunction0', event: 'custom_event0' },
324+
{ sig: 'customTrackFunction1(EVENT_NAME, PROPERTIES)', event: 'custom_event1' },
325+
{ sig: 'customTrackFunction2(userId, EVENT_NAME, PROPERTIES)', event: 'custom_event2' },
326+
{ sig: 'customTrackFunction3(EVENT_NAME, PROPERTIES, userEmail)', event: 'custom_event3' },
327+
{ sig: 'customTrackFunction4(userId, EVENT_NAME, userAddress, PROPERTIES, userEmail)', event: 'custom_event4' },
328+
];
329+
330+
variants.forEach(({ sig, event }) => {
331+
const events = analyzeJsFile(testFilePath, sig);
332+
const found = events.find(e => e.eventName === event && e.source === 'custom');
333+
assert.ok(found, `Should detect ${event} for signature ${sig}`);
334+
});
335+
});
320336
});

tests/analyzePython.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,20 @@ def customTrackFunction(user_id: str, event_name: str, params: Dict[str, Any]) -
313313
// Clean up
314314
fs.unlinkSync(typeTestFile);
315315
});
316+
317+
test('should detect events for all custom function signature variations', async () => {
318+
const variants = [
319+
{ sig: 'customTrackFunction0', event: 'custom_event0' },
320+
{ sig: 'customTrackFunction1(EVENT_NAME, PROPERTIES)', event: 'custom_event1' },
321+
{ sig: 'customTrackFunction2(userId, EVENT_NAME, PROPERTIES)', event: 'custom_event2' },
322+
{ sig: 'customTrackFunction3(EVENT_NAME, PROPERTIES, userEmail)', event: 'custom_event3' },
323+
{ sig: 'customTrackFunction4(userId, EVENT_NAME, userAddress, PROPERTIES, userEmail)', event: 'custom_event4' },
324+
];
325+
326+
for (const { sig, event } of variants) {
327+
const events = await analyzePythonFile(testFilePath, sig);
328+
const found = events.find(e => e.eventName === event && e.source === 'custom');
329+
assert.ok(found, `Should detect ${event} for signature ${sig}`);
330+
}
331+
});
316332
});

tests/analyzeRuby.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,20 @@ test.describe('analyzeRubyFile', () => {
233233
assert.ok(rudderstackEvent);
234234
assert.strictEqual(rudderstackEvent.source, 'rudderstack');
235235
});
236+
237+
test('should detect events for all custom function signature variations', async () => {
238+
const variants = [
239+
{ sig: 'customTrackFunction0', event: 'custom_event0' },
240+
{ sig: 'customTrackFunction1(EVENT_NAME, PROPERTIES)', event: 'custom_event1' },
241+
{ sig: 'customTrackFunction2(userId, EVENT_NAME, PROPERTIES)', event: 'custom_event2' },
242+
{ sig: 'customTrackFunction3(EVENT_NAME, PROPERTIES, userEmail)', event: 'custom_event3' },
243+
{ sig: 'customTrackFunction4(userId, EVENT_NAME, userAddress, PROPERTIES, userEmail)', event: 'custom_event4' },
244+
];
245+
246+
for (const { sig, event } of variants) {
247+
const events = await analyzeRubyFile(testFilePath, sig);
248+
const found = events.find(e => e.eventName === event && e.source === 'custom');
249+
assert.ok(found, `Should detect ${event} for signature ${sig}`);
250+
}
251+
});
236252
});

tests/analyzeTypeScript.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,4 +849,21 @@ test.describe('analyzeTsFile', () => {
849849
documentType: { type: 'string' }
850850
});
851851
});
852+
853+
test('should detect events for all custom function signature variations', () => {
854+
const variants = [
855+
{ sig: 'customTrackFunction0', event: 'custom_event0' },
856+
{ sig: 'customTrackFunction1(EVENT_NAME, PROPERTIES)', event: 'custom_event1' },
857+
{ sig: 'customTrackFunction2(userId, EVENT_NAME, PROPERTIES)', event: 'custom_event2' },
858+
{ sig: 'customTrackFunction3(EVENT_NAME, PROPERTIES, userEmail)', event: 'custom_event3' },
859+
{ sig: 'customTrackFunction4(userId, EVENT_NAME, userAddress, PROPERTIES, userEmail)', event: 'custom_event4' },
860+
];
861+
862+
variants.forEach(({ sig, event }) => {
863+
const program = createProgram(testFilePath);
864+
const events = analyzeTsFile(testFilePath, program, sig);
865+
const found = events.find(e => e.eventName === event && e.source === 'custom');
866+
assert.ok(found, `Should detect ${event} for signature ${sig}`);
867+
});
868+
});
852869
});

tests/fixtures/go/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ func customTrackFunction(userId string, eventName string, params map[string]any)
1616
log.Printf("Custom track: %s - %s - %+v\n", userId, eventName, params)
1717
}
1818

19+
// Stub custom tracking variants for tests
20+
func customTrackFunction0(eventName string, params map[string]any) {}
21+
func customTrackFunction1(eventName string, params map[string]any) {}
22+
func customTrackFunction2(userId string, eventName string, params map[string]any) {}
23+
func customTrackFunction3(eventName string, params map[string]any, userEmail string) {}
24+
func customTrackFunction4(userId string, eventName string, userAddress map[string]any, params map[string]any, userEmail string) {
25+
}
26+
1927
func segmentTrack(userId string) {
2028
client := analytics.New("YOUR_SEGMENT_WRITE_KEY")
2129
client.Enqueue(analytics.Track{
@@ -108,4 +116,11 @@ func main() {
108116
"list": list,
109117
"obj": obj,
110118
})
119+
120+
// Calls for additional custom tracking variants
121+
customTrackFunction0("custom_event0", map[string]any{"foo": "bar"})
122+
customTrackFunction1("custom_event1", map[string]any{"foo": "bar"})
123+
customTrackFunction2("user101", "custom_event2", map[string]any{"foo": "bar"})
124+
customTrackFunction3("custom_event3", map[string]any{"foo": "bar"}, "user@example.com")
125+
customTrackFunction4("user202", "custom_event4", map[string]any{"city": "San Francisco"}, map[string]any{"foo": "bar"}, "user@example.com")
111126
}

tests/fixtures/go/tracking-schema-go.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ events:
88
Signed Up:
99
implementations:
1010
- path: main.go
11-
line: 21
11+
line: 29
1212
function: segmentTrack
1313
destination: segment
1414
properties:
@@ -21,7 +21,7 @@ events:
2121
some_event:
2222
implementations:
2323
- path: main.go
24-
line: 33
24+
line: 41
2525
function: mixpanelTrack
2626
destination: mixpanel
2727
properties:
@@ -34,7 +34,7 @@ events:
3434
Button Clicked:
3535
implementations:
3636
- path: main.go
37-
line: 44
37+
line: 52
3838
function: amplitudeTrack
3939
destination: amplitude
4040
properties:
@@ -51,7 +51,7 @@ events:
5151
user_signed_up:
5252
implementations:
5353
- path: main.go
54-
line: 64
54+
line: 72
5555
function: posthogTrack
5656
destination: posthog
5757
properties:
@@ -66,7 +66,7 @@ events:
6666
add-to-basket:
6767
implementations:
6868
- path: main.go
69-
line: 81
69+
line: 89
7070
function: snowplowTrack
7171
destination: snowplow
7272
properties:
@@ -79,7 +79,7 @@ events:
7979
custom_event:
8080
implementations:
8181
- path: main.go
82-
line: 105
82+
line: 113
8383
function: main
8484
destination: custom
8585
properties:

tests/fixtures/javascript/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,13 @@ customTrackFunction('user999', 'customEvent', {
154154
value: 12345678,
155155
list: ['item1', 'item2', 'item3']
156156
});
157+
158+
// -----------------------------------------------------------------------------
159+
// Additional custom tracking function variants for testing
160+
// -----------------------------------------------------------------------------
161+
162+
customTrackFunction0('custom_event0', { foo: 'bar' });
163+
customTrackFunction1('custom_event1', { foo: 'bar' });
164+
customTrackFunction2('user101', 'custom_event2', { foo: 'bar' });
165+
customTrackFunction3('custom_event3', { foo: 'bar' }, 'user@example.com');
166+
customTrackFunction4('user202', 'custom_event4', { city: 'San Francisco' }, { foo: 'bar' }, 'user@example.com');

tests/fixtures/python/main.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,22 @@ def main() -> None:
156156
posthog_capture("user123", "email", True, "premium")
157157
snowplow_track_events("shop", 2)
158158
customTrackFunction("user999", "custom_event", {"key": "value", "nested": {"a": [1,2,3]}})
159+
160+
# Additional custom tracking function variant calls for testing
161+
customTrackFunction0("custom_event0", {"foo": "bar"})
162+
customTrackFunction1("custom_event1", {"foo": "bar"})
163+
customTrackFunction2("user101", "custom_event2", {"foo": "bar"})
164+
customTrackFunction3("custom_event3", {"foo": "bar"}, "user@example.com")
165+
customTrackFunction4("user202", "custom_event4", {"city": "San Francisco"}, {"foo": "bar"}, "user@example.com")
166+
167+
# Stub variant definitions to satisfy linters (not executed)
168+
169+
def customTrackFunction0(event_name: str, params: Dict[str, Any]) -> None: ...
170+
171+
def customTrackFunction1(event_name: str, params: Dict[str, Any]) -> None: ...
172+
173+
def customTrackFunction2(user_id: str, event_name: str, params: Dict[str, Any]) -> None: ...
174+
175+
def customTrackFunction3(event_name: str, params: Dict[str, Any], user_email: str) -> None: ...
176+
177+
def customTrackFunction4(user_id: str, event_name: str, user_address: Dict[str, Any], params: Dict[str, Any], user_email: str) -> None: ...

tests/fixtures/ruby/main.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,13 @@ def self.track_something
127127
)
128128
end
129129
end
130+
131+
# -----------------------------------------------------------------------------
132+
# Additional custom tracking function variant calls for testing
133+
# -----------------------------------------------------------------------------
134+
135+
customTrackFunction0('custom_event0', { foo: 'bar' })
136+
customTrackFunction1('custom_event1', { foo: 'bar' })
137+
customTrackFunction2('user101', 'custom_event2', { foo: 'bar' })
138+
customTrackFunction3('custom_event3', { foo: 'bar' }, 'user@example.com')
139+
customTrackFunction4('user202', 'custom_event4', { city: 'San Francisco' }, { foo: 'bar' }, 'user@example.com')

0 commit comments

Comments
 (0)