diff --git a/tienda_ilusion/don_confiao/tests/test_payment_methods.py b/tienda_ilusion/don_confiao/tests/test_payment_methods.py new file mode 100644 index 0000000..4fa504d --- /dev/null +++ b/tienda_ilusion/don_confiao/tests/test_payment_methods.py @@ -0,0 +1,23 @@ +from django.test import Client, TestCase + +# from ..models import PaymentMethods + +class TestPaymentMethods(TestCase): + def setUp(self): + self.client = Client() + + def test_keys_in_payment_methods_to_select(self): + response = self.client.get( + '/don_confiao/payment_methods/all/select_format' + ) + methods = response.json() + for method in methods: + self.assertEqual(set(method.keys()), {'text', 'value'}) + + def test_basic_payment_methods_to_select(self): + methods = self.client.get( + '/don_confiao/payment_methods/all/select_format' + ).json() + self.assertIn('CASH', [method.get('value') for method in methods]) + self.assertIn('CONFIAR', [method.get('value') for method in methods]) + self.assertIn('BANCOLOMBIA', [method.get('value') for method in methods]) diff --git a/tienda_ilusion/don_confiao/urls.py b/tienda_ilusion/don_confiao/urls.py index 7469a9a..0f7dc41 100644 --- a/tienda_ilusion/don_confiao/urls.py +++ b/tienda_ilusion/don_confiao/urls.py @@ -27,5 +27,6 @@ urlpatterns = [ path("cuadres", views.reconciliate_jar, name="reconciliations"), path("resumen_compra/", views.purchase_summary, name="purchase_summary"), path("resumen_compra_json/", views.purchase_json_summary, name="purchase_json_summary"), + path("payment_methods/all/select_format", views.payment_methods_to_select, name="payment_methods_to_select"), path('api/', include(router.urls)), ] diff --git a/tienda_ilusion/don_confiao/views.py b/tienda_ilusion/don_confiao/views.py index d338ad0..d332065 100644 --- a/tienda_ilusion/don_confiao/views.py +++ b/tienda_ilusion/don_confiao/views.py @@ -170,6 +170,14 @@ def purchase_json_summary(request, id): return JsonResponse(to_response, safe=False) +def payment_methods_to_select(request): + methods = [ + {'text': choice[1], 'value': choice[0]} + for choice in PaymentMethods.choices + ] + return JsonResponse(methods, safe=False) + + def _mask_phone(phone): digits = str(phone)[-3:] if phone else " " * 3 return "X" * 7 + digits