Fakultas Ilmu Komputer UI

Commit 718e67e0 authored by Mohammad Adli Daffa's avatar Mohammad Adli Daffa
Browse files

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

Pbi 15 pencatatan mustahik read and delete

See merge request !5
parents d8009e5f 847daff1
......@@ -33,3 +33,20 @@ class MustahikMutation(DjangoModelFormMutation):
class Meta:
form_class = MustahikForm
class DeleteMustahik(graphene.Mutation):
class Arguments:
id = graphene.ID()
message = graphene.String()
idMustahik = graphene.ID()
nama = graphene.String()
noKtp = graphene.String()
mustahik = graphene.Field(MustahikType)
def mutate(self, info, id):
mustahik = Mustahik.objects.get(pk=id)
_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
......@@ -6,6 +6,7 @@ from .types import MustahikType
class MustahikQuery(graphene.ObjectType):
mustahiks = graphene.List(MustahikType, statuses=graphene.List(graphene.String))
mustahik = graphene.Field(MustahikType, id=graphene.ID())
def resolve_mustahiks(self, info, statuses=[], **kwargs):
if statuses and len(statuses) > 0:
......@@ -15,3 +16,9 @@ class MustahikQuery(graphene.ObjectType):
return Mustahik.objects.filter(filter)
return Mustahik.objects.all()
def resolve_mustahik(self, info, id):
mustahik = Mustahik.objects.get(pk=id)
if mustahik is not None:
return mustahik
......@@ -233,3 +233,62 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
content = json.loads(response.content)
self.assertEqual(len(content['data']['mustahiks']), 0)
def test_mustahik_mutation_can_delete_mustahik(self):
count = Mustahik.objects.count()
response = self.query(
'''
mutation{
deleteMustahik(id: 3) {
mustahik {
id
name
}
message
idMustahik
nama
noKtp
}
}
''',
)
self.assertResponseNoErrors(response)
content = json.loads(response.content)
self.assertIsNone(content['data']['deleteMustahik']['mustahik'])
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
response = self.query(
'''
query detailMustahikQuery($id:ID){
mustahik(id:$id){
id
name
noKtp
phone
address
province
regency
rt
rw
birthdate
status
familySize
description
}
}
''',
op_name='detailMustahikQuery',
variables={'id':mustahik_id}
)
self.assertResponseNoErrors(response)
content = json.loads(response.content)
self.assertEqual(len(content['data']), 1)
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
......@@ -2,7 +2,7 @@ import graphene
from graphene_django import DjangoObjectType
from .mustahik.mutations import MustahikMutation
from .mustahik.mutations import MustahikMutation, DeleteMustahik
from .mustahik.query import MustahikQuery
ABOUT = 'Si Zakat merupakan sistem informasi untuk membantu masjid dalam \
......@@ -19,6 +19,7 @@ class Query(MustahikQuery, graphene.ObjectType):
class Mutation(graphene.ObjectType):
mustahik_mutation = MustahikMutation.Field()
delete_mustahik = DeleteMustahik.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
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