|
| 1 | +import { initKeaTests } from '~/test/init' |
| 2 | +import { |
| 3 | + CyclotronJobFiltersType, |
| 4 | + HogFunctionTemplateWithSubTemplateType, |
| 5 | + PropertyFilterType, |
| 6 | + PropertyOperator, |
| 7 | +} from '~/types' |
| 8 | + |
| 9 | +import { hogFunctionTemplateListLogic } from './hogFunctionTemplateListLogic' |
| 10 | + |
| 11 | +describe('hogFunctionTemplateListLogic - configuration structure', () => { |
| 12 | + beforeEach(() => { |
| 13 | + initKeaTests() |
| 14 | + }) |
| 15 | + |
| 16 | + it('should wrap filters in configuration object, not spread at top level', () => { |
| 17 | + const alertId = 'test-alert-id-123' |
| 18 | + const getConfigurationOverrides = (): CyclotronJobFiltersType => ({ |
| 19 | + properties: [ |
| 20 | + { |
| 21 | + key: 'alert_id', |
| 22 | + value: alertId, |
| 23 | + operator: PropertyOperator.Exact, |
| 24 | + type: PropertyFilterType.Event, |
| 25 | + }, |
| 26 | + ], |
| 27 | + events: [{ id: '$insight_alert_firing', type: 'events' as const }], |
| 28 | + }) |
| 29 | + |
| 30 | + const logic = hogFunctionTemplateListLogic.build({ |
| 31 | + type: 'destination', |
| 32 | + getConfigurationOverrides, |
| 33 | + }) |
| 34 | + logic.mount() |
| 35 | + |
| 36 | + const template: HogFunctionTemplateWithSubTemplateType = { |
| 37 | + id: 'template-slack', |
| 38 | + name: 'Slack', |
| 39 | + type: 'destination', |
| 40 | + status: 'stable', |
| 41 | + free: true, |
| 42 | + code: 'return event', |
| 43 | + code_language: 'hog', |
| 44 | + sub_template_id: 'insight-alert-firing', |
| 45 | + } |
| 46 | + |
| 47 | + const url = logic.values.urlForTemplate(template) |
| 48 | + expect(url).toBeTruthy() |
| 49 | + |
| 50 | + // Parse URL to verify structure |
| 51 | + const urlObj = new URL(url!, window.location.origin) |
| 52 | + const hashParams = new URLSearchParams(urlObj.hash.substring(1)) |
| 53 | + const configuration = JSON.parse(decodeURIComponent(hashParams.get('configuration') || '{}')) |
| 54 | + |
| 55 | + // filters must be wrapped, not at top level |
| 56 | + expect(configuration).toHaveProperty('filters') |
| 57 | + expect(configuration.filters).toHaveProperty('properties') |
| 58 | + expect(configuration).not.toHaveProperty('properties') // Should not be at top level |
| 59 | + }) |
| 60 | +}) |
0 commit comments