Related to issue 38438: added automated test
authorAlejandro <alekosmp86@gmail.com>
Thu, 15 Nov 2018 09:24:38 -0500
changeset 7889 deee522cb3c4
parent 7888 691b44f6f8a5
child 7890 2fc2c5f729fe
Related to issue 38438: added automated test
src-test/org/openbravo/test/mobile/core/utils/AllowedErrorsHelper.java
src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/creditnote/I38438_VerifyNoErrorWhenAddCreditNoteFromCustomerOfAnotherStore.java
--- a/src-test/org/openbravo/test/mobile/core/utils/AllowedErrorsHelper.java	Mon Nov 19 12:35:59 2018 +0100
+++ b/src-test/org/openbravo/test/mobile/core/utils/AllowedErrorsHelper.java	Thu Nov 15 09:24:38 2018 -0500
@@ -131,6 +131,8 @@
     testsAllowedToHaveTomcatErrors.add("I39089_VerifySaveAddressInRemoteMode");
     testsAllowedToHaveTomcatErrors.add("I36600_VerifyBPInvoiceAddressEmptyField");
     testsAllowedToHaveTomcatErrors.add("I36701_EnableButtonsInCancellationHook");
+    testsAllowedToHaveTomcatErrors
+        .add("I38438_VerifyNoErrorWhenAddCreditNoteFromCustomerOfAnotherStore");
     // Suite Offline
     // login online
     testsAllowedToHaveTomcatErrors.add("LoginOnlineAllowedFlows");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/creditnote/I38438_VerifyNoErrorWhenAddCreditNoteFromCustomerOfAnotherStore.java	Thu Nov 15 09:24:38 2018 -0500
@@ -0,0 +1,207 @@
+/*
+ *************************************************************************
+ * 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) 2018 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ *
+ *  @author alekosmp86@gmail.com
+ *
+ */
+
+package org.openbravo.test.mobile.retail.extmodules.selenium.tests.creditnote;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.core.utils.OBUtils;
+import org.openbravo.test.mobile.retail.extmodules.selenium.TestIdExtModules;
+import org.openbravo.test.mobile.retail.extmodules.selenium.terminals.WebPOSExtModulesTerminalHelper;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.SynchronizationMonitor;
+import org.openbravo.test.mobile.retail.mobilecore.selenium.TestIdConstructor;
+import org.openbravo.test.mobile.retail.mobilecore.utils.ApplicationWindow;
+import org.openbravo.test.mobile.retail.mobilecore.utils.RetailUtils;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+
+public class I38438_VerifyNoErrorWhenAddCreditNoteFromCustomerOfAnotherStore extends
+    WebPOSExtModulesTerminalHelper {
+  final static String CREDIT_NOTE_PAYMETHOD_ID = "7D5F775034674506B2B01F96B251A56A";
+  final static String VBS_POSTERMINAL_TYPE_ID = "BD39916225594B32A88983899CF05F72";
+  final static String VBS1_POSTERMINAL_ID = "9104513C2D0741D4850AE8493998A7C8";
+  final static String GL_CASH_DIFFERENCE = "1EC5D1EA070F45BEB4C8023631DC4BBE";
+  final static String GL_ITEM_WRITEOFF_ID = "2C62436C613E4C398E7B34A4DED1B726";
+  final static String PRODUCT_NAME = "Balaclava Cap";
+
+  final static String FIN_FINANCIAL_ACCOUNT_ID = RetailUtils.getRandomUUID();
+  final static String FINANCIAL_ACCOUNT_PAYMENT_METHOD_ID = RetailUtils.getRandomUUID();
+  final static String OBPOS_APP_PAYMENT_TYPE_ID = RetailUtils.getRandomUUID();
+  final static String OBPOS_APP_PAYMENT_ID = RetailUtils.getRandomUUID();
+  final static String TEST_CUSTOMER = "TC_" + RetailUtils.getRandomUUID().substring(0, 4);
+
+  public I38438_VerifyNoErrorWhenAddCreditNoteFromCustomerOfAnotherStore() {
+    super("VBS-1", "vallblanca", "openbravo");
+  }
+
+  @Test
+  public void test() {
+    final String VBS_1Uri = OBUtils.getCurrentHref();
+    final String YS_11Uri = VBS_1Uri.replace("VBS-1", "YS-11");
+
+    // create a new customer
+    tap(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    tap(TestIdPack.BUTTON_CUSTOMER_NEW);
+    isVisible(TestIdPack.FIELD_CUSTOMER_NAME, true);
+    write(TestIdPack.FIELD_CUSTOMER_NAME, TEST_CUSTOMER);
+    write(TestIdPack.FIELD_CUSTOMER_ADDRESS_INV_NAME, "TestAddress 123");
+    tap(TestIdPack.BUTTON_CUSTOMER_SAVE);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+
+    // assign customer to ticket
+    isVisible(TestIdPack.BUTTON_CUSTOMER_ASSIGNTOCUSTOMER, true);
+    tap(TestIdPack.BUTTON_CUSTOMER_ASSIGNTOCUSTOMER);
+
+    // insert product
+    addProduct(PRODUCT_NAME);
+    tap(TestIdPack.BUTTON_RECEIPT_ROW1);
+    tap(TestIdPack.BUTTON_EDIT_RETURNLINE);
+    verify(TestIdPack.BUTTON_PAY_AMOUNT, "-169.00");
+
+    // pay with the configured credit note payment
+    tap(TestIdPack.BUTTON_PAY);
+    TestIdConstructor creditNoteButton = new TestIdConstructor("Credit Note_button");
+    isVisible(creditNoteButton, true);
+    tap(creditNoteButton);
+    tap(TestIdPack.BUTTON_PAY_EXACT);
+    tap(TestIdPack.BUTTON_PAY_DONE);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+
+    // change terminal
+    changeTerminal(YS_11Uri);
+    logIn();
+    waitUntilCertainWindowIsReached(ApplicationWindow.POINTOFSALE);
+
+    // add product and return it
+    addProduct(PRODUCT_NAME);
+    tap(TestIdPack.BUTTON_RECEIPT_ROW1);
+    tap(TestIdPack.BUTTON_EDIT_RETURNLINE);
+    verify(TestIdPack.BUTTON_PAY_AMOUNT, "-169.00");
+
+    // pay it with credit note
+    tap(TestIdPack.BUTTON_PAY);
+    isVisible(TestIdExtModules.BUTTON_PAYMENT_CREDITNOTE, true);
+    tap(TestIdExtModules.BUTTON_PAYMENT_CREDITNOTE);
+    tap(TestIdPack.BUTTON_PAY_EXACT);
+    tap(TestIdPack.BUTTON_PAY_DONE);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+
+    // verify no errors
+    verifyThereAreNoErrors();
+
+    // change to initial terminal
+    changeTerminal(VBS_1Uri);
+    logIn();
+  }
+
+  public void beforeWithReload() {
+    createFinancialAccountForTest();
+    addPaymentMethodToFinancialAccount();
+    addPaymentMethodToPOSTerminalType(VBS_POSTERMINAL_TYPE_ID, CREDIT_NOTE_PAYMETHOD_ID);
+    addPaymentMethodToPOSTerminal(VBS1_POSTERMINAL_ID, CREDIT_NOTE_PAYMETHOD_ID);
+  }
+
+  public void afterWithReload() {
+
+  }
+
+  private void addPaymentMethodToPOSTerminalType(String terminalTypeId, String paymentMethodId) {
+    String clientId = BackboneHelper.getTerminalValue("client");
+    String orgId = BackboneHelper.getTerminalValue("organization");
+    String sql = String
+        .format(
+            "insert into obpos_app_payment_type (obpos_app_payment_type_id, ad_client_id, ad_org_id, createdby, updatedby,"
+                + " value, name, fin_paymentmethod_id, c_currency_id, obpos_terminaltype_id, automatemovementtoother, keepfixedamount, "
+                + "allowvariableamount, allowdontmove, allowmoveeverything, c_glitem_diff_id, allowdrops, allowdeposits, c_glitem_writeoff_id, countpaymentincashup) "
+                + "values ('%s', '%s', '%s', '100', '100', 'VBS_CreditNote', 'VBS_CreditNote', '%s', '102', '%s', 'N', 'N', 'N', 'N', 'N', '%s',"
+                + "'N', 'N', '%s', 'N')", OBPOS_APP_PAYMENT_TYPE_ID, clientId, orgId,
+            CREDIT_NOTE_PAYMETHOD_ID, VBS_POSTERMINAL_TYPE_ID, GL_CASH_DIFFERENCE,
+            GL_ITEM_WRITEOFF_ID);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+
+  private void addPaymentMethodToPOSTerminal(String terminalTypeId, String paymentMethodId) {
+    String clientId = BackboneHelper.getTerminalValue("client");
+    String orgId = BackboneHelper.getTerminalValue("organization");
+    String sql = String
+        .format(
+            "insert into obpos_app_payment (obpos_app_payment_id, ad_client_id, ad_org_id, createdby, updatedby, value, name, obpos_applications_id, "
+                + "obpos_app_payment_type_id, fin_financial_account_id) values ('%s', '%s', '%s', '100', '100', 'Credit Note', 'Credit Note', '%s', '%s', '%s')",
+            OBPOS_APP_PAYMENT_ID, clientId, orgId, VBS1_POSTERMINAL_ID, OBPOS_APP_PAYMENT_TYPE_ID,
+            FIN_FINANCIAL_ACCOUNT_ID);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+
+  private void createFinancialAccountForTest() {
+    String clientId = BackboneHelper.getTerminalValue("client");
+    String orgId = BackboneHelper.getTerminalValue("organization");
+    String sql = String
+        .format(
+            "insert into fin_financial_account (fin_financial_account_id, ad_client_id, ad_org_id, createdby, updatedby, c_currency_id, name) values ('%s', '%s', '%s', '100', '100', '102', 'Test Financial Account')",
+            FIN_FINANCIAL_ACCOUNT_ID, clientId, orgId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+
+  private void addPaymentMethodToFinancialAccount() {
+    String clientId = BackboneHelper.getTerminalValue("client");
+    String orgId = BackboneHelper.getTerminalValue("organization");
+    String sql = String
+        .format(
+            "insert into fin_finacc_paymentmethod (fin_finacc_paymentmethod_id, ad_client_id, ad_org_id, createdby, updatedby, fin_paymentmethod_id, fin_financial_account_id) values ('%s', '%s', '%s', '100', '100', '%s', '%s')",
+            FINANCIAL_ACCOUNT_PAYMENT_METHOD_ID, clientId, orgId, CREDIT_NOTE_PAYMETHOD_ID,
+            FIN_FINANCIAL_ACCOUNT_ID);
+
+    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 verifyThereAreNoErrors() {
+    String sql = String
+        .format("select 1 from obpos_errors where error like '%s'",
+            "through its property obposAppCashup but this referenced entity belongs to an organization");
+
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(ResultSet rs) throws SQLException {
+      }
+    }.execute(sql, 0);
+  }
+}
\ No newline at end of file