Skip to content

Commit 16e54c8

Browse files
committed
task: show alternative price and currency during a series import.
Also update the integration test to check for alternative price and currency. Part of #1230
1 parent b224fd4 commit 16e54c8

File tree

10 files changed

+99
-20
lines changed

10 files changed

+99
-20
lines changed

src/main/java/ru/mystamps/web/feature/series/importing/ImportSeriesSalesForm.java

+7-14
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,22 @@ public class ImportSeriesSalesForm implements AddSeriesSalesDto {
4343
@NotNull
4444
private Currency currency;
4545

46+
// CheckStyle: ignore LineLength for next 1 line
47+
// @todo #1230 /series/import/request/{id}: validate that both alt price/currency are present or absent
48+
private BigDecimal altPrice;
49+
private Currency altCurrency;
50+
4651
// We don't expose these fields to a form because we know already what
4752
// values should be. Even if user will try to provide its own values, it's not
4853
// a problem as we always rewrite them in the controller.
4954
private Date date;
5055
private String url;
5156

5257
//
53-
// The methods bellow required for AddSeriesSalesDto interface.
54-
// They are no-op methods because we don't support all values during series import.
58+
// The method below is required for AddSeriesSalesDto interface.
59+
// It is no-op method because we don't support all values during series import.
5560
//
5661

57-
// For future: altPrice is required when altCurrency is specified
58-
@Override
59-
public BigDecimal getAltPrice() {
60-
return null;
61-
}
62-
63-
// For future: altCurrency is required when altPrice is specified
64-
@Override
65-
public Currency getAltCurrency() {
66-
return null;
67-
}
68-
6962
@Override
7063
public Integer getBuyerId() {
7164
return null;

src/main/java/ru/mystamps/web/feature/series/importing/SeriesImportController.java

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public String showRequestAndImportSeriesForm(
167167
seriesSaleForm.setSellerId(seriesSale.getSellerId());
168168
seriesSaleForm.setPrice(seriesSale.getPrice());
169169
seriesSaleForm.setCurrency(seriesSale.getCurrency());
170+
seriesSaleForm.setAltPrice(seriesSale.getAltPrice());
171+
seriesSaleForm.setAltCurrency(seriesSale.getAltCurrency());
170172

171173
ImportSellerForm sellerForm = new ImportSellerForm();
172174
sellerForm.setName(seriesSale.getSellerName());

src/main/java/ru/mystamps/web/feature/series/importing/sale/RowMappers.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ private RowMappers() {
3939
String sellerUrl = rs.getString("seller_url");
4040
BigDecimal price = rs.getBigDecimal("price");
4141
Currency currency = JdbcUtils.getCurrency(rs, "currency");
42+
BigDecimal altPrice = rs.getBigDecimal("alt_price");
43+
Currency altCurrency = JdbcUtils.getCurrency(rs, "alt_currency");
4244

4345
return new SeriesSaleParsedDataDto(
4446
sellerId,
4547
sellerGroupId,
4648
sellerName,
4749
sellerUrl,
4850
price,
49-
currency
51+
currency,
52+
altPrice,
53+
altCurrency
5054
);
5155
}
5256

src/main/java/ru/mystamps/web/feature/series/importing/sale/SeriesSaleParsedDataDto.java

+2
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ public class SeriesSaleParsedDataDto {
3232
private final String sellerUrl;
3333
private final BigDecimal price;
3434
private final Currency currency;
35+
private final BigDecimal altPrice;
36+
private final Currency altCurrency;
3537
}

src/main/resources/liquibase/version/0.4/2018-12-03--site_parsers.xml

+12
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@
155155
<column name="value" value="RUB" />
156156
</insert>
157157

158+
<insert tableName="site_parser_params">
159+
<column name="parser_id" valueComputed="(SELECT id FROM site_parsers WHERE name = 'mockserver')" />
160+
<column name="name" value="alt-price-locator" />
161+
<column name="value" value="#alt-price" />
162+
</insert>
163+
164+
<insert tableName="site_parser_params">
165+
<column name="parser_id" valueComputed="(SELECT id FROM site_parsers WHERE name = 'mockserver')" />
166+
<column name="name" value="alt-currency-locator" />
167+
<column name="value" value="#alt-currency" />
168+
</insert>
169+
158170
</changeSet>
159171

160172
</databaseChangeLog>

src/main/resources/sql/series_import_request_dao_queries.properties

+2
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,7 @@ SELECT seller_id \
178178
, seller_name \
179179
, price \
180180
, currency \
181+
, alt_price \
182+
, alt_currency \
181183
FROM series_sales_import_parsed_data \
182184
WHERE request_id = :request_id

src/main/webapp/WEB-INF/views/series/import/info.html

+57
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,63 @@ <h3 th:text="#{t_gathered_data}">
495495
</td>
496496
</tr>
497497

498+
<tr th:if="${hasSalesInfo and (importSeriesForm.seriesSale.altPrice != null or !disabled)}"
499+
th:classappend="${#fields.hasErrors('seriesSale.altPrice') or #fields.hasErrors('seriesSale.altCurrency') ? 'has-error' : ''}">
500+
<th>
501+
<label for="alt-price" class="control-label" th:text="#{t_alternative_price}">
502+
Alternative price
503+
</label>
504+
</th>
505+
<td>
506+
<table>
507+
<tr>
508+
<td width="30%">
509+
<input id="alt-price"
510+
type="text"
511+
class="form-control"
512+
size="5"
513+
value="2300"
514+
th:field="*{seriesSale.altPrice}"
515+
th:disabled="${disabled}" />
516+
</td>
517+
<td width="30%">
518+
<select id="alt-currency" class="form-control" th:field="*{seriesSale.altCurrency}" th:disabled="${disabled}">
519+
<option value=""></option>
520+
<option value="USD">USD</option>
521+
<option value="EUR">EUR</option>
522+
<option value="GBP">GBP</option>
523+
<option value="RUB">RUB</option>
524+
<option value="CZK" selected="selected">CZK</option>
525+
<option value="BYN">BYN</option>
526+
<option value="UAH">UAH</option>
527+
</select>
528+
</td>
529+
<td width="40%"></td>
530+
</tr>
531+
<!--/*/
532+
<tr>
533+
<td>
534+
<span id="alt-price.errors"
535+
class="help-block"
536+
th:if="${#fields.hasErrors('seriesSale.altPrice')}"
537+
th:each="error : ${#fields.errors('seriesSale.altPrice')}"
538+
th:text="${error}"></span>
539+
</td>
540+
</tr>
541+
<tr>
542+
<td>
543+
<span id="alt-currency.errors"
544+
class="help-block"
545+
th:if="${#fields.hasErrors('seriesSale.altCurrency')}"
546+
th:each="error : ${#fields.errors('seriesSale.altCurrency')}"
547+
th:text="${error}"></span>
548+
</td>
549+
</tr>
550+
/*/-->
551+
</table>
552+
</td>
553+
</tr>
554+
498555
<tr th:unless="${disabled}">
499556
<td></td>
500557
<td>

src/test/java/ru/mystamps/web/service/TestObjects.java

+3
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ public static SeriesSaleParsedDataDto createSeriesSaleParsedDataDto() {
395395
sellerName,
396396
sellerUrl,
397397
Random.price(),
398+
Random.currency(),
399+
Random.price(),
400+
// FIXME: alternative currency shouldn't match with currency
398401
Random.currency()
399402
);
400403
}

src/test/robotframework/series/import/request-logic.robot

+8-4
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,24 @@ Import series and series sale with existing seller from an external site
9393
Submit Form id:import-series-form
9494
${requestLocation}= Get Location
9595
# sale info should be parsed and shown at the request page
96-
List Selection Should Be id:seller Eicca Toppinen
97-
Textfield Value Should Be id:price 111
98-
List Selection Should Be id:currency RUB
96+
List Selection Should Be id:seller Eicca Toppinen
97+
Textfield Value Should Be id:price 111
98+
List Selection Should Be id:currency RUB
99+
Textfield Value Should Be id:alt-price 1.5
100+
List Selection Should Be id:alt-currency EUR
99101
Submit Form id:create-series-form
100102
# after importing a series, sale info should be shown at the info page
101103
${currentDate}= Get Current Date result_format=%d.%m.%Y
102-
Element Text Should Be id:series-sale-1-info ${currentDate} Eicca Toppinen was selling for 111.00 RUB
104+
Element Text Should Be id:series-sale-1-info ${currentDate} Eicca Toppinen was selling for 111.00 RUB (1.50 EUR)
103105
Link Should Point To id:series-sale-1-seller http://example.com/eicca-toppinen
104106
Link Should Point To id:series-sale-1-transaction ${MOCK_SERVER}/series/import/request-logic/existing-seller.html
105107
Go To ${requestLocation}
106108
# after importing a series, sale info at the request page should be shown as read-only
107109
Element Should Be Disabled id:seller
108110
Element Should Be Disabled id:price
109111
Element Should Be Disabled id:currency
112+
Element Should Be Disabled id:alt-price
113+
Element Should Be Disabled id:alt-currency
110114

111115
Import series and series sale with a new seller from an external site
112116
[Documentation] Verify import series and sale (with a new seller)

src/test/wiremock/__files/series/import/request-logic/existing-seller.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<body>
88
Image: <a id="test-image" href="http://127.0.0.1:8080/image/1">series image</a><br />
99
Seller: <a id="test-seller" href="http://example.com/eicca-toppinen">Eicca Toppinen</a><br />
10-
Price: <span id="test-price">111</span> RUB<br />
10+
Price: <span id="test-price">111</span> RUB (<span id="alt-price">1.5</span> <span id="alt-currency">EUR</span>)<br />
1111
<!--
1212
This is needed to simplify an integration test:
1313
required fields "category" and "quantity" will be filled automatically

0 commit comments

Comments
 (0)