Skip to content

Commit

Permalink
OM-243: added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Aug 20, 2024
1 parent 4de3251 commit 0369735
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion worker_voucher/tests/test_create_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from policyholder.models import PolicyHolderInsuree
from policyholder.tests import create_test_policy_holder
from insuree.models import Insuree
from insuree.test_helpers import generate_random_insuree_number
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 @@ -24,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 = 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 Down Expand Up @@ -64,3 +66,77 @@ def test_create_worker_success(self):
phi = PolicyHolderInsuree.objects.filter(policy_holder=self.policyholder)
self.assertEquals(workers.count(), 1)
self.assertEquals(phi.count(), 1)

def test_create_existing_worker_success(self):
InsureeConfig.reset_validation_settings()
mutation_id = "39g453h5g92h04gh34"
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 = "39g453h5g92h04gh34"
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, None)

def test_create_worker_already_assigned_to_economic_unit(self):
InsureeConfig.reset_validation_settings()
mutation_id = "39g453h5g92h04gh34"
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 0369735

Please sign in to comment.