summaryrefslogtreecommitdiff
path: root/merchant-terminal/src/test/java
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-03-18 14:24:41 -0300
committerTorsten Grote <t@grobox.de>2020-03-18 14:24:41 -0300
commita4796ec47d89a851b260b6fc195494547208a025 (patch)
treed2941b68ff2ce22c523e7aa634965033b1100560 /merchant-terminal/src/test/java
downloadtaler-android-a4796ec47d89a851b260b6fc195494547208a025.tar.gz
taler-android-a4796ec47d89a851b260b6fc195494547208a025.tar.bz2
taler-android-a4796ec47d89a851b260b6fc195494547208a025.zip
Merge all three apps into one repository
Diffstat (limited to 'merchant-terminal/src/test/java')
-rw-r--r--merchant-terminal/src/test/java/net/taler/merchantpos/order/OrderManagerTest.kt151
1 files changed, 151 insertions, 0 deletions
diff --git a/merchant-terminal/src/test/java/net/taler/merchantpos/order/OrderManagerTest.kt b/merchant-terminal/src/test/java/net/taler/merchantpos/order/OrderManagerTest.kt
new file mode 100644
index 0000000..cdb928a
--- /dev/null
+++ b/merchant-terminal/src/test/java/net/taler/merchantpos/order/OrderManagerTest.kt
@@ -0,0 +1,151 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.merchantpos.order
+
+import android.app.Application
+import androidx.test.core.app.ApplicationProvider.getApplicationContext
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.kotlin.KotlinModule
+import kotlinx.coroutines.runBlocking
+import net.taler.merchantpos.R
+import org.json.JSONObject
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class OrderManagerTest {
+
+ private val mapper = ObjectMapper()
+ .registerModule(KotlinModule())
+ .configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
+
+ private val app: Application = getApplicationContext()
+ private val orderManager = OrderManager(app, mapper)
+
+ @Test
+ fun `config test missing categories`() = runBlocking {
+ val json = JSONObject(
+ """
+ { "categories": [] }
+ """.trimIndent()
+ )
+ val result = orderManager.onConfigurationReceived(json, "KUDOS")
+ assertEquals(app.getString(R.string.config_error_category), result)
+ }
+
+ @Test
+ fun `config test currency mismatch`() = runBlocking {
+ val json = JSONObject(
+ """{
+ "categories": [
+ {
+ "id": 1,
+ "name": "Snacks"
+ }
+ ],
+ "products": [
+ {
+ "product_id": "631361561",
+ "description": "Chips",
+ "price": "WRONGCURRENCY:1.00",
+ "categories": [ 1 ],
+ "delivery_location": "cafeteria"
+ }
+ ]
+ }""".trimIndent()
+ )
+ val result = orderManager.onConfigurationReceived(json, "KUDOS")
+ val expectedStr = app.getString(
+ R.string.config_error_currency, "Chips", "WRONGCURRENCY", "KUDOS"
+ )
+ assertEquals(expectedStr, result)
+ }
+
+ @Test
+ fun `config test unknown category ID`() = runBlocking {
+ val json = JSONObject(
+ """{
+ "categories": [
+ {
+ "id": 1,
+ "name": "Snacks"
+ }
+ ],
+ "products": [
+ {
+ "product_id": "631361561",
+ "description": "Chips",
+ "price": "KUDOS:1.00",
+ "categories": [ 2 ]
+ }
+ ]
+ }""".trimIndent()
+ )
+ val result = orderManager.onConfigurationReceived(json, "KUDOS")
+ val expectedStr = app.getString(
+ R.string.config_error_product_category_id, "Chips", 2
+ )
+ assertEquals(expectedStr, result)
+ }
+
+ @Test
+ fun `config test no products`() = runBlocking {
+ val json = JSONObject(
+ """{
+ "categories": [
+ {
+ "id": 1,
+ "name": "Snacks"
+ }
+ ],
+ "products": []
+ }""".trimIndent()
+ )
+ val result = orderManager.onConfigurationReceived(json, "KUDOS")
+ val expectedStr = app.getString(R.string.config_error_product_zero)
+ assertEquals(expectedStr, result)
+ }
+
+ @Test
+ fun `config test valid config gets accepted`() = runBlocking {
+ val json = JSONObject(
+ """{
+ "categories": [
+ {
+ "id": 1,
+ "name": "Snacks"
+ }
+ ],
+ "products": [
+ {
+ "product_id": "631361561",
+ "description": "Chips",
+ "price": "KUDOS:1.00",
+ "categories": [ 1 ]
+ }
+ ]
+ }""".trimIndent()
+ )
+ val result = orderManager.onConfigurationReceived(json, "KUDOS")
+ assertNull(result)
+ }
+
+}