: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 { MOCK_DEFAULT_ORGANIZATION } from 'lib/api.mock'
import { expectLogic } from 'kea-test-utils'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { membersLogic } from '~/models/membersLogic'
import { initKeaTests } from '~/test/init'
import { inviteLogic } from './inviteLogic'
describe('inviteLogic', () => {
let logic: ReturnType<typeof inviteLogic.build>
beforeEach(async () => {
initKeaTests(true, undefined, undefined, MOCK_DEFAULT_ORGANIZATION)
logic = inviteLogic()
logic.mount()
logic.actions.ensureAllMembersLoaded()
await expectLogic(membersLogic).toDispatchActions(['loadAllMembersSuccess'])
})
afterEach(() => {
logic.unmount()
})
it.each([
['the current user', '[email protected]', true],
['another member, in any letter case', ' [email protected]', true],
['a new person', '[email protected]', false],
])('marks an invite row for %s', async (_description, email, isExistingMember) => {
logic.actions.updateInviteAtIndex({ target_email: email, isValid: true }, 0)
await expectLogic(logic).toMatchValues({
existingMemberInviteRows: [isExistingMember],
canSubmit: !isExistingMember,
})
})
it('keeps the rows and shows no success toast when a blocked invite is submitted', async () => {
const successToast = jest.spyOn(lemonToast, 'success')
logic.actions.updateInviteAtIndex({ target_email: '[email protected]', isValid: true }, 0)
await expectLogic(logic, () => {
logic.actions.inviteTeamMembers()
})
.toFinishAllListeners()
.toMatchValues({
invitesToSend: [expect.objectContaining({ target_email: '[email protected]' })],
})
expect(successToast).not.toHaveBeenCalled()
})
it('shows a message validation error under the field until the message changes', async () => {
logic.actions.inviteTeamMembersFailure('', {
status: 400,
attr: 'message',
code: 'invalid_url',
detail: 'URLs are not allowed in this field.',
})
await expectLogic(logic).toMatchValues({ messageError: 'URLs are not allowed in this field.' })
logic.actions.updateInviteAtIndex({ first_name: 'Jo' }, 0)
await expectLogic(logic).toMatchValues({ messageError: 'URLs are not allowed in this field.' })
logic.actions.updateMessage('no link this time')
await expectLogic(logic).toMatchValues({ messageError: null })
})
})