Fakultas Ilmu Komputer UI

Commit 80eb096c authored by Abdurrafi Arief's avatar Abdurrafi Arief
Browse files

Merge branch 'PBI-15-pencatatan_mustahik-read_and_delete' into 'PBI-15-pencatatan_mustahik'

Merge Pbi 15 pencatatan mustahik read and delete (with task search mustahik done) to main pbi-15 branch

See merge request !9
parents 718e67e0 ad3d86cc
......@@ -49,4 +49,6 @@ class DeleteMustahik(graphene.Mutation):
_nama = mustahik.name
_no_ktp = mustahik.no_ktp
mustahik.delete()
return DeleteMustahik(message = "Success", idMustahik=id, nama=_nama, noKtp=_no_ktp)
\ No newline at end of file
return DeleteMustahik(message = "Success", idMustahik=id, nama=_nama, noKtp=_no_ktp)
......@@ -4,9 +4,11 @@ from django.db.models import Q
from .models import Mustahik
from .types import MustahikType
class MustahikQuery(graphene.ObjectType):
mustahiks = graphene.List(MustahikType, statuses=graphene.List(graphene.String))
mustahik = graphene.Field(MustahikType, id=graphene.ID())
mustahikWithName = graphene.Field(lambda: graphene.List(MustahikType), name=graphene.String())
def resolve_mustahiks(self, info, statuses=[], **kwargs):
if statuses and len(statuses) > 0:
......@@ -22,3 +24,10 @@ class MustahikQuery(graphene.ObjectType):
if mustahik is not None:
return mustahik
def resolve_mustahikWithName(self, info, name=""):
if name != "":
return Mustahik.objects.filter(name__icontains=name)
return Mustahik.objects.all()
......@@ -235,10 +235,12 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
def test_mustahik_mutation_can_delete_mustahik(self):
count = Mustahik.objects.count()
mustahik = Mustahik.objects.get(no_ktp='31751234567890')
mustahik_id = mustahik.pk
response = self.query(
'''
mutation{
deleteMustahik(id: 3) {
mutation deleteMustahik($id: ID) {
deleteMustahik(id: $id) {
mustahik {
id
name
......@@ -250,7 +252,10 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
}
}
''',
op_name='deleteMustahik',
variables={'id':mustahik_id}
)
self.assertResponseNoErrors(response)
content = json.loads(response.content)
......@@ -258,6 +263,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
self.assertEquals(content['data']['deleteMustahik']['message'], "Success")
self.assertEquals(Mustahik.objects.count(), count-1)
def test_mustahik_query_can_read_detail_mustahik(self):
mustahik = Mustahik.objects.get(no_ktp='31751234567890')
mustahik_id = mustahik.pk
......@@ -291,4 +297,94 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
self.assertEqual(content['data']['mustahik']['name'], 'mustahik')
self.assertEqual(content['data']['mustahik']['noKtp'], '31751234567890')
self.assertEqual(content['data']['mustahik']['address'], 'Jalan raya depok')
\ No newline at end of file
def test_mustahikWithName_should_return_list_of_mustahik(self):
response = self.query(
'''
query mustahikWithName($name:String){
mustahikWithName(name: $name){
id,
name
}
}
''',
op_name='mustahikWithName',
)
content = json.loads(response.content)
self.assertEqual(len(content['data']['mustahikWithName']),1)
self.assertEqual(content['data']['mustahikWithName'][0]['name'], 'mustahik')
def test_mustahikWithName_if_name_is_set_should_return_list_of_mustahiks_that_contain_the_name(self):
Mustahik.objects.create(
name='test',
no_ktp='11751234567890',
phone='081234567890',
address='Jalan raya depok',
province='Jawa Barat',
regency='Depok',
rt='003',
rw='002',
birthdate=date(1987, 6, 5),
status=Mustahik.Status.YATIM,
family_size=4,
description='desc'
)
Mustahik.objects.create(
name='eslu',
no_ktp='22751234337899',
phone='081234567890',
address='Jalan depok',
province='Jawa Timur',
regency='Bondo',
rt='003',
rw='002',
birthdate=date(1987, 6, 5),
status=Mustahik.Status.YATIM,
family_size=4,
description='desc'
)
response = self.query(
'''
query mustahikWithName($name:String){
mustahikWithName(name: $name){
id,
name
}
}
''',
op_name='mustahikWithName',
variables={'name':'es'}
)
content = json.loads(response.content)
self.assertEqual(len(content['data']['mustahikWithName']), 2)
self.assertEqual(content['data']['mustahikWithName'][0]['name'], 'test')
self.assertEqual(content['data']['mustahikWithName'][1]['name'], 'eslu')
def test_mustahikWithName_if_name_is_not_available_should_return_empty_list(self):
response = self.query(
'''
query mustahikWithName($name:String){
mustahikWithName(name: $name){
id,
name
}
}
''',
op_name='mustahikWithName',
variables={'name':'#'}
)
content = json.loads(response.content)
self.assertEqual(len(content['data']['mustahikWithName']), 0)
......@@ -39,7 +39,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'graphene_django',
'corsheaders',
'sizakat.mustahik'
'sizakat.mustahik',
]
GRAPHENE = {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment