Fakultas Ilmu Komputer UI

Commit c1715945 authored by Naufal Alauddin Hilmi's avatar Naufal Alauddin Hilmi 🍦
Browse files

Merge branch 'PBI-16-TASK-pencarian_mustahik_dengan_SDM' into 'PBI-16-pencatatan_mustahik'

PBI 16 TASK: Pencarian mustahik dengan sdm

See merge request !20
parents 6657d991 df13252d
Pipeline #51913 passed with stage
in 13 minutes and 18 seconds
......@@ -11,7 +11,8 @@ class MustahikQuery(graphene.ObjectType):
mustahiks = graphene.List(
MustahikType,
statuses=graphene.List(graphene.String),
name_contains=graphene.String()
name_contains=graphene.String(),
data_sources=graphene.List(graphene.ID)
)
mustahik = graphene.Field(MustahikType, id=graphene.ID(required=True))
data_sources = graphene.List(
......@@ -23,15 +24,22 @@ class MustahikQuery(graphene.ObjectType):
def resolve_mustahiks(self, info, **kwargs):
statuses = kwargs.get('statuses', None)
data_sources = kwargs.get('data_sources', None)
name_contains = kwargs.get('name_contains', None)
filter_query = Q()
if statuses and len(statuses) > 0:
filter_query |= reduce(
filter_query &= reduce(
lambda a, b: a | b,
[Q(status=status) for status in statuses]
)
if data_sources and len(data_sources) > 0:
filter_query &= reduce(
lambda a, b: a | b,
[Q(data_source=data_source) for data_source in data_sources]
)
if name_contains:
filter_query &= Q(name__icontains=name_contains)
......
......@@ -361,6 +361,44 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
content = json.loads(response.content)
self.assertEqual(len(content['data']['mustahiks']), 0)
def test_mustahiks_query_if_data_sources_provided_should_return_mustahiks_with_coresponding_data_sources(self):
dataSourceId = DataSource.objects.all()[0].id
response = self.query(
'''
query mustahiks($dataSources: [ID]) {
mustahiks(dataSources: $dataSources) {
dataSource {
id
}
}
}
''',
op_name='mustahiks',
variables={'dataSources': [dataSourceId]}
)
content = json.loads(response.content)
self.assertEqual(int(content['data']['mustahiks'][0]['dataSource']['id']), dataSourceId)
def test_mustahiks_query_if_data_sources_provided_has_no_corresponding_mustahiks_it_should_return_empty_list(self):
dataSourceId = 99999
response = self.query(
'''
query mustahiks($dataSources: [ID]) {
mustahiks(dataSources: $dataSources) {
dataSource {
id
}
}
}
''',
op_name='mustahiks',
variables={'dataSources': [dataSourceId]}
)
content = json.loads(response.content)
self.assertEqual(len(content['data']['mustahiks']), 0)
def test_data_sources_query_should_return_list_data_sources(self):
response = self.query(
'''
......
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