Related to issue 39974: added automated test
authorAlejandro <alekosmp86@gmail.com>
Wed, 23 Jan 2019 14:20:51 -0500
changeset 8118 03de69d63b09
parent 8117 918237bba90f
child 8119 74e8b350af09
Related to issue 39974: added automated test
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I39974_VerifyOverpaymentWith2DifferentPaymentMethods.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I39974_VerifyOverpaymentWith2DifferentPaymentMethods.java	Wed Jan 23 14:20:51 2019 -0500
@@ -0,0 +1,120 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2019 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author alekosmp86@gmail.com
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.payment;
+
+import java.math.BigDecimal;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.SynchronizationMonitor;
+import org.openbravo.test.mobile.retail.mobilecore.selenium.TestIdCore;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+public class I39974_VerifyOverpaymentWith2DifferentPaymentMethods extends WebPOSTerminalHelper {
+  final static String VBS_CREDIT_CARD_PAYMENT_TYPE_ID = "4785B70E9C1048AB9E9E7B26CFEF6E31";
+  final static String VBS_VOUCHER_PAYMENT_TYPE_ID = "5A2A5B8DABCF49759C1D0EE674B2CD04";
+  final static String PRODUCT_A = "Avalanche transceiver";
+  final static String PRODUCT_B = "Balaclava cap";
+
+  @Test
+  public void test() {
+    createLayaway(PRODUCT_A, "129.99");
+    createLayaway(PRODUCT_B, "49.99");
+    tap(TestIdCore.BUTTON_MENU);
+    tap(TestIdPack.BUTTON_MENU_PAYOPENTICKETS);
+    tap(TestIdPack.BUTTON_POPUP_OPENTICKETS_SEARCH);
+    tap(TestIdPack.BUTTON_POPUP_OPENTICKETS_ROW1);
+    tap(TestIdPack.BUTTON_POPUP_OPENTICKETS_ROW2);
+    tap(TestIdPack.BUTTON_POPUP_OPENTICKETS_DONE);
+    isVisible(TestIdPack.LABEL_RECEIPT_PAY_REMAINING, true);
+    verify(TestIdPack.LABEL_RECEIPT_PAY_REMAINING, "179.98€");
+    write(TestIdPack.INPUT_POINTOFSALE, "149.99");
+    tap(TestIdPack.BUTTON_PAYMENT_VOUCHER);
+    write(TestIdPack.INPUT_POINTOFSALE, "30");
+    tap(TestIdPack.BUTTON_PAYMENT_CARD);
+    verify(TestIdPack.LABEL_RECEIPT_PAY_OVERPAYMENT, "0.01€");
+    tap(TestIdPack.BUTTON_PAY_DONE);
+    isVisible(TestIdPack.LABEL_POPUP_TITLE, true);
+    verify(TestIdPack.LABEL_POPUP_TITLE, "Overpayment");
+    tap(TestIdPack.BUTTON_POPUP_OK);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+    verifyPaymentInBackend();
+  }
+
+  public void beforeWithReload() {
+    setAllowOverpayment(VBS_VOUCHER_PAYMENT_TYPE_ID, BigDecimal.ZERO);
+    resetAllowOverpaymentToSampledataValue(VBS_CREDIT_CARD_PAYMENT_TYPE_ID);
+  }
+
+  public void afterWithReload() {
+    resetAllowOverpaymentToSampledataValue(VBS_VOUCHER_PAYMENT_TYPE_ID);
+  }
+
+  private void setAllowOverpayment(String paymentTypeId, BigDecimal overpayLimit) {
+    String sql = String
+        .format(
+            "update obpos_app_payment_type set overpayment_limit = '%s' where obpos_app_payment_type_id = '%s'",
+            overpayLimit, paymentTypeId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+
+  private void resetAllowOverpaymentToSampledataValue(String paymentTypeId) {
+    String sql = String
+        .format(
+            "update obpos_app_payment_type set overpayment_limit = null where obpos_app_payment_type_id = '%s'",
+            paymentTypeId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+
+  private void addProduct(String productName) {
+    // add a product
+    tap(TestIdPack.BUTTON_SEARCH);
+    write(TestIdPack.FIELD_SEARCH_TEXT, productName);
+    TestIdPack.FIELD_SEARCH_TEXT.enyoNode().executeExtension(".waterfall('onchange')");
+    tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
+    tap(TestIdPack.BUTTON_SEARCHPRODUCT_FIRSTROW);
+  }
+
+  private void createLayaway(String product, String price) {
+    tap(TestIdCore.BUTTON_MENU);
+    tap(TestIdPack.BUTTON_MENU_LAYAWAYTHISRECEIPT);
+    addProduct(product);
+    isVisible(TestIdPack.BUTTON_RECEIPT_ROW1, true);
+    tap(TestIdPack.BUTTON_RECEIPT_ROW1);
+    write(TestIdPack.INPUT_POINTOFSALE, price);
+    tap(TestIdPack.BUTTON_KEYPAD_PRICE);
+    verify(TestIdPack.BUTTON_PAY_AMOUNT, price);
+    tap(TestIdPack.BUTTON_PAY);
+    tap(TestIdPack.BUTTON_LAYAWAY);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+  }
+
+  private void verifyPaymentInBackend() {
+
+  }
+}
\ No newline at end of file