Repository: fidals/shopelectro

Issue:
order.es6:234: Test order redirect to ya.kassa
The puzzle `473-f28eab07` from #473 has to be resolved:

https://github.com/fidals/shopelectro/blob/f0e50b7c3b66e1d18f3f8356c245e16167c51fc3/front/js/components/order.es6#L234-L234

The puzzle was created by duker33 on 06-Aug-18. 

Estimate: 30 minutes,     

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is _removed_ from the source code. Here is more about [PDD](http://www.yegor256.com/2009/03/04/pdd.html) and [about me](http://www.yegor256.com/2017/04/05/pdd-in-action.html).


Discussion:
@artemiyds2 @duker33 please pay attention to this new issue.

Resolving patch:
diff --git a/shopelectro/settings/base.py b/shopelectro/settings/base.py
--- a/shopelectro/settings/base.py
+++ b/shopelectro/settings/base.py
@@ -371,3 +371,6 @@ def get_robots_content():
 # Multipliers are related to prices in this order:
 # big/medium/small/retail. First three are wholesale prices.
 PRICE_MULTIPLIERS = 1.0, 1.0, 1.0, 1.0
+
+# default for local tests. Prod's one may differ
+YANDEX_KASSA_LINK = 'https://money.yandex.ru/eshop.xml'


Test patch:
diff --git a/shopelectro/tests/tests_selenium.py b/shopelectro/tests/tests_selenium.py
--- a/shopelectro/tests/tests_selenium.py
+++ b/shopelectro/tests/tests_selenium.py
@@ -604,6 +604,9 @@ def test_feedback_filter(self):
 @helpers.disable_celery
 class OrderPage(helpers.SeleniumTestCase):
 
+    # Ya.Kassa's domain with card processing UI
+    YA_KASSA_INNER_DOMAIN = 'money.yandex.ru'
+
     @staticmethod
     def get_cell(pos, col):
         # table columns mapping: http://prntscr.com/bsv5hp  # Ignore InvalidLinkBear
@@ -647,12 +650,19 @@ def buy_products(self):
                 .format(i)
             ).click()
 
-    def perform_operations_on_cart(self):
-        self.click((By.ID, 'id_payment_type_0'))
+    def select_payment_type(self, payment_type='cash'):
+        # @todo #473:15m Move `payment_type` to dict or dataclass
+        input_item = self.browser.find_element_by_css_selector(
+            f'input[name="payment_type"][value="{payment_type}"]'
+        )
+        input_item.click()
+
+    def append_products_to_cart(self):
+        self.select_payment_type('cash')
         add_one_more = self.click((By.XPATH, self.add_product))
         self.wait.until(EC.staleness_of(add_one_more))
 
-    def fill_and_submit_form(self):
+    def fill_contacts_data(self):
         @helpers.try_again_on_stale_element(3)
         def insert_value(id, keys, expected_keys=''):
             def expected_conditions(browser):
@@ -664,8 +674,10 @@ def expected_conditions(browser):
         insert_value('id_city', 'Санкт-Петербург')
         insert_value('id_phone', '2222222222', expected_keys='+7 (222) 222 22 22')
         insert_value('id_email', 'test@test.test')
+
+    def submit_form(self):
+        # @todo #473:30m Hide all form processing methods to a separated class.
         self.click((By.ID, 'submit-order'))
-        self.wait.until(EC.url_to_be(self.success_order_url))
 
     def test_table_is_presented_if_there_is_some_products(self):
         """If there are some products in cart, we should see them in table on OrderPage."""
@@ -736,8 +748,10 @@ def assert_count(count):
 
     def test_confirm_order(self):
         """After filling the form we should be able to confirm an Order."""
-        self.perform_operations_on_cart()
-        self.fill_and_submit_form()
+        self.append_products_to_cart()
+        self.fill_contacts_data()
+        self.submit_form()
+        self.wait.until(EC.url_to_be(self.success_order_url))
         self.assertEqual(
             self.browser.current_url,
             self.live_server_url + reverse(Page.CUSTOM_PAGES_URL_NAME, args=('order-success', ))
@@ -749,10 +763,12 @@ def test_order_email(self):
             'order-table-product-id')
         clean_codes = [code.text for code in codes]
 
-        self.perform_operations_on_cart()
+        self.append_products_to_cart()
         final_price = self.browser.find_element_by_id('cart-page-sum').text[:-5]
 
-        self.fill_and_submit_form()
+        self.fill_contacts_data()
+        self.submit_form()
+        self.wait.until(EC.url_to_be(self.success_order_url))
         self.assertEqual(len(mail.outbox), 1)
         sent_mail_body = mail.outbox[0].body
 
@@ -778,6 +794,32 @@ def test_order_email(self):
             sent_mail_body
         )
 
+    def test_pay_with_yandex_kassa(self):
+        success_page_domain = self.YA_KASSA_INNER_DOMAIN
+        self.fill_contacts_data()
+        self.select_payment_type('AC')
+        self.submit_form()
+        self.wait.until(EC.url_contains(success_page_domain))
+        self.assertIn(success_page_domain, self.browser.current_url)
+
+    # @todo #489:60m Fix yandex.kassa payment type bug.
+    #  See details in the test case below.
+    @unittest.expectedFailure
+    def test_change_cart_and_pay_with_yandex_kassa(self):
+        """
+        The same as `test_pay_with_yandex_kassa`, but with the detail.
+
+        Appending products to cart on order page
+        suddenly breaks yandex kassa payment type.
+        """
+        success_page_domain = self.YA_KASSA_INNER_DOMAIN
+        self.append_products_to_cart()
+        self.fill_contacts_data()  # Ignore CPDBear
+        self.select_payment_type('AC')
+        self.submit_form()
+        self.wait.until(EC.url_contains(success_page_domain))
+        self.assertIn(success_page_domain, self.browser.current_url)
+
 
 class SitePage(helpers.SeleniumTestCase):