Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { initKeaTests } from '~/test/init'
import {
CyclotronJobFiltersType,
HogFunctionTemplateWithSubTemplateType,
PropertyFilterType,
PropertyOperator,
} from '~/types'

import { hogFunctionTemplateListLogic } from './hogFunctionTemplateListLogic'

describe('hogFunctionTemplateListLogic - configuration structure', () => {
beforeEach(() => {
initKeaTests()
})

it('should wrap filters in configuration object, not spread at top level', () => {
const alertId = 'test-alert-id-123'
const getConfigurationOverrides = (): CyclotronJobFiltersType => ({
properties: [
{
key: 'alert_id',
value: alertId,
operator: PropertyOperator.Exact,
type: PropertyFilterType.Event,
},
],
events: [{ id: '$insight_alert_firing', type: 'events' as const }],
})

const logic = hogFunctionTemplateListLogic.build({
type: 'destination',
getConfigurationOverrides,
})
logic.mount()

const template: HogFunctionTemplateWithSubTemplateType = {
id: 'template-slack',
name: 'Slack',
type: 'destination',
status: 'stable',
free: true,
code: 'return event',
code_language: 'hog',
sub_template_id: 'insight-alert-firing',
}

const url = logic.values.urlForTemplate(template)
expect(url).toBeTruthy()

// Parse URL to verify structure
const urlObj = new URL(url!, window.location.origin)
const hashParams = new URLSearchParams(urlObj.hash.substring(1))
const configuration = JSON.parse(decodeURIComponent(hashParams.get('configuration') || '{}'))

// filters must be wrapped, not at top level
expect(configuration).toHaveProperty('filters')
expect(configuration.filters).toHaveProperty('properties')
expect(configuration).not.toHaveProperty('properties') // Should not be at top level
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,17 @@ export const hogFunctionTemplateListLogic = kea<hogFunctionTemplateListLogicType
? getConfigurationOverrides(subTemplate?.sub_template_id)
: null

const filters =
configurationOverrides || subTemplate?.filters
? {
...(subTemplate?.filters ?? {}),
...(configurationOverrides ?? {}),
}
: undefined

const configuration: Record<string, any> = {
...subTemplate,
...configurationOverrides,
...(filters ? { filters } : {}),
}

return combineUrl(
Expand Down
Loading