Skip to content

Commit

Permalink
add regression test for single step funnel (#819)
Browse files Browse the repository at this point in the history
* Add regression test for single step funnels

* refine the test!
  • Loading branch information
fuziontech authored May 21, 2020
1 parent 7df967c commit 9c7d7af
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions posthog/api/test/test_funnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ def _movie_event(self, **kwargs):
Element(tag_name='a', href='/movie')
], **kwargs)

def _single_step_funnel(self, properties=None, filters=None):
if filters is None:
filters = {
'events': [
{'id': 'user signed up', 'type': 'events', 'order': 0},
],
}

if properties is not None:
filters.update({
'properties': properties
})

funnel = Funnel.objects.create(
team=self.team,
name='funnel',
filters=filters
)
return funnel

def _basic_funnel(self, properties=None, filters=None):
action_credit_card = Action.objects.create(team=self.team, name='paid')
ActionStep.objects.create(action=action_credit_card, tag_name='button', text='Pay $10')
Expand Down Expand Up @@ -97,6 +117,23 @@ def _basic_funnel(self, properties=None, filters=None):
)
return funnel

def test_funnel_with_single_step(self):
funnel = self._single_step_funnel()

# event
person1_stopped_after_signup = Person.objects.create(distinct_ids=["stopped_after_signup1"], team=self.team)
self._signup_event(distinct_id='stopped_after_signup1')

person2_stopped_after_signup = Person.objects.create(distinct_ids=["stopped_after_signup2"], team=self.team)
self._signup_event(distinct_id='stopped_after_signup2')

with self.assertNumQueries(5):
response = self.client.get('/api/funnel/{}/'.format(funnel.pk)).json()
self.assertEqual(response['steps'][0]['name'], 'user signed up')
self.assertEqual(response['steps'][0]['count'], 2)
# check ordering of people in first step
self.assertEqual(response['steps'][0]['people'], [person1_stopped_after_signup.pk, person2_stopped_after_signup.pk])

def test_funnel_events(self):
funnel = self._basic_funnel()

Expand Down

0 comments on commit 9c7d7af

Please sign in to comment.