diff --git a/policy/schema.py b/policy/schema.py index 0055963..5d915c9 100644 --- a/policy/schema.py +++ b/policy/schema.py @@ -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) @@ -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] diff --git a/policy/services.py b/policy/services.py index c9eccf0..fdfcd81 100644 --- a/policy/services.py +++ b/policy/services.py @@ -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__ @@ -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 = {} diff --git a/policy/tests_gql.py b/policy/tests_gql.py index 36c137a..8adc7fb 100644 --- a/policy/tests_gql.py +++ b/policy/tests_gql.py @@ -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)