Fakultas Ilmu Komputer UI

Commit e3a5a539 authored by Mohammad Adli Daffa's avatar Mohammad Adli Daffa
Browse files

Merge branch 'PBI-16-Pencarian_SDM_dengan_picName' into 'PBI-16-pencatatan_mustahik'

PBI 16 TASK Pencarian SDM dengan PIC Name

See merge request !17
parents 49263b7d f5797bf7
Pipeline #51756 passed with stage
in 18 minutes and 35 seconds
......@@ -16,7 +16,8 @@ class MustahikQuery(graphene.ObjectType):
mustahik = graphene.Field(MustahikType, id=graphene.ID(required=True))
data_sources = graphene.List(
DataSourceType, category=graphene.String(),
name_contains=graphene.String()
name_contains=graphene.String(),
picName_contains=graphene.String()
)
data_source = graphene.Field(DataSourceType, id=graphene.ID(required=True))
......@@ -39,9 +40,13 @@ class MustahikQuery(graphene.ObjectType):
def resolve_mustahik(self, info, id):
return Mustahik.objects.get(pk=id)
def resolve_data_source(self, info, id):
return DataSource.objects.get(pk=id)
def resolve_data_sources(self, info, **kwargs):
category = kwargs.get('category', None)
query = kwargs.get('name_contains', None)
picName = kwargs.get('picName_contains', None)
filter_query = Q()
if category:
filter_query &= Q(category=category)
......@@ -56,7 +61,14 @@ class MustahikQuery(graphene.ObjectType):
| Q(datasourcewarga__village__icontains=query)
)
if picName:
filter_query &= (
Q(datasourcepekerja__pic_name__icontains=picName)
| Q(datasourceinstitusi__pic_name__icontains=picName)
| Q(datasourcewarga__pic_name__icontains=picName)
)
return DataSource.objects.filter(filter_query)
def resolve_data_source(self, info, id):
return DataSource.objects.get(pk=id)
......@@ -479,6 +479,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
self.assertEqual(content['data']['q3']['id'], str(institusi_detail.data_source.pk))
self.assertEqual(content['data']['q3']['detail']['__typename'], 'DataSourceInstitusiType')
def test_data_source_mutation_can_add_new_data_source(self):
existing_data_source_ammount = DataSource.objects.count()
response = self.query(
......@@ -871,3 +872,38 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
datasource_warga = datasource['dataSourceDetail']
kelurahan = datasource_warga.get('village', None)
self.assertIn(kelurahan, ['pinangranti', None])
def test_query_search_by_picname(self):
response = self.query(
'''
{
dataSources(picNameContains:"pic test") {
id
category
dataSourceDetail {
__typename
... on DataSourceInstitusiType {
picName
name
}
... on DataSourcePekerjaType {
picName
profession
location
}
... on DataSourceWargaType {
picName
rt
rw
village
}
}
}
}
''')
self.assertResponseNoErrors(response)
datasources = json.loads(response.content)['data']['dataSources']
for datasource in datasources:
datasourceDetails = datasource['dataSourceDetail']
picName = datasourceDetails.get('picName', None)
self.assertIn(picName, ['pic test', None])
\ No newline at end of file
Markdown is supported
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