Skip to content

Commit

Permalink
Merge branch 'feat/cdp-internal-events' into feat/cdp-error-events
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Dec 20, 2024
2 parents 0d1356a + 087a7a7 commit 7794fef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
3 changes: 3 additions & 0 deletions posthog/api/hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
TYPES_WITH_COMPILED_FILTERS,
TYPES_WITH_TRANSPILED_FILTERS,
TYPES_WITH_JAVASCRIPT_SOURCE,
HogFunctionType,
)
from posthog.models.plugin import TranspilerError
from posthog.plugins.plugin_server_api import create_hog_invocation_test
Expand Down Expand Up @@ -88,6 +89,8 @@ class HogFunctionSerializer(HogFunctionMinimalSerializer):
template = HogFunctionTemplateSerializer(read_only=True)
masking = HogFunctionMaskingSerializer(required=False, allow_null=True)

type = serializers.ChoiceField(choices=HogFunctionType.choices, required=False, allow_null=True)

class Meta:
model = HogFunction
fields = [
Expand Down
19 changes: 19 additions & 0 deletions posthog/api/test/test_hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,25 @@ def test_inputs_required(self, *args):
"attr": "inputs__url",
}

def test_validation_error_on_invalid_type(self, *args):
payload = {
"name": "Fetch URL",
"hog": "fetch(inputs.url);",
"inputs_schema": [
{"key": "url", "type": "string", "label": "Webhook URL", "required": True},
],
"type": "invalid_type",
}
# Check required
res = self.client.post(f"/api/projects/{self.team.id}/hog_functions/", data={**payload})
assert res.status_code == status.HTTP_400_BAD_REQUEST, res.json()
assert res.json() == {
"type": "validation_error",
"code": "invalid_choice",
"detail": '"invalid_type" is not a valid choice.',
"attr": "type",
}

def test_inputs_mismatch_type(self, *args):
payload = {
"name": "Fetch URL",
Expand Down
21 changes: 2 additions & 19 deletions posthog/migrations/0535_alter_hogfunction_type.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.15 on 2024-12-19 11:01
# Generated by Django 4.2.15 on 2024-12-19 14:58

from django.db import migrations, models

Expand All @@ -12,23 +12,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="hogfunction",
name="type",
field=models.CharField(
blank=True,
choices=[
("destination", "Destination"),
("site_destination", "Site Destination"),
("internal_destination", "Internal Destination"),
("site_app", "Site App"),
("transformation", "Transformation"),
("email", "Email"),
("sms", "Sms"),
("push", "Push"),
("activity", "Activity"),
("alert", "Alert"),
("broadcast", "Broadcast"),
],
max_length=24,
null=True,
),
field=models.CharField(blank=True, max_length=24, null=True),
),
]
2 changes: 1 addition & 1 deletion posthog/models/hog_functions/hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Meta:
deleted = models.BooleanField(default=False)
updated_at = models.DateTimeField(auto_now=True)
enabled = models.BooleanField(default=False)
type = models.CharField(max_length=24, choices=HogFunctionType.choices, null=True, blank=True)
type = models.CharField(max_length=24, null=True, blank=True)

icon_url = models.TextField(null=True, blank=True)

Expand Down

0 comments on commit 7794fef

Please sign in to comment.