Skip to content

Commit ef6e3e9

Browse files
committed
add test cases for shop specific prices
1 parent 470a4a7 commit ef6e3e9

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

core/src/androidTest/assets/metadata.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@
6868
"state": "NRW",
6969
"street": "Acherstraße 26",
7070
"zip": "53111"
71+
},
72+
{
73+
"city": "Bonn",
74+
"country": "Deutschland",
75+
"email": "[email protected]",
76+
"external": null,
77+
"externalId": null,
78+
"id": "42",
79+
"lat": 50.7352963,
80+
"lon": 7.1001417,
81+
"name": "snabble GmbH 2",
82+
"openingHoursSpecification": [],
83+
"phone": "+491717673249",
84+
"project": "test",
85+
"services": [],
86+
"state": "NRW",
87+
"street": "Acherstraße 26",
88+
"zip": "53111"
7189
}
7290
],
7391
"unitPrefixes": [
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"sku": "online1",
3+
"name": "Kugelschreiber tarent schwarz",
4+
"subtitle": "tarent",
5+
"description": "Schwarzer Kugelschreiber im coolen tarent-Design",
6+
"imageUrl": "https://snabble.io/media/products/Produkt_Bilder__0000_Kugelschreiber-grau.png",
7+
"price": 299,
8+
"decimalDigits": 2,
9+
"taxCategory": "normal",
10+
"eans": [
11+
"0"
12+
],
13+
"codes": [
14+
{
15+
"code": "0"
16+
}
17+
],
18+
"productType": "default"
19+
}
88 KB
Binary file not shown.

core/src/androidTest/java/io/snabble/sdk/ProductDatabaseTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,34 @@ public void testFindBySkuOnline() {
187187
assertNull(findBySkuBlocking(productDatabase, "unknownCode"));
188188
}
189189

190+
@Test
191+
public void testFindBySkuOnlineWithShopSpecificPrice() {
192+
ProductDatabase productDatabase = project.getProductDatabase();
193+
final Product product = findBySkuBlocking(productDatabase, "online1");
194+
assertEquals(product.getSku(), "online1");
195+
assertEquals(product.getPrice(), 399);
196+
197+
project.setCheckedInShop(project.getShops()[1]);
198+
final Product product2 = findBySkuBlocking(productDatabase, "online1");
199+
assertEquals(product2.getSku(), "online1");
200+
assertEquals(product2.getPrice(), 299);
201+
}
202+
203+
@Test
204+
public void testFindBySkuWithShopSpecificPrice() throws IOException, Snabble.SnabbleException {
205+
withDb("testDb_1_15.sqlite3");
206+
207+
ProductDatabase productDatabase = project.getProductDatabase();
208+
final Product product = productDatabase.findBySku("salfter-classic");
209+
assertEquals(product.getSku(), "salfter-classic");
210+
assertEquals(product.getPrice(), 100);
211+
212+
project.setCheckedInShop(project.getShops()[1]);
213+
final Product product2 = productDatabase.findBySku("salfter-classic");
214+
assertEquals(product2.getSku(), "salfter-classic");
215+
assertEquals(product2.getPrice(), 200);
216+
}
217+
190218
private Product findBySkuBlocking(ProductDatabase productDatabase, String sku) {
191219
final CountDownLatch countDownLatch = new CountDownLatch(1);
192220
final Product[] productArr = new Product[1];
@@ -475,4 +503,6 @@ public void error() {
475503
Assert.assertNotNull(product);
476504
Assert.assertEquals("1", product.getSku());
477505
}
506+
507+
478508
}

core/src/androidTest/java/io/snabble/sdk/SnabbleSdkTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public static void setupMockWebServer() throws Exception {
5151
final Buffer product1Buffer = new Buffer();
5252
product1Buffer.readFrom(context.getAssets().open("product.json"));
5353

54+
final Buffer product1OtherPriceBuffer = new Buffer();
55+
product1OtherPriceBuffer.readFrom(context.getAssets().open("product_otherprice.json"));
56+
5457
final Buffer product2Buffer = new Buffer();
5558
product2Buffer.readFrom(context.getAssets().open("product2.json"));
5659

@@ -70,6 +73,11 @@ public MockResponse dispatch(RecordedRequest request) {
7073
.addHeader("Content-Type", "application/vnd+sellfio.appdb+sqlite3")
7174
.addHeader("Cache-Control", "no-cache")
7275
.setBody(productDbBuffer);
76+
} else if (request.getPath().contains("/products/sku/online1?shopID=42")) {
77+
return new MockResponse()
78+
.addHeader("Content-Type", "application/json")
79+
.addHeader("Cache-Control", "no-cache")
80+
.setBody(product1OtherPriceBuffer);
7381
} else if (request.getPath().contains("/products/sku/online1")) {
7482
return new MockResponse()
7583
.addHeader("Content-Type", "application/json")
@@ -146,6 +154,7 @@ public void withDb(String testDbName, boolean generateSearchIndex) throws IOExce
146154

147155
project = snabble.getProjects().get(0);
148156
project.getShoppingCart().clear();
157+
project.setCheckedInShop(null);
149158

150159
final CountDownLatch countDownLatch = new CountDownLatch(1);
151160
project.getProductDatabase().update(new ProductDatabase.UpdateCallback() {

0 commit comments

Comments
 (0)