Skip to content

Commit

Permalink
Merge pull request #28 from openimis/feature/OM-243
Browse files Browse the repository at this point in the history
OM-243: added possibility to export workers
  • Loading branch information
malinowskikam authored Aug 20, 2024
2 parents 49012c7 + 91d8cb5 commit c442357
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion worker_voucher/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class Query(ExportableQueryMixin, graphene.ObjectType):
exportable_fields = ['worker_voucher']
exportable_fields = ['worker_voucher', 'worker']
module_name = "worker_voucher"

worker = OrderedDjangoFilterConnectionField(
Expand Down
83 changes: 81 additions & 2 deletions worker_voucher/tests/test_create_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from policyholder.models import PolicyHolderInsuree
from policyholder.tests import create_test_policy_holder
from insuree.models import Insuree
from insuree.test_helpers import create_test_insuree, generate_random_insuree_number
from insuree.apps import InsureeConfig
from worker_voucher.schema import Query, Mutation
from worker_voucher.tests.data.gql_payloads import gql_mutation_create_worker

Expand All @@ -22,13 +24,15 @@ def __init__(self, user):
other_names = None
gender_id = None
dob = None
existing_worker = None

@classmethod
def setUpClass(cls):
super(GQLCreateWorkerTestCase, cls).setUpClass()
cls.user = create_test_interactive_user(username='VoucherTestUser2')
cls.policyholder = create_test_policy_holder()
cls.chf_id = '4455667788'
cls.chf_id = F"{generate_random_insuree_number()}"
cls.existing_worker = create_test_insuree(with_family=False)
cls.last_name = 'Test'
cls.other_names = 'Test'
cls.gender_id = 'M'
Expand All @@ -43,6 +47,7 @@ def setUpClass(cls):
cls.gql_context = cls.GQLContext(cls.user)

def test_create_worker_success(self):
InsureeConfig.reset_validation_settings()
mutation_id = "39g453h5g92h04gh34"
payload = gql_mutation_create_worker % (
self.chf_id,
Expand All @@ -60,4 +65,78 @@ def test_create_worker_success(self):
workers = Insuree.objects.filter(chf_id=self.chf_id)
phi = PolicyHolderInsuree.objects.filter(policy_holder=self.policyholder)
self.assertEquals(workers.count(), 1)
self.assertEquls(phi.count(), 1)
self.assertEquals(phi.count(), 1)

def test_create_existing_worker_success(self):
InsureeConfig.reset_validation_settings()
mutation_id = "39g453h5g92h04gh35"
payload = gql_mutation_create_worker % (
self.existing_worker.chf_id,
self.last_name,
self.other_names,
self.gender_id,
self.dob,
self.policyholder.code,
mutation_id
)

_ = self.gql_client.execute(payload, context=self.gql_context)
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id)
self.assertFalse(mutation_log.error)
workers = Insuree.objects.filter(chf_id=self.existing_worker.chf_id)
phi = PolicyHolderInsuree.objects.filter(policy_holder=self.policyholder)
self.assertEquals(workers.count(), 1)
self.assertEquals(phi.count(), 1)

def test_create_worker_false_not_existing_economic_unit(self):
InsureeConfig.reset_validation_settings()
mutation_id = "39g453h5g92h04gh36"
national_id = F"{generate_random_insuree_number()}"
payload = gql_mutation_create_worker % (
national_id,
self.last_name,
self.other_names,
self.gender_id,
self.dob,
'NOT-EXIST',
mutation_id
)

_ = self.gql_client.execute(payload, context=self.gql_context)
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id)
self.assertTrue(mutation_log.error)
workers = Insuree.objects.filter(chf_id=national_id)
self.assertEquals(workers.count(), 0)

def test_create_worker_already_assigned_to_economic_unit(self):
InsureeConfig.reset_validation_settings()
mutation_id = "39g453h5g92h04gh37"
national_id = F"{generate_random_insuree_number()}"
payload = gql_mutation_create_worker % (
national_id,
self.last_name,
self.other_names,
self.gender_id,
self.dob,
self.policyholder.code,
mutation_id
)

_ = self.gql_client.execute(payload, context=self.gql_context)
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id)
self.assertFalse(mutation_log.error)
workers = Insuree.objects.filter(chf_id=national_id)
phi = PolicyHolderInsuree.objects.filter(policy_holder=self.policyholder)
self.assertEquals(workers.count(), 1)
self.assertEquals(phi.count(), 1)
payload = gql_mutation_create_worker % (
national_id,
self.last_name,
self.other_names,
self.gender_id,
self.dob,
self.policyholder.code,
mutation_id
)
_ = self.gql_client.execute(payload, context=self.gql_context)
self.assertFalse(mutation_log.error)

0 comments on commit c442357

Please sign in to comment.