Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

147 lines
4.7 KiB
TypeScript

import { expectLogic } from 'kea-test-utils'
import api from 'lib/api'
import { AlertState } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import { InsightsFunctionType } from '~/types'
import { AlertType } from '../types'
import { alertsLogic } from './alertsLogic'
const alert = {
id: 'alert-1',
name: 'Checkout conversion dropped',
calculation_interval: 'daily',
condition: {},
config: {},
enabled: true,
insight: { id: 1 },
state: AlertState.NOT_FIRING,
subscribed_users: [],
threshold: { configuration: {} },
} as unknown as AlertType
describe('alertsLogic', () => {
let deleteSpy: jest.SpyInstance
let listSpy: jest.SpyInstance
let insightsFunctionsListSpy: jest.SpyInstance
let updateSpy: jest.SpyInstance
beforeEach(() => {
initKeaTests()
listSpy = jest.spyOn(api.alerts, 'list').mockResolvedValue({ results: [alert], count: 1 })
insightsFunctionsListSpy = jest.spyOn(api.insightsFunctions, 'list').mockResolvedValue({ results: [], count: 0 })
})
afterEach(() => {
deleteSpy?.mockRestore()
listSpy.mockRestore()
insightsFunctionsListSpy.mockRestore()
updateSpy?.mockRestore()
})
it('deletes an alert and reloads the list', async () => {
deleteSpy = jest.spyOn(api.alerts, 'delete').mockResolvedValue()
const logic = alertsLogic()
logic.mount()
await expectLogic(logic).toFinishAllListeners()
await expectLogic(logic, () => logic.actions.deleteAlert(alert)).toFinishAllListeners()
expect(deleteSpy).toHaveBeenCalledWith(alert.id)
expect(listSpy).toHaveBeenCalledTimes(2)
logic.unmount()
})
it('keeps the delete action disabled while deleting', async () => {
let resolveDelete: () => void = () => {}
const deletePromise = new Promise<void>((resolve) => {
resolveDelete = resolve
})
deleteSpy = jest.spyOn(api.alerts, 'delete').mockReturnValue(deletePromise)
const logic = alertsLogic()
logic.mount()
await expectLogic(logic).toFinishAllListeners()
logic.actions.deleteAlert(alert)
expect(logic.values.deletingAlertIds).toEqual(new Set([alert.id]))
resolveDelete()
await expectLogic(logic).toFinishAllListeners().toMatchValues({ deletingAlertIds: new Set() })
logic.unmount()
})
it('keeps the alert toggle loading and patches the latest alert list', async () => {
let resolveUpdate: (updatedAlert: AlertType) => void = () => {}
const updatePromise = new Promise<AlertType>((resolve) => {
resolveUpdate = resolve
})
updateSpy = jest.spyOn(api.alerts, 'update').mockReturnValue(updatePromise)
const logic = alertsLogic()
logic.mount()
await expectLogic(logic).toFinishAllListeners()
logic.actions.toggleAlertEnabled(alert)
expect(updateSpy).toHaveBeenCalledWith(alert.id, { enabled: false })
expect(logic.values.togglingAlertIds).toEqual(new Set([alert.id]))
const alertFromNewerList = { ...alert, id: 'alert-2', name: 'Newer filtered result' }
logic.actions.loadAlertsSuccess({ results: [alert, alertFromNewerList], count: 2 })
resolveUpdate({ ...alert, enabled: false })
await expectLogic(logic)
.toFinishAllListeners()
.toMatchValues({
alertsResponse: {
results: [{ ...alert, enabled: false }, alertFromNewerList],
count: 2,
},
togglingAlertIds: new Set(),
})
logic.unmount()
})
it('counts only enabled destinations for alerts on the current page', async () => {
insightsFunctionsListSpy.mockResolvedValue({
count: 3,
results: [
{
id: 'destination-1',
enabled: true,
filters: { properties: [{ key: 'alert_id', value: alert.id }] },
},
{
id: 'destination-2',
enabled: false,
filters: { properties: [{ key: 'alert_id', value: alert.id }] },
},
{
id: 'destination-for-other-alert',
enabled: true,
filters: { properties: [{ key: 'alert_id', value: 'other-alert' }] },
},
] as unknown as InsightsFunctionType[],
})
const logic = alertsLogic()
logic.mount()
await expectLogic(logic)
.toFinishAllListeners()
.toMatchValues({
alertDestinationCounts: { [alert.id]: 1 },
})
logic.unmount()
})
})