:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import api from 'lib/api'
import type { HogQLQueryResponse } from '~/queries/schema/schema-general'
import { loadAppMetricsTimeSeries } from './appMetricsLogic'
describe('app metrics logic', () => {
afterEach(() => {
jest.restoreAllMocks()
})
it('filters a time series to a set of instance ids', async () => {
jest.spyOn(api, 'queryHogQL').mockResolvedValue({ results: [] } as HogQLQueryResponse)
await loadAppMetricsTimeSeries(
{
appSource: 'warehouse_source_sync',
instanceIds: ['schema-1', 'schema-2'],
breakdownBy: 'metric_name',
dateFrom: '2026-10-01T00:00:00Z',
dateTo: '2026-10-02T00:00:00Z',
},
'UTC'
)
expect(jest.mocked(api.queryHogQL).mock.calls[0][0]).toContain("instance_id IN ['schema-1', 'schema-2']")
})
it('keeps ISO offsets that distinguish repeated local hours', async () => {
const labels = ['2026-11-01T01:00:00-07:00', '2026-11-01T01:00:00-08:00']
jest.spyOn(api, 'queryHogQL').mockResolvedValue({
results: [[labels, 'success', [2, 3]]],
} as HogQLQueryResponse)
const result = await loadAppMetricsTimeSeries(
{
appSource: 'hog_flow',
breakdownBy: 'metric_kind',
interval: 'hour',
dateFrom: '2026-11-01T00:00:00-07:00',
dateTo: '2026-11-01T03:00:00-08:00',
},
'US/Pacific'
)
expect(result).toEqual({
labels,
interval: 'hour',
timezone: 'US/Pacific',
series: [{ name: 'success', values: [2, 3] }],
})
})
})