Relate issue 40650: test case
authorEduardo Becerra <ebec70@yahoo.com>
Wed, 22 May 2019 11:27:38 +0200
changeset 8558 a330b3387ac5
parent 8557 0aec79ceddc7
child 8559 5189babcc582
Relate issue 40650: test case
src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/creditnote/I40650_VerifyCreditNoteExpirationDate.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/creditnote/I40650_VerifyCreditNoteExpirationDate.java	Wed May 22 11:27:38 2019 +0200
@@ -0,0 +1,111 @@
+/*
+ *************************************************************************
+ * 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):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.mobile.retail.extmodules.selenium.tests.creditnote;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.math.BigDecimal;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.junit.Test;
+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.annotations.TestClassAnnotations;
+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.pack.selenium.TestIdPack;
+
+@TestClassAnnotations(isHighVolumeCompatible = true)
+public class I40650_VerifyCreditNoteExpirationDate extends WebPOSExtModulesTerminalHelper {
+  static String query;
+
+  private final String giftCardInstanceQuery = "select gci.gcnv_giftcard_inst_id as gcId, gci.type, gci.amount as initBal, gci.obgcne_expirationdate as expirationDate, gci.dateordered "
+      + " from gcnv_giftcard_inst gci "
+      + " where gci.c_order_id in (select c_order_id from c_order where documentno = '%s') ";
+
+  @Test
+  public void test() {
+    // Blind Return
+    addProduct();
+    tap(TestIdExtModules.BUTTON_RECEIPT_ROW1);
+    tap(TestIdExtModules.BUTTON_EDIT_RETURNLINE);
+    final String documentNo = BackboneHelper.getDocumentNo();
+    tap(TestIdExtModules.BUTTON_PAY);
+    tap(TestIdExtModules.BUTTON_PAYMENT_CREDITNOTE);
+    tap(TestIdExtModules.BUTTON_PAY_EXACT);
+    verify(TestIdPack.LABEL_RECEIPT_ADDEDPAYMENT_ROW1_NAME, "Credit Note");
+    verify(TestIdPack.LABEL_RECEIPT_ADDEDPAYMENT_ROW1_AMOUNT, "18.90");
+    verify(TestIdExtModules.LABEL_TOTALTOPAY, "-18.90");
+    tap(TestIdExtModules.BUTTON_PAY_DONE);
+
+    query = String.format(giftCardInstanceQuery, documentNo);
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(final ResultSet rs) throws SQLException {
+        final BigDecimal intialBalance = rs.getBigDecimal("initBal").setScale(2);
+        final Date expirationDate = rs.getDate("expirationDate");
+        final Date dateordered = rs.getDate("dateordered");
+        final String type = rs.getString("type");
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(dateordered);
+        cal.add(Calendar.DAY_OF_YEAR, 10);
+
+        assertThat("The Inital Balance is not one of the expected", intialBalance,
+            equalTo(new BigDecimal("18.90")));
+        assertThat("The Type is not one of the expected", type, equalTo("BasedOnCreditNote"));
+        assertThat("The expiration date is not one of the expected", expirationDate, equalTo(cal.getTime()));
+      }
+    }.execute(query, 1);
+  }
+
+  private void addProduct() {
+    tap(TestIdExtModules.BUTTON_SEARCH);
+    write(TestIdPack.FIELD_SEARCH_TEXT, "WVG/L0001");
+    tap(TestIdExtModules.BUTTON_SEARCH_EXECUTE);
+    tap(TestIdExtModules.BUTTON_SEARCHPRODUCT_HEADLAMPULTRALIGHTWVG);
+    verify(TestIdExtModules.LABEL_TOTALTOPAY, "18.90");
+  }
+  
+  @Override
+  public void beforeWithReload() {
+    setExpireTime(10);
+    super.beforeWithReload();
+  }
+  
+  @Override
+  public void afterWithReload() {
+    setExpireTime(0);
+    super.afterWithReload();
+  }
+    
+  private void setExpireTime(long time) {
+    final String sql = "UPDATE ad_org SET em_gcnv_creditnote_timelife = " + time + " WHERE ad_org_id = 'E41B10B390B0430289A00FD6E5CC0CDA'"; 
+    new DatabaseHelperInsertUpdateOrDelete(
+        "Update store Credit Note Configuration")
+         .execute(sql, 1);
+  }
+  
+}
+