Skip to content

Commit dfb7cb5

Browse files
committed
Add test
1 parent 8d9313a commit dfb7cb5

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

src/services/events/amplitude/amplitude.test.tsx

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import { Config, CoreClient, Event } from '@amplitude/analytics-types'
2+
13
import config from 'config'
24

3-
import { AmplitudeEventTracker, initAmplitude } from './amplitude'
5+
import {
6+
AmplitudeEventTracker,
7+
initAmplitude,
8+
pageViewTrackingSanitization,
9+
} from './amplitude'
410

511
const mockIdentifySet = vi.hoisted(() => vi.fn())
612
const mockIdentifyConstructor = vi.hoisted(() => vi.fn())
@@ -53,6 +59,53 @@ describe('when initAmplitude is called', () => {
5359
})
5460
})
5561

62+
describe('pageViewTrackingSanitization', () => {
63+
it('removes sensitive info from Page Viewed event properties', async () => {
64+
const plugin = pageViewTrackingSanitization()
65+
66+
if (plugin.setup) {
67+
plugin?.setup({} as Config, {} as CoreClient)
68+
}
69+
70+
if (plugin.execute) {
71+
const event = await plugin.execute({
72+
event_type: '[Amplitude] Page Viewed',
73+
event_properties: {
74+
'[Amplitude] Page Counter': 1,
75+
'[Amplitude] Page Domain': 'app.codecov.io',
76+
'[Amplitude] Page Path': '/sensitive/info',
77+
'[Amplitude] Page Location': 'https://app.codecov.io/sensitive/info',
78+
},
79+
} as Event)
80+
expect(event?.event_properties).toMatchObject({
81+
'[Amplitude] Page Counter': 1,
82+
'[Amplitude] Page Domain': 'app.codecov.io',
83+
path: undefined,
84+
})
85+
}
86+
})
87+
88+
it('does not touch other event types', async () => {
89+
const plugin = pageViewTrackingSanitization()
90+
91+
if (plugin.setup) {
92+
plugin?.setup({} as Config, {} as CoreClient)
93+
}
94+
95+
if (plugin.execute) {
96+
const event = await plugin.execute({
97+
event_type: 'Button Clicked',
98+
event_properties: {
99+
'[Amplitude] Page Path': '/sensitive/info',
100+
},
101+
} as Event)
102+
expect(event?.event_properties).toMatchObject({
103+
'[Amplitude] Page Path': '/sensitive/info',
104+
})
105+
}
106+
})
107+
})
108+
56109
describe('AmplitudeEventTracker', () => {
57110
describe('identify', () => {
58111
describe('when identify is called', () => {

src/services/events/amplitude/amplitude.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { providerToInternalProvider } from 'shared/utils/provider'
88
import { eventTracker } from '../events'
99
import { Event, EventContext, EventTracker, Identity } from '../types'
1010

11-
const pageViewTrackingSanitization = (): EnrichmentPlugin => {
11+
export const pageViewTrackingSanitization = (): EnrichmentPlugin => {
1212
return {
1313
name: 'page-view-tracking-sanitization',
1414
type: 'enrichment',

0 commit comments

Comments
 (0)