Skip to content

Commit

Permalink
Feature/allow target date (#100)
Browse files Browse the repository at this point in the history
* Update schema.py

* test passing
  • Loading branch information
delcroip authored Mar 27, 2024
1 parent a8add75 commit e279d8d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion policy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Query(graphene.ObjectType):
active_or_last_expired_only=graphene.Boolean(),
show_history=graphene.Boolean(),
order_by=graphene.String(),
target_date=graphene.Date(),
)
# TODO: refactoring
# Eligibility is calculated for a Policy... which is bound to a Family (not an Insuree)
Expand Down Expand Up @@ -218,7 +219,8 @@ def resolve_policies_by_family(self, info, **kwargs):
active_or_last_expired_only=kwargs.get(
'active_or_last_expired_only', False),
show_history=kwargs.get('show_history', False),
order_by=kwargs.get('order_by', None)
order_by=kwargs.get('order_by', None),
target_date=kwargs.get('target_date', None)
)
res = ByFamilyService(user=info.context.user).request(req)
return [Query._to_policy_by_family_or_insuree_item(x) for x in res.items]
Expand Down
5 changes: 3 additions & 2 deletions policy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,12 @@ def request(self, by_insuree_request):
@core.comparable
class ByFamilyRequest(object):

def __init__(self, family_uuid, active_or_last_expired_only=False, show_history=False, order_by=None):
def __init__(self, family_uuid, active_or_last_expired_only=False, show_history=False, order_by=None, target_date=None):
self.family_uuid = family_uuid
self.active_or_last_expired_only = active_or_last_expired_only
self.show_history = show_history
self.order_by = order_by
self.target_date = target_date

def __eq__(self, other):
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
Expand All @@ -388,7 +389,7 @@ def __init__(self, user):

def request(self, by_family_request):
res = self.build_query(by_family_request)
res = res.filter(family_uuid=by_family_request.family_uuid)
res = res.filter(family__uuid=by_family_request.family_uuid)
# .distinct('product__code') >> DISTINCT ON fields not supported by MS-SQL
if by_family_request.active_or_last_expired_only:
products = {}
Expand Down
27 changes: 27 additions & 0 deletions policy/tests_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ def test_query_with_variables(self):

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)

def test_family_query_with_variables(self):
response = self.query(
'''
query policiesByFamily($familyUuid: String!, $targetDate: Date! ) {
policiesByFamily(orderBy: "expiryDate",activeOrLastExpiredOnly: true,familyUuid:$familyUuid ,targetDate: $targetDate,first: 5)
{
totalCount
pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor}
edges
{
node
{
policyUuid,productCode,productName,officerCode,officerName,enrollDate,effectiveDate,startDate,expiryDate,status,policyValue,balance,ded,dedInPatient,dedOutPatient,ceiling,ceilingInPatient,ceilingOutPatient
}
}
}
}
''',
headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"},
variables={'familyUuid': str(self.insuree.family.uuid), 'targetDate':"2019-01-01"}
)

content = json.loads(response.content)

# This validates the status code and if you get errors
self.assertResponseNoErrors(response)



Expand Down

0 comments on commit e279d8d

Please sign in to comment.