Skip to content

Commit

Permalink
test for destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Oct 24, 2024
1 parent 108df5d commit 0a64fb5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugin-server/src/cdp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export type HogFunctionInvocationSerializedCompressed = {

// Mostly copied from frontend types
export type HogFunctionInputSchemaType = {
type: 'string' | 'boolean' | 'dictionary' | 'choice' | 'json' | 'integration' | 'integration_field'
type: 'string' | 'boolean' | 'dictionary' | 'choice' | 'json' | 'integration' | 'integration_field' | 'email'
key: string
label?: string
choices?: { value: string; label: string }[]
Expand Down
34 changes: 28 additions & 6 deletions plugin-server/tests/cdp/hog-function-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ describe('HogFunctionManager', () => {
})
)

hogFunctions.push(
await insertHogFunction(hub.postgres, teamId1, {
name: 'Email Provider team 1',
type: 'email',
inputs_schema: [
{
type: 'email',
key: 'message',
},
],
inputs: {
email: {
value: { from: '[email protected]', to: '[email protected]', subject: 'subject', html: 'text' },
},
},
})
)

hogFunctions.push(
await insertHogFunction(hub.postgres, teamId2, {
name: 'Test Hog Function team 2',
Expand Down Expand Up @@ -89,7 +107,7 @@ describe('HogFunctionManager', () => {
})

it('returns the hog functions', async () => {
let items = manager.getTeamHogFunctions(teamId1)
let items = manager.getTeamHogDestinations(teamId1)

expect(items).toEqual([
{
Expand Down Expand Up @@ -124,6 +142,10 @@ describe('HogFunctionManager', () => {
},
])

const allFunctions = manager.getTeamHogFunctions(teamId1)
expect(allFunctions.length).toEqual(2)
expect(allFunctions.map((f) => f.type).sort()).toEqual(['destination', 'email'])

await hub.db.postgres.query(
PostgresUse.COMMON_WRITE,
`UPDATE posthog_hogfunction SET name='Test Hog Function team 1 updated' WHERE id = $1`,
Expand All @@ -134,7 +156,7 @@ describe('HogFunctionManager', () => {
// This is normally dispatched by django
await manager.reloadHogFunctions(teamId1, [hogFunctions[0].id])

items = manager.getTeamHogFunctions(teamId1)
items = manager.getTeamHogDestinations(teamId1)

expect(items).toMatchObject([
{
Expand All @@ -145,7 +167,7 @@ describe('HogFunctionManager', () => {
})

it('removes disabled functions', async () => {
let items = manager.getTeamHogFunctions(teamId1)
let items = manager.getTeamHogDestinations(teamId1)

expect(items).toMatchObject([
{
Expand All @@ -163,14 +185,14 @@ describe('HogFunctionManager', () => {
// This is normally dispatched by django
await manager.reloadHogFunctions(teamId1, [hogFunctions[0].id])

items = manager.getTeamHogFunctions(teamId1)
items = manager.getTeamHogDestinations(teamId1)

expect(items).toEqual([])
})

it('enriches integration inputs if found and belonging to the team', () => {
const function1Inputs = manager.getTeamHogFunctions(teamId1)[0].inputs
const function2Inputs = manager.getTeamHogFunctions(teamId2)[0].inputs
const function1Inputs = manager.getTeamHogDestinations(teamId1)[0].inputs
const function2Inputs = manager.getTeamHogDestinations(teamId2)[0].inputs

// Only the right team gets the integration inputs enriched
expect(function1Inputs).toEqual({
Expand Down

0 comments on commit 0a64fb5

Please sign in to comment.