summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <ms@taler.net>2020-04-29 17:11:24 +0200
committerMarcello Stanisci <ms@taler.net>2020-04-29 17:11:24 +0200
commitf49ae7d5613adc3b6329d04d9c842a7801f97baf (patch)
tree4f64a89b9574f5e6096ee57683c46eea18b1c424
parent82870057112f43f36483542f8b2574e8723113c0 (diff)
downloadlibeufin-f49ae7d5613adc3b6329d04d9c842a7801f97baf.tar.gz
libeufin-f49ae7d5613adc3b6329d04d9c842a7801f97baf.tar.bz2
libeufin-f49ae7d5613adc3b6329d04d9c842a7801f97baf.zip
Integration test.
Up to the point where the test asks for cardinality of history set and fails. The failure is due to the Sandbox that uses a hardcoded response.
-rwxr-xr-xintegration-tests/test-ebics.py8
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt25
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt51
3 files changed, 46 insertions, 38 deletions
diff --git a/integration-tests/test-ebics.py b/integration-tests/test-ebics.py
index 67368932..5c5fbbbb 100755
--- a/integration-tests/test-ebics.py
+++ b/integration-tests/test-ebics.py
@@ -110,6 +110,14 @@ resp = post(
assert(resp.status_code == 200)
# FIXME: assert that history is EMPTY at this point!
+resp = get(
+ "http://localhost:5001/users/{}/history".format(USERNAME)
+)
+
+assert(
+ resp.status_code == 200 and \
+ len(resp.json().get("payments")) == 0
+)
#6 Prepare a payment (via pure Nexus service)
#7 Execute such payment via EBICS
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
index 188aa2df..dca08065 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -137,24 +137,6 @@ class TestSubscriber()
/** PAYMENT INSTRUCTIONS TYPES */
-/** Represents a prepared payment at the nexus. This structure is
- * used to SHOW a prepared payment to the caller. */
-data class PaymentInfoElement(
- /**
- * This field is the mnemonic value that bank accounts usually have.
- */
- val debtorAccount: String,
- val creditorIban: String,
- val creditorBic: String,
- val creditorName: String,
- val subject: String,
- val sum: Amount,
- val submitted: Boolean
-)
-data class PaymentsInfo(
- var payments: MutableList<PaymentInfoElement> = mutableListOf()
-)
-
/** This structure is used to INSTRUCT the nexus to prepare such payment. */
data class Pain001Data(
val creditorIban: String,
@@ -166,9 +148,9 @@ data class Pain001Data(
)
/**
- * This type is more of a debug one, and it shows details
- * about one payment that was accounted by the bank (typically
- * in a CAMT.05x entry)
+ * (Very) generic information about one payment. Can be
+ * derived from a CAMT response, or from a prepared PAIN
+ * document.
*/
data class RawPayment(
val creditorIban: String,
@@ -177,7 +159,6 @@ data class RawPayment(
val subject: String,
val date: String
)
-
data class RawPayments(
var payments: MutableList<RawPayment> = mutableListOf()
) \ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 1b87c27a..59abf557 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -135,14 +135,13 @@ fun main() {
routing {
- /** General / debug endpoints */
+ /** GENERAL / DEBUG ENDPOINTS */
get("/") {
call.respondText("Hello by Nexus!\n")
return@get
}
-
- get("/taler/test-auth") {
+ get("/test-auth") {
authenticateRequest(call.request.headers["Authorization"])
call.respondText("Authenticated!", ContentType.Text.Plain, HttpStatusCode.OK)
return@get
@@ -150,6 +149,31 @@ fun main() {
/** USER endpoints (no EBICS) */
+ get("/users/{id}/history") {
+ /** NOTE: behaviour could be augmented by filtering on date range. */
+ val nexusUser = extractNexusUser(call.parameters["id"])
+ val ret = RawPayments()
+ transaction {
+ RawBankTransactionEntity.find {
+ RawBankTransactionsTable.nexusUser eq nexusUser.id.value
+ }.forEach {
+ ret.payments.add(
+ RawPayment(
+ debitorIban = it.debitorIban,
+ creditorIban = it.creditorIban,
+ subject = it.unstructuredRemittanceInformation,
+ date = DateTime(it.bookingDate).toDashedDate(),
+ amount = "${it.currency}:${it.amount}"
+ )
+ )
+ }
+ }
+ call.respond(
+ HttpStatusCode.OK,
+ ret
+ )
+ return@get
+ }
/** Lists the users known to this system */
get("/users") {
val ret = NexusUsers()
@@ -176,9 +200,8 @@ fun main() {
call.respond(ret)
return@get
}
-
/** Get all the details associated with a NEXUS user */
- get("/user/{id}") {
+ get("/users/{id}") {
val response = transaction {
val nexusUser = extractNexusUser(call.parameters["id"])
NexusUser(
@@ -188,7 +211,6 @@ fun main() {
call.respond(HttpStatusCode.OK, response)
return@get
}
-
/** Make a new NEXUS user in the system */
post("/users/{id}") {
val newUserId = expectId(call.parameters["id"])
@@ -210,8 +232,7 @@ fun main() {
)
return@post
}
-
- /** List all the bank accounts associated with a given NEXUS user. */
+ /** Show bank accounts associated with a given NEXUS user */
get("/users/{id}/accounts") {
// this information is only avaiable *after* HTD or HKD has been called
val id = expectId(call.parameters["id"])
@@ -236,10 +257,10 @@ fun main() {
)
return@get
}
- /** Show list of payments prepared by calling user. */
+ /** Show PREPARED payments */
get("/users/{id}/payments") {
val nexusUserId = expectId(call.parameters["id"])
- val ret = PaymentsInfo()
+ val ret = RawPayments()
transaction {
val nexusUser = extractNexusUser(nexusUserId)
val bankAccountsMap = UserToBankAccountEntity.find {
@@ -250,14 +271,12 @@ fun main() {
Pain001Table.debtorAccount eq it.bankAccount.iban
}.forEach {
ret.payments.add(
- PaymentInfoElement(
- debtorAccount = it.debtorAccount,
+ RawPayment(
creditorIban = it.creditorIban,
- creditorBic = it.creditorBic,
- creditorName = it.creditorName,
+ debitorIban = "FIXME",
subject = it.subject,
- sum = it.sum,
- submitted = it.submitted // whether Nexus processed and sent to the bank
+ amount = "${it.currency}:${it.sum}",
+ date = DateTime(it.date).toDashedDate()
)
)
}