: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 { expectLogic } from 'kea-test-utils'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { personalIntegrationsLogic } from './personalIntegrationsLogic'
describe('personalIntegrationsLogic', () => {
let logic: ReturnType<typeof personalIntegrationsLogic.build>
beforeEach(() => {
useMocks({
get: {
'/api/users/@me/integrations/': () => [200, { results: [] }],
'/api/users/@me/integrations/slack/linkable_workspaces/': () => [200, { results: [] }],
},
})
initKeaTests()
logic = personalIntegrationsLogic()
})
afterEach(() => {
jest.useRealTimers()
logic.unmount()
})
it('refreshes on an interval only while a section is subscribed, and stops with the last one', async () => {
jest.useFakeTimers()
logic.mount()
await expectLogic(logic).toDispatchActions(['loadIntegrationsSuccess'])
logic.actions.startPolling()
logic.actions.startPolling()
expect(logic.cache.disposables.registry.has('poll')).toBe(true)
await expectLogic(logic, () => {
jest.advanceTimersByTime(30_000)
}).toDispatchActions(['loadIntegrations'])
logic.actions.stopPolling()
expect(logic.cache.disposables.registry.has('poll')).toBe(true)
logic.actions.stopPolling()
expect(logic.cache.disposables.registry.has('poll')).toBe(false)
})
it('keeps a connection that needs reconnecting in the list but out of the healthy count', async () => {
useMocks({
get: {
'/api/users/@me/integrations/': () => [
200,
{
results: [
{ kind: 'github', installation_id: '1', needs_reauthorization: false },
{
kind: 'github',
installation_id: '2',
needs_reauthorization: true,
needs_reauthorization_at: '2024-01-01T12:00:00Z',
},
],
},
],
},
})
logic.mount()
await expectLogic(logic)
.toDispatchActions(['loadIntegrationsSuccess'])
.toMatchValues({
integrations: expect.arrayContaining([expect.objectContaining({ installation_id: '2' })]),
healthyIntegrations: [expect.objectContaining({ installation_id: '1' })],
})
})
})