Skip to content

Commit

Permalink
Fix schema filter name collision bug (#1036)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Jackins <djackins@twilio.com>
  • Loading branch information
danieljackins and danieljackins authored Feb 13, 2024
1 parent b76c679 commit f65c131
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-fireants-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': patch
---

Fix schema-filter bug
45 changes: 43 additions & 2 deletions packages/browser/src/plugins/schema-filter/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const settings: LegacySettings = {
'Braze Web Mode (Actions)': {},
// note that Fullstory's name here doesn't contain 'Actions'
Fullstory: {},
'Google Analytics': {},
'Google Analytics 4 Web': {},
'Segment.io': {},
},
remotePlugins: [
Expand All @@ -35,7 +37,7 @@ const settings: LegacySettings = {
{
// note that Fullstory name contains 'Actions'
name: 'Fullstory (Actions)',
creationName: 'Fullstory (Actions)',
creationName: 'Fullstory',
libraryName: 'fullstoryDestination',
url: 'https://cdn.segment.com/next-integrations/actions/fullstory/35ea1d304f85f3306f48.js',
settings: {
Expand All @@ -49,6 +51,19 @@ const settings: LegacySettings = {
],
},
},
{
name: 'Google Analytics 4 Web',
creationName: 'Google Analytics 4 Web',
libraryName: 'google-analytics-4-webDestination',
url: 'https://cdn.segment.com/next-integrations/actions/google-analytics-4-web/bfab87631cbcb7d70964.js',
settings: {
subscriptions: [
{
partnerAction: 'Custom Event',
},
],
},
},
],
}

Expand Down Expand Up @@ -92,6 +107,11 @@ const fullstory: Plugin = {
name: 'Fullstory (Actions) trackEvent',
}

const ga4: Plugin = {
...trackEvent,
name: 'Google Analytics 4 Web Custom Event',
}

describe('schema filter', () => {
let options: SegmentioSettings
let filterXt: Plugin
Expand All @@ -113,6 +133,7 @@ describe('schema filter', () => {
jest.spyOn(updateUserProfile, 'track')
jest.spyOn(amplitude, 'track')
jest.spyOn(fullstory, 'track')
jest.spyOn(ga4, 'track')
})

describe('plugins and destinations', () => {
Expand Down Expand Up @@ -472,7 +493,7 @@ describe('schema filter', () => {
expect(updateUserProfile.track).toHaveBeenCalled()
})

it('covers different names between remote plugins and integrations', async () => {
it('works when current name differs from creation name', async () => {
const filterXt = schemaFilter(
{
hi: {
Expand Down Expand Up @@ -516,5 +537,25 @@ describe('schema filter', () => {
expect(updateUserProfile.track).toHaveBeenCalled()
expect(fullstory.track).toHaveBeenCalled()
})

it('doesnt block destinations with similar names', async () => {
const filterXt = schemaFilter(
{
hi: {
enabled: true,
integrations: {
'Google Analytics': false,
},
},
},
settings
)

await ajs.register(segment, ga4, filterXt)

await ajs.track('hi')

expect(ga4.track).toHaveBeenCalled()
})
})
})
2 changes: 1 addition & 1 deletion packages/browser/src/plugins/schema-filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function disabledActionDestinations(
const disabledRemotePlugins: string[] = []
;(settings.remotePlugins ?? []).forEach((p: RemotePlugin) => {
disabledIntegrations.forEach((int) => {
if (p.name.includes(int) || int.includes(p.name)) {
if (p.creationName == int) {
disabledRemotePlugins.push(p.name)
}
})
Expand Down

0 comments on commit f65c131

Please sign in to comment.