Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tiina303 committed Jul 18, 2024
1 parent 025d6ec commit 0d0414f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
7 changes: 4 additions & 3 deletions plugin-server/functional_tests/webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
createGroup,
createGroupType,
createHook,
createOrganization,
createOrganizationRaw,
createTeam,
createUser,
Expand Down Expand Up @@ -41,7 +40,9 @@ test.concurrent(`webhooks: fires slack webhook`, async () => {

const distinctId = new UUIDT().toString()

const organizationId = await createOrganization()
const organizationId = await createOrganizationRaw({
available_product_features: `array ['{ "key": "group_analytics", "name": "group_analytics" }'::jsonb]`,
})
const teamId = await createTeam(organizationId, `http://localhost:${server.address()?.port}`)
const user = await createUser(teamId, new UUIDT().toString())
await createGroupType(teamId, 0, 'organization')
Expand Down Expand Up @@ -90,7 +91,7 @@ test.concurrent(`webhooks: fires slack webhook`, async () => {
$current_url: 'http://localhost:8000',
$elements: [{ tag_name: 'div', nth_child: 1, nth_of_type: 2, $el_text: 'text' }],
$set: { email: '[email protected]' },
$group_0: 'TestWebhookOrg',
$groups: { organization: 'TestWebhookOrg' },
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,27 @@ async function addGroupPropertiesToPostIngestionEvent(

for (const [groupType, columnIndex] of Object.entries(groupTypes)) {
const groupKey = (event.properties[`$groups`] || {})[groupType]
if (!groupKey) {
continue
}

const queryString = `SELECT properties FROM posthog_group WHERE team_id = $1 AND group_type_index = $2 AND group_key = $3`
const queryString = `SELECT group_properties FROM posthog_group WHERE team_id = $1 AND group_type_index = $2 AND group_key = $3`

const selectResult: QueryResult = await postgres.query(
PostgresUse.COMMON_READ,
queryString,
[event.teamId, columnIndex, groupKey],
'fetchGroup'
)

const groupProperties = selectResult.rows.length > 0 ? selectResult.rows[0].group_properties : {}

if (groupKey && groupProperties) {
groups[groupType] = {
index: columnIndex,
key: groupKey,
type: groupType,
properties: JSON.parse(groupProperties),
properties: groupProperties,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const clickhouseEvent: RawClickHouseEvent = {
person_id: 'F99FA0A1-E0C2-4CFE-A09A-4C3C4327A4CC',
person_created_at: '2020-02-20 02:15:00' as ClickHouseTimestampSecondPrecision, // Match createEvent ts format
person_properties: '{}',
group0_properties: JSON.stringify({ name: 'PostHog' }),
person_mode: 'full',
}

Expand All @@ -47,6 +46,30 @@ describe('eachMessageWebhooksHandlers', () => {
[],
'testTag'
)
await hub.db.postgres.query(
PostgresUse.COMMON_WRITE,
`
INSERT INTO posthog_group (team_id, group_key, group_type_index, group_properties, created_at, properties_last_updated_at, properties_last_operation, version)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
`,
[
2,
'org_posthog',
0,
JSON.stringify({ name: 'PostHog' }),
new Date().toISOString(),
JSON.stringify({}),
JSON.stringify({}),
1,
],
'upsertGroup'
)
await hub.db.postgres.query(
PostgresUse.COMMON_WRITE,
`UPDATE posthog_team SET slack_incoming_webhook = 'https://webhook.example.com/'`,
[],
'testTag'
)
})

afterEach(async () => {
Expand Down Expand Up @@ -120,7 +143,8 @@ describe('eachMessageWebhooksHandlers', () => {
actionMatcher,
hookCannon,
groupTypeManager,
organizationManager
organizationManager,
hub.postgres
)

// NOTE: really it would be nice to verify that fire has been called
Expand Down

0 comments on commit 0d0414f

Please sign in to comment.